Skip to content

Commit

Permalink
ref: Remove unused Metrics code (#3271)
Browse files Browse the repository at this point in the history
* ref: Remove unused Metrics code

Remove the timestamp and SentryMetric because they aren't used.

* update api

* Remove code locations / stacklevel as well

* Revert "Remove code locations / stacklevel as well"

This reverts commit d1877da.

---------
  • Loading branch information
philipphofmann authored Mar 20, 2024
1 parent 28c9a83 commit 0352200
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 156 deletions.
27 changes: 5 additions & 22 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -3433,15 +3433,15 @@ public final class io/sentry/metrics/CodeLocations {
}

public final class io/sentry/metrics/CounterMetric : io/sentry/metrics/Metric {
public fun <init> (Ljava/lang/String;DLio/sentry/MeasurementUnit;Ljava/util/Map;Ljava/lang/Long;)V
public fun <init> (Ljava/lang/String;DLio/sentry/MeasurementUnit;Ljava/util/Map;)V
public fun add (D)V
public fun getValue ()D
public fun getWeight ()I
public fun serialize ()Ljava/lang/Iterable;
}

public final class io/sentry/metrics/DistributionMetric : io/sentry/metrics/Metric {
public fun <init> (Ljava/lang/String;DLio/sentry/MeasurementUnit;Ljava/util/Map;Ljava/lang/Long;)V
public fun <init> (Ljava/lang/String;DLio/sentry/MeasurementUnit;Ljava/util/Map;)V
public fun add (D)V
public fun getWeight ()I
public fun serialize ()Ljava/lang/Iterable;
Expand All @@ -3453,7 +3453,7 @@ public final class io/sentry/metrics/EncodedMetrics {
}

public final class io/sentry/metrics/GaugeMetric : io/sentry/metrics/Metric {
public fun <init> (Ljava/lang/String;DLio/sentry/MeasurementUnit;Ljava/util/Map;Ljava/lang/Long;)V
public fun <init> (Ljava/lang/String;DLio/sentry/MeasurementUnit;Ljava/util/Map;)V
public fun add (D)V
public fun getCount ()I
public fun getLast ()D
Expand All @@ -3475,11 +3475,10 @@ public final class io/sentry/metrics/LocalMetricsAggregator {
}

public abstract class io/sentry/metrics/Metric {
public fun <init> (Lio/sentry/metrics/MetricType;Ljava/lang/String;Lio/sentry/MeasurementUnit;Ljava/util/Map;Ljava/lang/Long;)V
public fun <init> (Lio/sentry/metrics/MetricType;Ljava/lang/String;Lio/sentry/MeasurementUnit;Ljava/util/Map;)V
public abstract fun add (D)V
public fun getKey ()Ljava/lang/String;
public fun getTags ()Ljava/util/Map;
public fun getTimeStampMs ()Ljava/lang/Long;
public fun getType ()Lio/sentry/metrics/MetricType;
public fun getUnit ()Lio/sentry/MeasurementUnit;
public abstract fun getWeight ()I
Expand Down Expand Up @@ -3582,24 +3581,8 @@ public final class io/sentry/metrics/NoopMetricsAggregator : io/sentry/IMetricsA
public fun timing (Ljava/lang/String;Ljava/lang/Runnable;Lio/sentry/MeasurementUnit$Duration;Ljava/util/Map;ILio/sentry/metrics/LocalMetricsAggregator;)V
}

public final class io/sentry/metrics/SentryMetric : io/sentry/JsonSerializable {
public fun <init> (Lio/sentry/metrics/Metric;)V
public fun serialize (Lio/sentry/ObjectWriter;Lio/sentry/ILogger;)V
}

public final class io/sentry/metrics/SentryMetric$JsonKeys {
public static final field EVENT_ID Ljava/lang/String;
public static final field NAME Ljava/lang/String;
public static final field TAGS Ljava/lang/String;
public static final field TIMESTAMP Ljava/lang/String;
public static final field TYPE Ljava/lang/String;
public static final field UNIT Ljava/lang/String;
public static final field VALUE Ljava/lang/String;
public fun <init> ()V
}

public final class io/sentry/metrics/SetMetric : io/sentry/metrics/Metric {
public fun <init> (Ljava/lang/String;Lio/sentry/MeasurementUnit;Ljava/util/Map;Ljava/lang/Long;)V
public fun <init> (Ljava/lang/String;Lio/sentry/MeasurementUnit;Ljava/util/Map;)V
public fun add (D)V
public fun getWeight ()I
public fun serialize ()Ljava/lang/Iterable;
Expand Down
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/MetricsAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,16 @@ private void add(
final @NotNull Metric metric;
switch (type) {
case Counter:
metric = new CounterMetric(key, value, unit, tags, timestampMs);
metric = new CounterMetric(key, value, unit, tags);
break;
case Gauge:
metric = new GaugeMetric(key, value, unit, tags, timestampMs);
metric = new GaugeMetric(key, value, unit, tags);
break;
case Distribution:
metric = new DistributionMetric(key, value, unit, tags, timestampMs);
metric = new DistributionMetric(key, value, unit, tags);
break;
case Set:
metric = new SetMetric(key, unit, tags, timestampMs);
metric = new SetMetric(key, unit, tags);
// sets API is either ints or strings cr32 encoded into ints
// noinspection unchecked
metric.add((int) value);
Expand Down
5 changes: 2 additions & 3 deletions sentry/src/main/java/io/sentry/metrics/CounterMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ public CounterMetric(
final @NotNull String key,
final double value,
final @Nullable MeasurementUnit unit,
final @Nullable Map<String, String> tags,
final @NotNull Long timestamp) {
super(MetricType.Counter, key, unit, tags, timestamp);
final @Nullable Map<String, String> tags) {
super(MetricType.Counter, key, unit, tags);
this.value = value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public DistributionMetric(
final @NotNull String key,
final double value,
final @Nullable MeasurementUnit unit,
final @Nullable Map<String, String> tags,
final @NotNull Long timestamp) {
super(MetricType.Distribution, key, unit, tags, timestamp);
final @Nullable Map<String, String> tags) {
super(MetricType.Distribution, key, unit, tags);
this.values.add(value);
}

Expand Down
5 changes: 2 additions & 3 deletions sentry/src/main/java/io/sentry/metrics/GaugeMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public GaugeMetric(
final @NotNull String key,
final double value,
final @Nullable MeasurementUnit unit,
final @Nullable Map<String, String> tags,
final @NotNull Long timestamp) {
super(MetricType.Gauge, key, unit, tags, timestamp);
final @Nullable Map<String, String> tags) {
super(MetricType.Gauge, key, unit, tags);

this.last = value;
this.min = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void add(

@Nullable GaugeMetric gauge = bucket.get(bucketKey);
if (gauge == null) {
gauge = new GaugeMetric(key, value, unit, tags, timestampMs);
gauge = new GaugeMetric(key, value, unit, tags);
bucket.put(bucketKey, gauge);
} else {
gauge.add(value);
Expand Down
11 changes: 1 addition & 10 deletions sentry/src/main/java/io/sentry/metrics/Metric.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public abstract class Metric {
private final @NotNull String key;
private final @Nullable MeasurementUnit unit;
private final @Nullable Map<String, String> tags;
private final @NotNull Long timestampMs;

/**
* Creates a new instance of {@link Metric}.
Expand All @@ -23,19 +22,16 @@ public abstract class Metric {
* @param unit An optional {@link MeasurementUnit} that describes the values being tracked
* @param tags An optional set of key/value pairs that can be used to add dimensionality to
* metrics
* @param timestampMs A time when the metric was emitted.
*/
public Metric(
final @NotNull MetricType type,
final @NotNull String key,
final @Nullable MeasurementUnit unit,
final @Nullable Map<String, String> tags,
final @NotNull Long timestampMs) {
final @Nullable Map<String, String> tags) {
this.type = type;
this.key = key;
this.unit = unit;
this.tags = tags;
this.timestampMs = timestampMs;
}

/** Adds a value to the metric */
Expand Down Expand Up @@ -63,10 +59,5 @@ public Map<String, String> getTags() {
return tags;
}

/** the unix timestamp in milliseconds when the metric was emitted. */
public Long getTimeStampMs() {
return timestampMs;
}

public abstract @NotNull Iterable<?> serialize();
}
77 changes: 0 additions & 77 deletions sentry/src/main/java/io/sentry/metrics/SentryMetric.java

This file was deleted.

5 changes: 2 additions & 3 deletions sentry/src/main/java/io/sentry/metrics/SetMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public final class SetMetric extends Metric {
public SetMetric(
final @NotNull String key,
final @Nullable MeasurementUnit unit,
final @Nullable Map<String, String> tags,
final @NotNull Long timestamp) {
super(MetricType.Set, key, unit, tags, timestamp);
final @Nullable Map<String, String> tags) {
super(MetricType.Set, key, unit, tags);
}

/**
Expand Down
12 changes: 4 additions & 8 deletions sentry/src/test/java/io/sentry/metrics/CounterMetricTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class CounterMetricTest {
mapOf(
"tag1" to "value1",
"tag2" to "value2"
),
System.currentTimeMillis()
)
)
assertEquals(1.0, metric.value)

Expand All @@ -37,8 +36,7 @@ class CounterMetricTest {
mapOf(
"tag1" to "value1",
"tag2" to "value2"
),
System.currentTimeMillis()
)
)
assertEquals(MetricType.Counter, metric.type)
}
Expand All @@ -52,8 +50,7 @@ class CounterMetricTest {
mapOf(
"tag1" to "value1",
"tag2" to "value2"
),
System.currentTimeMillis()
)
)
assertEquals(1, metric.weight)
}
Expand All @@ -67,8 +64,7 @@ class CounterMetricTest {
mapOf(
"tag1" to "value1",
"tag2" to "value2"
),
System.currentTimeMillis()
)
)

val values0 = metric.serialize().toList()
Expand Down
12 changes: 4 additions & 8 deletions sentry/src/test/java/io/sentry/metrics/DistributionMetricTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class DistributionMetricTest {
"test",
1.0,
null,
null,
System.currentTimeMillis()
null
)
assertEquals(listOf(1.0), metric.serialize().toList())

Expand All @@ -27,8 +26,7 @@ class DistributionMetricTest {
"test",
1.0,
null,
null,
System.currentTimeMillis()
null
)
assertEquals(MetricType.Distribution, metric.type)
}
Expand All @@ -39,8 +37,7 @@ class DistributionMetricTest {
"test",
1.0,
null,
null,
System.currentTimeMillis()
null
)
assertEquals(1, metric.weight)

Expand All @@ -54,8 +51,7 @@ class DistributionMetricTest {
"test",
1.0,
null,
null,
System.currentTimeMillis()
null
)
metric.add(2.0)

Expand Down
9 changes: 3 additions & 6 deletions sentry/src/test/java/io/sentry/metrics/GaugeMetricTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class GaugeMetricTest {
"test",
1.0,
null,
null,
System.currentTimeMillis()
null
)
assertEquals(
listOf(
Expand Down Expand Up @@ -48,8 +47,7 @@ class GaugeMetricTest {
"test",
1.0,
null,
null,
System.currentTimeMillis()
null
)
assertEquals(MetricType.Gauge, metric.type)
}
Expand All @@ -60,8 +58,7 @@ class GaugeMetricTest {
"test",
1.0,
null,
null,
System.currentTimeMillis()
null
)
assertEquals(5, metric.weight)

Expand Down
3 changes: 1 addition & 2 deletions sentry/src/test/java/io/sentry/metrics/MetricsHelperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ class MetricsHelperTest {
mapOf(
"tag1" to "value1",
"tag2" to "value2"
),
1000
)
)
),
stringBuilder
Expand Down
Loading

0 comments on commit 0352200

Please sign in to comment.