test_class.declarator: log = LoggerFactory.getLogger(GoogleMonitoringIngesterTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger log = LoggerFactory.getLogger(GoogleMonitoringIngesterTest.class);
test_class.type: Logger
test_class.var_name: log
test_class.declarator: conf
test_class.modifier: private
test_class.original_string: private MacroBaseConf conf;
test_class.type: MacroBaseConf
test_class.var_name: conf
test_class.file: contrib/src/test/java/macrobase/ingest/GoogleMonitoringIngesterTest.java
test_class.identifier: GoogleMonitoringIngesterTest
test_case.body: @Test
      public void testProcessResponse() throws Exception {
          Map<String, String> metricLabels1 = new HashMap<>();
          metricLabels1.put("attr1", "foo");
          metricLabels1.put("attr2", "bar");
  
          Map<String, String> metricLabels2 = new HashMap<>();
          metricLabels2.put("attr1", "foo");
          metricLabels2.put("attr2", "baz");
  
          // Missing one of the attributes. Will be skipped.
          Map<String, String> metricLabels3 = new HashMap<>();
          metricLabels3.put("attr1", "foo");
  
          Metric metric1 = new Metric();
          metric1.setType("custom.googleapis.com/test");
          metric1.setLabels(metricLabels1);
  
          Metric metric2 = new Metric();
          metric2.setType("custom.googleapis.com/skipped");
          metric2.setLabels(metricLabels1);
  
          Metric metric3 = new Metric();
          metric3.setType("custom.googleapis.com/test");
          metric3.setLabels(metricLabels2);
  
          Metric metric4 = new Metric();
          metric4.setType("custom.googleapis.com/test");
          metric4.setLabels(metricLabels3);
  
          Map<String, String> resourceLabels1 = new HashMap<>();
          resourceLabels1.put("project_id", "my-project");
          resourceLabels1.put("region", "us-central-1");
  
          // Get the second attribute from the resource labels.
          Map<String, String> resourceLabels2 = new HashMap<>();
          resourceLabels2.put("project_id", "my-project");
          resourceLabels2.put("region", "us-central-1");
          resourceLabels2.put("attr2", "bar");
  
          MonitoredResource resource1 = new MonitoredResource();
          resource1.setType("gce_instance");
          resource1.setLabels(resourceLabels1);
  
          MonitoredResource resource2 = new MonitoredResource();
          resource2.setType("gce_instance");
          resource2.setLabels(resourceLabels2);
  
          TimeInterval time1 = new TimeInterval();
          time1.setEndTime("2016-08-08T00:00:00Z");
  
          TimeInterval time2 = new TimeInterval();
          time2.setEndTime("2016-08-08T00:00:01Z");
  
          TimeInterval time3 = new TimeInterval();
          time3.setEndTime("2016-08-08T00:00:02Z");
  
          Point p1 = new Point();
          p1.setInterval(time1);
          p1.setValue(new TypedValue());
          p1.getValue().setDoubleValue(77.0);
  
          Point p2 = new Point();
          p2.setInterval(time2);
          p2.setValue(new TypedValue());
          p2.getValue().setDoubleValue(88.0);
  
          Point p3 = new Point();
          p3.setInterval(time1);
          p3.setValue(new TypedValue());
          p3.getValue().setInt64Value(99l);
  
          Point p4 = new Point();
          p4.setInterval(time3);
          p4.setValue(new TypedValue());
          p4.getValue().setBoolValue(true);
  
          TimeSeries ts1 = new TimeSeries();
          ts1.setMetric(metric1);
          ts1.setResource(resource1);
          ts1.setPoints(Lists.newArrayList(p1, p2));
          ts1.setValueType("DOUBLE");
          ts1.setMetricKind("GAUGE");
  
          // This TimeSeries will be skipped because it has the wrong metric type.
          TimeSeries ts2 = new TimeSeries();
          ts2.setMetric(metric2);
          ts2.setResource(resource1);
          ts2.setPoints(Lists.newArrayList(p2));
          ts2.setValueType("DOUBLE");
          ts2.setMetricKind("GAUGE");
  
          TimeSeries ts3 = new TimeSeries();
          ts3.setMetric(metric3);
          ts3.setResource(resource1);
          ts3.setPoints(Lists.newArrayList(p3));
          ts3.setValueType("INT64");
          ts3.setMetricKind("GAUGE");
  
          TimeSeries ts4 = new TimeSeries();
          ts4.setMetric(metric4);
          ts4.setResource(resource2);
          ts4.setPoints(Lists.newArrayList(p4));
          ts4.setValueType("BOOL");
          ts4.setMetricKind("GAUGE");
  
          ListTimeSeriesResponse response = new ListTimeSeriesResponse();
          response.setTimeSeries(Lists.newArrayList(ts1, ts2, ts3, ts4));
  
          List<String> allMetrics = new ArrayList<>();
          allMetrics.add("custom.googleapis.com/test");
  
          Map<String, Map<String, Record>> byTime = new TreeMap<>();
          GoogleMonitoringIngester ingester = new GoogleMonitoringIngester(conf);
          ingester.processResponse(response, allMetrics, byTime);
  
          assertEquals(3, byTime.size());
  
          Map<String, Record> recordMap1 = byTime.get("2016-08-08T00:00:00Z");
          List<Record> records1 = Lists.newArrayList(recordMap1.values());
          assertEquals(2, records1.size());
          assertEquals(2, records1.get(0).attributes.size());
          assertEquals("foo", records1.get(0).attributes.get("attr1"));
          assertEquals("baz", records1.get(0).attributes.get("attr2"));
          assertEquals(99, records1.get(0).values.get("custom.googleapis.com/test"), 0.0);
          assertEquals(2, records1.get(1).attributes.size());
          assertEquals("foo", records1.get(1).attributes.get("attr1"));
          assertEquals("bar", records1.get(1).attributes.get("attr2"));
          assertEquals(77, records1.get(1).values.get("custom.googleapis.com/test"), 0.0);
  
          Map<String, Record> recordMap2 = byTime.get("2016-08-08T00:00:01Z");
          List<Record> records2 = Lists.newArrayList(recordMap2.values());
          assertEquals(1, records2.size());
          assertEquals(2, records2.get(0).attributes.size());
          assertEquals("foo", records2.get(0).attributes.get("attr1"));
          assertEquals("bar", records2.get(0).attributes.get("attr2"));
          assertEquals(88, records2.get(0).values.get("custom.googleapis.com/test"), 0.0);
  
          Map<String, Record> recordMap3 = byTime.get("2016-08-08T00:00:02Z");
          List<Record> records3 = Lists.newArrayList(recordMap3.values());
          assertEquals(1, records3.size());
          assertEquals(2, records3.get(0).attributes.size());
          assertEquals("foo", records3.get(0).attributes.get("attr1"));
          assertEquals("bar", records3.get(0).attributes.get("attr2"));
          assertEquals(1.0, records3.get(0).values.get("custom.googleapis.com/test"), 0.0);
      }
test_case.class_method_signature: GoogleMonitoringIngesterTest.testProcessResponse()
test_case.full_signature: @Test public void testProcessResponse()
test_case.identifier: testProcessResponse
test_case.invocations: put put put put put setType setLabels setType setLabels setType setLabels setType setLabels put put put put put setType setLabels setType setLabels setEndTime setEndTime setEndTime setInterval setValue setDoubleValue getValue setInterval setValue setDoubleValue getValue setInterval setValue setInt64Value getValue setInterval setValue setBoolValue getValue setMetric setResource setPoints newArrayList setValueType setMetricKind setMetric setResource setPoints newArrayList setValueType setMetricKind setMetric setResource setPoints newArrayList setValueType setMetricKind setMetric setResource setPoints newArrayList setValueType setMetricKind setTimeSeries newArrayList add processResponse assertEquals size get newArrayList values assertEquals size assertEquals size get assertEquals get get assertEquals get get assertEquals get get assertEquals size get assertEquals get get assertEquals get get assertEquals get get get newArrayList values assertEquals size assertEquals size get assertEquals get get assertEquals get get assertEquals get get get newArrayList values assertEquals size assertEquals size get assertEquals get get assertEquals get get assertEquals get get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testProcessResponse()
focal_class.declarator: log = LoggerFactory.getLogger(GoogleMonitoringIngester.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger log = LoggerFactory.getLogger(GoogleMonitoringIngester.class);
focal_class.type: Logger
focal_class.var_name: log
focal_class.declarator: GOOGLE_MONITORING_QUERIES = "macrobase.loader.googlemonitoring.queries"
focal_class.modifier: public static final
focal_class.original_string: public static final String GOOGLE_MONITORING_QUERIES = "macrobase.loader.googlemonitoring.queries";
focal_class.type: String
focal_class.var_name: GOOGLE_MONITORING_QUERIES
focal_class.declarator: GOOGLE_MONITORING_START_TIME = "macrobase.loader.googlemonitoring.startTime"
focal_class.modifier: public static final
focal_class.original_string: public static final String GOOGLE_MONITORING_START_TIME = "macrobase.loader.googlemonitoring.startTime";
focal_class.type: String
focal_class.var_name: GOOGLE_MONITORING_START_TIME
focal_class.declarator: GOOGLE_MONITORING_END_TIME = "macrobase.loader.googlemonitoring.endTime"
focal_class.modifier: public static final
focal_class.original_string: public static final String GOOGLE_MONITORING_END_TIME = "macrobase.loader.googlemonitoring.endTime";
focal_class.type: String
focal_class.var_name: GOOGLE_MONITORING_END_TIME
focal_class.declarator: dataStream
focal_class.modifier: private
focal_class.original_string: private MBStream<Datum> dataStream;
focal_class.type: MBStream<Datum>
focal_class.var_name: dataStream
focal_class.declarator: loaded = false
focal_class.modifier: private
focal_class.original_string: private boolean loaded = false;
focal_class.type: boolean
focal_class.var_name: loaded
focal_class.declarator: pointsAdded = 0
focal_class.modifier: private
focal_class.original_string: private int pointsAdded = 0;
focal_class.type: int
focal_class.var_name: pointsAdded
focal_class.declarator: skippedTimeSeries = 0
focal_class.modifier: private
focal_class.original_string: private int skippedTimeSeries = 0;
focal_class.type: int
focal_class.var_name: skippedTimeSeries
focal_class.declarator: skippedPoints = 0
focal_class.modifier: private
focal_class.original_string: private int skippedPoints = 0;
focal_class.type: int
focal_class.var_name: skippedPoints
focal_class.file: contrib/src/main/java/macrobase/ingest/GoogleMonitoringIngester.java
focal_class.identifier: GoogleMonitoringIngester
focal_class.class_method_signature: GoogleMonitoringIngester.GoogleMonitoringIngester(MacroBaseConf conf)
focal_class.full_signature: public  GoogleMonitoringIngester(MacroBaseConf conf)
focal_class.identifier: GoogleMonitoringIngester
focal_class.modifiers: public
focal_class.parameters: (MacroBaseConf conf)
focal_class.signature:  GoogleMonitoringIngester(MacroBaseConf conf)
focal_class.class_method_signature: GoogleMonitoringIngester.getStream()
focal_class.full_signature: @Override public MBStream<Datum> getStream()
focal_class.identifier: getStream
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: MBStream<Datum>
focal_class.signature: MBStream<Datum> getStream()
focal_class.class_method_signature: GoogleMonitoringIngester.getQueries(String queryJson)
focal_class.full_signature:  QueryConf getQueries(String queryJson)
focal_class.identifier: getQueries
focal_class.parameters: (String queryJson)
focal_class.return: QueryConf
focal_class.signature: QueryConf getQueries(String queryJson)
focal_class.class_method_signature: GoogleMonitoringIngester.processResponse(ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)
focal_class.full_signature:  void processResponse(ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)
focal_class.identifier: processResponse
focal_class.parameters: (ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)
focal_class.return: void
focal_class.signature: void processResponse(ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)
focal_class.class_method_signature: GoogleMonitoringIngester.processRecord(Record rec)
focal_class.full_signature:  Datum processRecord(Record rec)
focal_class.identifier: processRecord
focal_class.parameters: (Record rec)
focal_class.return: Datum
focal_class.signature: Datum processRecord(Record rec)
focal_class.class_method_signature: GoogleMonitoringIngester.convertToStream(Map<String, Map<String, Record>> byTime)
focal_class.full_signature:  MBStream<Datum> convertToStream(Map<String, Map<String, Record>> byTime)
focal_class.identifier: convertToStream
focal_class.parameters: (Map<String, Map<String, Record>> byTime)
focal_class.return: MBStream<Datum>
focal_class.signature: MBStream<Datum> convertToStream(Map<String, Map<String, Record>> byTime)
focal_class.class_method_signature: GoogleMonitoringIngester.buildClient()
focal_class.full_signature: private Monitoring buildClient()
focal_class.identifier: buildClient
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.return: Monitoring
focal_class.signature: Monitoring buildClient()
focal_class.superclass: extends DataIngester
focal_method.body: void processResponse(ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime) {
  
          for (TimeSeries ts : response.getTimeSeries()) {
              if (!allMetrics.contains(ts.getMetric().getType())) {
                  ++skippedTimeSeries;
                  continue;
              }
  
              // Extract attribute values from TimeSeries metric/resource labels. If some are
              // missing, skip this time series. Keep the keys sorted so that they correspond
              // to the attribute names recorded in the encoder.
              Map<String, String> attrMap = new TreeMap<>();
              boolean hasAllAttributes = true;
  
              for (String a : attributes) {
                  String val = ts.getMetric().getLabels().get(a);
                  if (val == null) {
                      val = ts.getResource().getLabels().get(a);
                      if (val == null) {
                          log.debug("Skipping TimeSeries due to missing attribute: " + a);
                          hasAllAttributes = false;
                          break;
                      }
                  }
                  attrMap.put(a, val);
              }
  
              if (!hasAllAttributes) {
                  ++skippedTimeSeries;
                  continue;
              }
              String attrKey = attrMap.toString();
  
              for (Point p : ts.getPoints()) {
                  String timestamp = p.getInterval().getEndTime();
  
                  byTime.putIfAbsent(timestamp, new HashMap<>());
                  Record rec = byTime.get(timestamp).putIfAbsent(attrKey, new Record());
                  if (rec == null) {
                      rec = byTime.get(timestamp).get(attrKey);
                      rec.attributes = attrMap;
                      rec.values = new HashMap<>();
                  }
  
                  double val;
                  switch (ts.getValueType()) {
                      case "DOUBLE":
                          val = p.getValue().getDoubleValue();
                          break;
                      case "INT64":
                          val = p.getValue().getInt64Value();
                          break;
                      case "BOOL":
                          val = (p.getValue().getBoolValue()) ? 1.0 : 0.0;
                          break;
                      default:
                          continue;
                  }
  
                  rec.values.put(ts.getMetric().getType(), val);
              }
          }
      }
focal_method.class_method_signature: GoogleMonitoringIngester.processResponse(ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)
focal_method.full_signature:  void processResponse(ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)
focal_method.identifier: processResponse
focal_method.invocations: getTimeSeries contains getType getMetric get getLabels getMetric get getLabels getResource debug put toString getPoints getEndTime getInterval putIfAbsent putIfAbsent get get get getValueType getDoubleValue getValue getInt64Value getValue getBoolValue getValue put getType getMetric
focal_method.parameters: (ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)
focal_method.return: void
focal_method.signature: void processResponse(ListTimeSeriesResponse response, List<String> allMetrics,
                           Map<String, Map<String, Record>> byTime)