mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 09:08:05 +01:00
Add some additional backup metrics
This commit is contained in:
committed by
Jon Chambers
parent
4a42ff562d
commit
2b07a21477
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.metrics;
|
||||
|
||||
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import org.signal.libsignal.zkgroup.backups.BackupCredentialType;
|
||||
import org.whispersystems.textsecuregcm.backup.CopyResult;
|
||||
|
||||
public class BackupMetrics {
|
||||
|
||||
private final static String COPY_MEDIA_COUNTER_NAME = name(BackupMetrics.class, "copyMedia");
|
||||
private final static String GET_BACKUP_CREDENTIALS_NAME = name(BackupMetrics.class, "getBackupCredentials");
|
||||
|
||||
|
||||
private MeterRegistry registry;
|
||||
|
||||
public BackupMetrics() {
|
||||
this(Metrics.globalRegistry);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
BackupMetrics(MeterRegistry registry) {
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
public void updateCopyCounter(final CopyResult copyResult, final Tag platformTag) {
|
||||
registry.counter(COPY_MEDIA_COUNTER_NAME, Tags.of(
|
||||
platformTag,
|
||||
Tag.of("outcome", copyResult.outcome().name().toLowerCase())))
|
||||
.increment();
|
||||
}
|
||||
|
||||
public void updateGetCredentialCounter(final Tag platformTag, BackupCredentialType credentialType,
|
||||
final int numCredentials) {
|
||||
Metrics.counter(GET_BACKUP_CREDENTIALS_NAME, Tags.of(
|
||||
platformTag,
|
||||
Tag.of("num", Integer.toString(numCredentials)),
|
||||
Tag.of("type", credentialType.name().toLowerCase())))
|
||||
.increment();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.whispersystems.textsecuregcm.storage.ClientReleaseManager;
|
||||
import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException;
|
||||
import org.whispersystems.textsecuregcm.util.ua.UserAgent;
|
||||
import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Utility class for extracting platform/version metrics tags from User-Agent strings.
|
||||
@@ -26,15 +27,19 @@ public class UserAgentTagUtil {
|
||||
}
|
||||
|
||||
public static Tag getPlatformTag(final String userAgentString) {
|
||||
String platform;
|
||||
|
||||
UserAgent userAgent = null;
|
||||
|
||||
try {
|
||||
platform = UserAgentUtil.parseUserAgentString(userAgentString).getPlatform().name().toLowerCase();
|
||||
} catch (final UnrecognizedUserAgentException e) {
|
||||
platform = "unrecognized";
|
||||
userAgent = UserAgentUtil.parseUserAgentString(userAgentString);
|
||||
} catch (final UnrecognizedUserAgentException ignored) {
|
||||
}
|
||||
|
||||
return Tag.of(PLATFORM_TAG, platform);
|
||||
return getPlatformTag(userAgent);
|
||||
}
|
||||
|
||||
public static Tag getPlatformTag(@Nullable final UserAgent userAgent) {
|
||||
return Tag.of(PLATFORM_TAG, userAgent != null ? userAgent.getPlatform().name().toLowerCase() : "unrecognized");
|
||||
}
|
||||
|
||||
public static Optional<Tag> getClientVersionTag(final String userAgentString, final ClientReleaseManager clientReleaseManager) {
|
||||
|
||||
Reference in New Issue
Block a user