GoogleMonitoringIngester extends DataIngester { QueryConf getQueries(String queryJson) throws IOException { ObjectMapper mapper = Jackson.newObjectMapper(); return mapper.readValue(queryJson, QueryConf.class); } 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 testGetQueries() throws Exception { GoogleMonitoringIngester ingester = new GoogleMonitoringIngester(conf); QueryConf queryConf = ingester.getQueries(conf.getString(GoogleMonitoringIngester.GOOGLE_MONITORING_QUERIES)); assertEquals(1, queryConf.getQueries().size()); QueryConf.Query query = queryConf.getQueries().get(0); assertEquals("some-project", query.getProject()); assertEquals("metric.type=\"custom.googleapis.com/test\"", query.getFilter()); assertEquals("300s", query.getAlignmentPeriod()); assertEquals("ALIGN_MEAN", query.getPerSeriesAligner()); assertEquals("REDUCE_MEAN", query.getCrossSeriesReducer()); assertArrayEquals(Lists.newArrayList("foo", "project").toArray(), query.getGroupByFields().toArray()); }
@Test public void testGetQueriesUsesDefaults() throws Exception { GoogleMonitoringIngester ingester = new GoogleMonitoringIngester(conf); QueryConf queryConf = ingester.getQueries( "{`queries`: [{`project`: `some-project`, `filter`: `metric.type=\\`custom.googleapis.com/test\\``}]}".replace('`', '"')); assertEquals(1, queryConf.getQueries().size()); QueryConf.Query query = queryConf.getQueries().get(0); assertEquals("some-project", query.getProject()); assertEquals("metric.type=\"custom.googleapis.com/test\"", query.getFilter()); assertEquals("", query.getAlignmentPeriod()); assertEquals("ALIGN_NONE", query.getPerSeriesAligner()); assertEquals("REDUCE_NONE", query.getCrossSeriesReducer()); assertEquals(0, query.getGroupByFields().size()); }