-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathMetricCollector.java
More file actions
170 lines (151 loc) · 4.39 KB
/
MetricCollector.java
File metadata and controls
170 lines (151 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package datadog.trace.api.telemetry;
import static datadog.trace.api.telemetry.MetricCollector.Metric;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import datadog.trace.util.HashingUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
public interface MetricCollector<M extends Metric> {
int RAW_QUEUE_SIZE = 1024;
// TODO All implementations are based on queueing metrics and never care when the queue is full.
// TODO This leads to always resetting counters even if the related metrics could not be enqueued.
// TODO So we may loose metric information during this call.
void prepareMetrics();
Collection<M> drain();
default Collection<DistributionSeriesPoint> drainDistributionSeries() {
return Collections.emptySet();
}
class Metric {
public final String metricName;
public final boolean common;
public final String namespace;
public final String type;
public final long timestamp;
public final Number value;
public final List<String> tags;
public Metric(
String namespace,
boolean common,
String metricName,
String type,
Number value,
final String tag) {
this(
namespace,
common,
metricName,
type,
value,
tag == null ? emptyList() : singletonList(tag));
}
public Metric(
String namespace,
boolean common,
String metricName,
String type,
Number value,
final String... tags) {
this(namespace, common, metricName, type, value, Arrays.asList(tags));
}
public Metric(
String namespace,
boolean common,
String metricName,
String type,
Number value,
final List<String> tags) {
this.namespace = namespace;
this.common = common;
this.metricName = metricName;
this.type = type;
this.timestamp = System.currentTimeMillis() / 1000;
this.value = value;
this.tags = tags;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof Metric)) return false;
Metric metric = (Metric) o;
return common == metric.common
&& Objects.equals(metricName, metric.metricName)
&& Objects.equals(namespace, metric.namespace)
&& Objects.equals(tags, metric.tags);
}
@Override
public int hashCode() {
return HashingUtils.hash(metricName, common, namespace, tags);
}
@Override
public String toString() {
return "Metric{"
+ "metricName='"
+ metricName
+ '\''
+ ", common="
+ common
+ ", namespace='"
+ namespace
+ '\''
+ ", type='"
+ type
+ '\''
+ ", timestamp="
+ timestamp
+ ", value="
+ value
+ ", tags="
+ tags
+ '}';
}
}
class DistributionSeriesPoint {
public final String metricName;
public final boolean common;
public final String namespace;
public final int value;
public final List<String> tags;
public DistributionSeriesPoint(
String metricName, boolean common, String namespace, int value, List<String> tags) {
this.metricName = metricName;
this.common = common;
this.namespace = namespace;
this.value = value;
this.tags = tags;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DistributionSeriesPoint that = (DistributionSeriesPoint) o;
return common == that.common
&& Objects.equals(metricName, that.metricName)
&& Objects.equals(namespace, that.namespace)
&& Objects.equals(tags, that.tags);
}
@Override
public int hashCode() {
return HashingUtils.hash(metricName, common, namespace, tags);
}
@Override
public String toString() {
return "DistributionSeriesPoint{"
+ "metricName='"
+ metricName
+ '\''
+ ", common="
+ common
+ ", namespace='"
+ namespace
+ '\''
+ ", value="
+ value
+ ", tags="
+ tags
+ '}';
}
}
}