private void writeMetrics()

in src/main/java/com/google/cloud/run/kafkascaler/Scaler.java [241:252]


  private void writeMetrics(long currentLag, int recommendedInstanceCount, int newInstanceCount) {
    try {
      metricsService.writeMetric(LAG_METRIC_NAME, (double) currentLag, metricLabels);
      metricsService.writeMetric(
          RECOMMENDED_INSTANCE_COUNT_METRIC_NAME, (double) recommendedInstanceCount, metricLabels);
      metricsService.writeMetric(
          REQUESTED_INSTANCE_COUNT_METRIC_NAME, (double) newInstanceCount, metricLabels);
    } catch (RuntimeException ex) {
      // An exception here is not critical to scaling. Log the exception and continue.
      logger.atWarning().withCause(ex).log("Failed to write metrics to Cloud Monitoring.");
    }
  }