use of com.google.api.services.monitoring.v3.model.Point in project kork by spinnaker.
the class StackdriverWriterTest method writeRegistryWithLargeRegistry.
@Test
public void writeRegistryWithLargeRegistry() throws IOException {
TestableStackdriverWriter spy = spy(new TestableStackdriverWriter(writerConfig.build()));
Monitoring.Projects.TimeSeries.Create mockCreateMethod = Mockito.mock(Monitoring.Projects.TimeSeries.Create.class);
DefaultRegistry registry = new DefaultRegistry(clock);
// The contents of this timeseries doesnt matter.
// It is technically invalid to have null entries in the list,
// but since we're mocking out the access the values does not matter.
// What is important is the size of the list, so we can verify chunking.
List<TimeSeries> tsList = new ArrayList<TimeSeries>();
for (int i = 0; i < 200; ++i) {
tsList.add(null);
}
// make last one different to test chunking
tsList.add(new TimeSeries());
doReturn(tsList).when(spy).registryToTimeSeries(registry);
// the calls point to the same instance with the final mutated value.
class MatchN implements ArgumentMatcher<CreateTimeSeriesRequest> {
public int found = 0;
private int n;
public MatchN(int n) {
super();
this.n = n;
}
@Override
public String toString() {
return "Match n=" + n;
}
@Override
public boolean matches(CreateTimeSeriesRequest obj) {
boolean eq = ((CreateTimeSeriesRequest) obj).getTimeSeries().size() == n;
found += eq ? 1 : 0;
return eq;
}
}
;
MatchN match200 = new MatchN(200);
MatchN match1 = new MatchN(1);
when(timeseriesApi.create(eq("projects/test-project"), argThat(match200))).thenReturn(mockCreateMethod);
when(timeseriesApi.create(eq("projects/test-project"), argThat(match1))).thenReturn(mockCreateMethod);
when(mockCreateMethod.execute()).thenReturn(null);
spy.writeRegistry(registry);
verify(mockCreateMethod, times(2)).execute();
Assert.assertEquals(1, match200.found);
Assert.assertEquals(1, match1.found);
}
use of com.google.api.services.monitoring.v3.model.Point in project kork by spinnaker.
the class StackdriverWriter method measurementToTimeSeries.
/**
* Convert a Spectator metric Meter into a Stackdriver TimeSeries entry.
*
* @param descriptorType
* The Stackdriver MetricDescriptorType name for the measurement.
*
* @param measurement
* The Spectator Measurement to encode.
*
* @return
* The Stackdriver TimeSeries equivalent for the measurement.
*/
public TimeSeries measurementToTimeSeries(String descriptorType, Registry registry, Meter meter, Measurement measurement) {
Map<String, String> labels = cache.tagsToTimeSeriesLabels(descriptorType, measurement.id().tags());
long millis = measurement.timestamp();
double value = measurement.value();
TimeInterval timeInterval = new TimeInterval();
Date date = new Date(millis);
timeInterval.setEndTime(rfc3339.format(date));
String descriptorKind = cache.descriptorTypeToKind(descriptorType, registry, meter);
if (descriptorKind == "CUMULATIVE") {
timeInterval.setStartTime(counterStartTimeRfc3339);
}
TypedValue typedValue = new TypedValue();
typedValue.setDoubleValue(value);
Point point = new Point();
point.setValue(typedValue);
point.setInterval(timeInterval);
Metric metric = new Metric();
metric.setType(descriptorType);
metric.setLabels(labels);
TimeSeries ts = new TimeSeries();
ts.setResource(monitoredResource);
ts.setMetric(metric);
ts.setMetricKind(descriptorKind);
ts.setValueType("DOUBLE");
ts.setPoints(Lists.<Point>newArrayList(point));
return ts;
}
Aggregations