GoogleMonitoringIngester extends DataIngester { Datum processRecord(Record rec) throws Exception { int idx = 0; RealVector metricVec = new ArrayRealVector(metrics.size()); for (String metric : metrics) { metricVec.setEntry(idx, rec.values.get(metric)); ++idx; } idx = 1; List<Integer> attrList = new ArrayList<>(attributes.size()); for (String attr : attributes) { attrList.add(conf.getEncoder().getIntegerEncoding(idx, rec.attributes.get(attr))); ++idx; } return new Datum(attrList, metricVec); } GoogleMonitoringIngester(MacroBaseConf conf); @Override MBStream<Datum> getStream(); static final String GOOGLE_MONITORING_QUERIES; static final String GOOGLE_MONITORING_START_TIME; static final String GOOGLE_MONITORING_END_TIME; }
@Test public void testProcessRecord() throws Exception { Record record = new Record(); record.attributes = new TreeMap<>(); record.attributes.put("attr1", "foo"); record.attributes.put("attr2", "bar"); record.values = new HashMap<>(); record.values.put("custom.googleapis.com/test", 77.0); GoogleMonitoringIngester ingester = new GoogleMonitoringIngester(conf); Datum datum = ingester.processRecord(record); assertEquals(77, datum.metrics().getEntry(0), 0.0); assertEquals(0, datum.attributes().get(0), 0.0); assertEquals(1, datum.attributes().get(1), 0.0); }
@Test(expected = NullPointerException.class) public void testProcessRecordMissingMetric() throws Exception { Record record = new Record(); record.attributes = new TreeMap<>(); record.attributes.put("attr1", "foo"); record.attributes.put("attr2", "bar"); record.values = new HashMap<>(); GoogleMonitoringIngester ingester = new GoogleMonitoringIngester(conf); ingester.processRecord(record); }