-
-
Notifications
You must be signed in to change notification settings - Fork 15
OpenTelemetry #443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
OpenTelemetry #443
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5aa10ce
replace Micrometer with OpenTelemetry
overheadhunter b72a34e
adjust chart for Hub's OpenTelemetry capabilities
overheadhunter e50edc4
fix protocol
overheadhunter 199cc14
Merge branch 'develop' into feature/otel
overheadhunter ce6b95a
we use gRCP over HTTP by default
overheadhunter 886dd50
cleanup metrics classes
overheadhunter 63024bb
add traceability annotations
overheadhunter 17d60ae
tune resource limits (remove hard cpu limit)
overheadhunter 59978d2
use opentelemetry-enabled build
overheadhunter d9814d7
README.md: fix inconsistency in example
overheadhunter 195329f
deterministic order of resource attributes
overheadhunter 5590460
address findings from code review
overheadhunter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 52 additions & 50 deletions
102
backend/src/main/java/org/cryptomator/hub/metrics/SystemUsageMetrics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,73 @@ | ||
| package org.cryptomator.hub.metrics; | ||
|
|
||
| import io.micrometer.core.instrument.Gauge; | ||
| import io.micrometer.core.instrument.MeterRegistry; | ||
| import io.quarkus.scheduler.Scheduled; | ||
| import jakarta.annotation.PostConstruct; | ||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.Meter; | ||
| import io.opentelemetry.api.metrics.ObservableLongGauge; | ||
| import io.opentelemetry.api.metrics.ObservableLongMeasurement; | ||
| import io.quarkus.narayana.jta.QuarkusTransaction; | ||
| import io.quarkus.runtime.ShutdownEvent; | ||
| import jakarta.enterprise.context.ApplicationScoped; | ||
| import jakarta.enterprise.event.Observes; | ||
| import jakarta.inject.Inject; | ||
| import jakarta.transaction.Transactional; | ||
| import org.cryptomator.hub.entities.Device; | ||
| import org.cryptomator.hub.entities.EffectiveVaultAccess; | ||
| import org.cryptomator.hub.entities.Vault; | ||
|
|
||
| import java.util.EnumMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
|
|
||
| @ApplicationScoped | ||
| public class SystemUsageMetrics { | ||
|
|
||
| private static final String VAULTS_TOTAL_METRIC = "hub_vaults_total"; | ||
| private static final String ACTIVE_USERS_TOTAL_METRIC = "hub_active_users_total"; | ||
| private static final String DEVICES_TOTAL_METRIC = "hub_devices_total"; | ||
|
|
||
| @Inject | ||
| MeterRegistry meterRegistry; | ||
|
|
||
| @Inject | ||
| Vault.Repository vaultRepo; | ||
| private static final String VAULTS_METRIC = "hub_vaults"; | ||
| private static final String ACTIVE_USERS_METRIC = "hub_active_users"; | ||
| private static final String DEVICES_METRIC = "hub_devices"; | ||
| private static final AttributeKey<String> DEVICE_TYPE_KEY = AttributeKey.stringKey("type"); | ||
|
|
||
| @Inject | ||
| EffectiveVaultAccess.Repository effectiveVaultAccessRepo; | ||
| private final Vault.Repository vaultRepo; | ||
| private final EffectiveVaultAccess.Repository effectiveVaultAccessRepo; | ||
| private final Device.Repository deviceRepo; | ||
| private final ObservableLongGauge vaultsGauge; | ||
| private final ObservableLongGauge activeUsersGauge; | ||
| private final ObservableLongGauge devicesGauge; | ||
|
|
||
| @Inject | ||
| Device.Repository deviceRepo; | ||
|
|
||
| private final AtomicLong vaultsTotal = new AtomicLong(0); | ||
| private final AtomicLong activeUsersTotal = new AtomicLong(0); | ||
| private final Map<Device.Type, AtomicLong> devicesPerType = new EnumMap<>(Device.Type.class); | ||
| SystemUsageMetrics(Meter meter, Vault.Repository vaultRepo, EffectiveVaultAccess.Repository effectiveVaultAccessRepo, Device.Repository deviceRepo) { | ||
| this.vaultRepo = vaultRepo; | ||
| this.effectiveVaultAccessRepo = effectiveVaultAccessRepo; | ||
| this.deviceRepo = deviceRepo; | ||
| this.vaultsGauge = meter.gaugeBuilder(VAULTS_METRIC) | ||
| .ofLongs() | ||
| .setDescription("Number of vaults") | ||
| .buildWithCallback(this::recordVaultCount); | ||
| this.activeUsersGauge = meter.gaugeBuilder(ACTIVE_USERS_METRIC) | ||
| .ofLongs() | ||
| .setDescription("Number of unique users with access to any non-archived vault") | ||
| .buildWithCallback(this::recordSeatCount); | ||
| this.devicesGauge = meter.gaugeBuilder(DEVICES_METRIC) | ||
| .ofLongs() | ||
| .setDescription("Number of devices grouped by type") | ||
| .buildWithCallback(this::recordDeviceCount); | ||
| } | ||
|
|
||
| @PostConstruct | ||
| void registerMetrics() { | ||
| Gauge.builder(VAULTS_TOTAL_METRIC, vaultsTotal, AtomicLong::get) | ||
| .description("Number of vaults") | ||
| .register(meterRegistry); | ||
| private void recordVaultCount(ObservableLongMeasurement measurement) { | ||
| measurement.record(QuarkusTransaction.requiringNew().call(vaultRepo::count)); | ||
| } | ||
|
|
||
| Gauge.builder(ACTIVE_USERS_TOTAL_METRIC, activeUsersTotal, AtomicLong::get) | ||
| .description("Number of unique users with access to any non-archived vault") | ||
| .register(meterRegistry); | ||
| private void recordSeatCount(ObservableLongMeasurement measurement) { | ||
| measurement.record(QuarkusTransaction.requiringNew().call(effectiveVaultAccessRepo::countSeatOccupyingUsers)); | ||
| } | ||
|
|
||
| for (var deviceType : Device.Type.values()) { | ||
| var value = new AtomicLong(0); | ||
| devicesPerType.put(deviceType, value); | ||
| Gauge.builder(DEVICES_TOTAL_METRIC, value, AtomicLong::get) | ||
| .description("Number of devices grouped by type") | ||
| .tag("type", deviceType.name()) | ||
| .register(meterRegistry); | ||
| } | ||
| private void recordDeviceCount(ObservableLongMeasurement measurement) { | ||
| QuarkusTransaction.requiringNew().run(() -> { | ||
| for (var type : Device.Type.values()) { | ||
| measurement.record(deviceRepo.count("type", type), Attributes.of(DEVICE_TYPE_KEY, type.name())); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| @Scheduled(every = "24h", delayed = "10s") | ||
| @Transactional | ||
| void collect() { | ||
| vaultsTotal.set(vaultRepo.count()); | ||
| activeUsersTotal.set(effectiveVaultAccessRepo.countSeatOccupyingUsers()); | ||
| for (var deviceType : Device.Type.values()) { | ||
| var count = deviceRepo.count("type", deviceType); | ||
| devicesPerType.get(deviceType).set(count); | ||
| } | ||
| void onStop(@Observes ShutdownEvent event) { | ||
| vaultsGauge.close(); | ||
| activeUsersGauge.close(); | ||
| devicesGauge.close(); | ||
| } | ||
|
|
||
| } | ||
48 changes: 22 additions & 26 deletions
48
backend/src/main/java/org/cryptomator/hub/metrics/VaultUnlockMetrics.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.