Skip to content

Commit 2d73765

Browse files
PhoenixRionBrandonArp
authored andcommitted
Add dimensions support (#33)
* Dimensions support. This commit squashes the history of commit edbf443, tagged dimensions-pre-reset, on top of ArpNetworking/metrics-aggregator-daemon master branch.
1 parent 4265e96 commit 2d73765

File tree

67 files changed

+2573
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2573
-260
lines changed

src/main/java/com/arpnetworking/metrics/mad/Aggregator.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* This class is thread safe.
5555
*
5656
* @author Ville Koskela (ville dot koskela at inscopemetrics dot com)
57+
* @author Ryan Ascheman (rascheman at groupon dot com)
5758
*/
5859
// NOTE: The _periodWorkerExecutor is accessed both in synchronized lifecycle methods like launch() and shutdown() but
5960
// also non-synchronized methods like notify(). Access to _periodWorkerExecutor does not need to be synchronized.
@@ -113,8 +114,9 @@ public void notify(final Observable observable, final Object event) {
113114
.log();
114115
return;
115116
}
117+
116118
final Record record = (Record) event;
117-
final Key key = new DefaultKey(createDimensions(record));
119+
final Key key = new DefaultKey(record.getDimensions());
118120
LOGGER.trace()
119121
.setMessage("Processing record")
120122
.addData("record", record)
@@ -149,15 +151,6 @@ public String toString() {
149151
return toLogValue().toString();
150152
}
151153

152-
private ImmutableMap<String, String> createDimensions(final Record record) {
153-
// TODO(ville): Promote user specified annotations to dimensions.
154-
final ImmutableMap.Builder<String, String> dimensionBuilder = ImmutableMap.builder();
155-
dimensionBuilder.put(Key.HOST_DIMENSION_KEY, record.getAnnotations().get(Key.HOST_DIMENSION_KEY));
156-
dimensionBuilder.put(Key.SERVICE_DIMENSION_KEY, record.getAnnotations().get(Key.SERVICE_DIMENSION_KEY));
157-
dimensionBuilder.put(Key.CLUSTER_DIMENSION_KEY, record.getAnnotations().get(Key.CLUSTER_DIMENSION_KEY));
158-
return dimensionBuilder.build();
159-
}
160-
161154
private List<PeriodWorker> createPeriodWorkers(final Key key) {
162155
final List<PeriodWorker> periodWorkerList = Lists.newArrayListWithExpectedSize(_periods.size());
163156
for (final Period period : _periods) {

src/main/java/com/arpnetworking/metrics/mad/model/DefaultRecord.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,19 @@
1717

1818
import com.arpnetworking.commons.builder.OvalBuilder;
1919
import com.arpnetworking.logback.annotations.Loggable;
20-
import com.arpnetworking.tsdcore.model.Key;
2120
import com.google.common.base.MoreObjects;
2221
import com.google.common.base.Objects;
23-
import com.google.common.base.Strings;
2422
import com.google.common.collect.ImmutableMap;
25-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2623
import net.sf.oval.constraint.NotEmpty;
2724
import net.sf.oval.constraint.NotNull;
28-
import net.sf.oval.constraint.ValidateWithMethod;
2925
import org.joda.time.DateTime;
3026

3127
/**
3228
* Default implementation of the <code>Record</code> interface.
3329
*
3430
* @author Brandon Arp (brandonarp at gmail dot com)
3531
* @author Ville Koskela (ville dot koskela at inscopemetrics dot com)
32+
* @author Ryan Ascheman (rascheman at groupon dot com)
3633
*/
3734
@Loggable
3835
public final class DefaultRecord implements Record {
@@ -69,6 +66,14 @@ public ImmutableMap<String, String> getAnnotations() {
6966
return _annotations;
7067
}
7168

69+
/**
70+
* {@inheritDoc}
71+
*/
72+
@Override
73+
public ImmutableMap<String, String> getDimensions() {
74+
return _dimensions;
75+
}
76+
7277
/**
7378
* {@inheritDoc}
7479
*/
@@ -105,6 +110,7 @@ public String toString() {
105110
.add("Id", _id)
106111
.add("Time", _time)
107112
.add("Annotations", _annotations)
113+
.add("Dimensions", _dimensions)
108114
.toString();
109115
}
110116

@@ -115,12 +121,14 @@ private DefaultRecord(final Builder builder) {
115121
_id = builder._id;
116122
_time = builder._time;
117123
_annotations = builder._annotations;
124+
_dimensions = builder._dimensions;
118125
}
119126

120127
private final ImmutableMap<String, ? extends Metric> _metrics;
121128
private final String _id;
122129
private final DateTime _time;
123130
private final ImmutableMap<String, String> _annotations;
131+
private final ImmutableMap<String, String> _dimensions;
124132

125133
/**
126134
* Implementation of builder pattern for <code>DefaultRecord</code>.
@@ -181,19 +189,16 @@ public Builder setAnnotations(final ImmutableMap<String, String> value) {
181189
return this;
182190
}
183191

184-
// Called by OVal reflectively
185-
@SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD")
186-
private boolean validateAnnotations(final ImmutableMap<String, String> annotations) {
187-
if (Strings.isNullOrEmpty(annotations.get(Key.HOST_DIMENSION_KEY))) {
188-
return false;
189-
}
190-
if (Strings.isNullOrEmpty(annotations.get(Key.SERVICE_DIMENSION_KEY))) {
191-
return false;
192-
}
193-
if (Strings.isNullOrEmpty(annotations.get(Key.CLUSTER_DIMENSION_KEY))) {
194-
return false;
195-
}
196-
return true;
192+
/**
193+
* The dimension mappings <code>ImmutableMap</code>. Optional. Default is an empty
194+
* <code>ImmutableMap</code>. Cannot be null.
195+
*
196+
* @param value The dimension mappings <code>ImmutableMap</code>
197+
* @return This instance of <code>Builder</code>.
198+
*/
199+
public Builder setDimensions(final ImmutableMap<String, String> value) {
200+
_dimensions = value;
201+
return this;
197202
}
198203

199204
@NotNull
@@ -204,7 +209,8 @@ private boolean validateAnnotations(final ImmutableMap<String, String> annotatio
204209
@NotNull
205210
private DateTime _time;
206211
@NotNull
207-
@ValidateWithMethod(methodName = "validateAnnotations", parameterType = ImmutableMap.class)
208212
private ImmutableMap<String, String> _annotations = ImmutableMap.of();
213+
@NotNull
214+
private ImmutableMap<String, String> _dimensions = ImmutableMap.of();
209215
}
210216
}

src/main/java/com/arpnetworking/metrics/mad/model/Record.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
/**
2222
* The interface to a record. Records consistent of a timestamp, any number of
23-
* named metrics and annotations (arbitrary key-value pairs).
23+
* named metrics, annotations (arbitrary key-value pairs) and dimensions (arbitrary key-value pairs).
2424
*
2525
* @author Brandon Arp (brandonarp at gmail dot com)
2626
* @author Ville Koskela (ville dot koskela at inscopemetrics dot com)
27+
* @author Ryan Ascheman (rascheman at groupon dot com)
2728
*/
2829
public interface Record {
2930

@@ -54,4 +55,11 @@ public interface Record {
5455
* @return the annotations
5556
*/
5657
ImmutableMap<String, String> getAnnotations();
58+
59+
/**
60+
* Gets dimensions.
61+
*
62+
* @return the dimensions
63+
*/
64+
ImmutableMap<String, String> getDimensions();
5765
}

0 commit comments

Comments
 (0)