From 9cfdfb79e4ceabe25dfdeea03c9d4e83be86420e Mon Sep 17 00:00:00 2001 From: eitah Date: Thu, 7 Apr 2022 18:11:20 +0200 Subject: [PATCH 1/3] Metrics-ingest-delay bugfix Signed-off-by: eitah --- README.md | 1 + collectors/monitoring_collector.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 054aa7ab..fc3f9795 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ If you are still using the legacy [Access scopes][access-scopes], the `https://w | `monitoring.filters` | No | | Formatted string to allow filtering on certain metrics type | | `web.listen-address` | No | `:9255` | Address to listen on for web interface and telemetry | | `web.telemetry-path` | No | `/metrics` | Path under which to expose Prometheus metrics | +| `monitoring.metrics-ingest-delay` | No | | Offsets metric collection by a delay appropriate for each metric type, e.g. because bigquery metrics are slow to appear | ### Metrics diff --git a/collectors/monitoring_collector.go b/collectors/monitoring_collector.go index 5f6f1698..369278f8 100644 --- a/collectors/monitoring_collector.go +++ b/collectors/monitoring_collector.go @@ -266,6 +266,11 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri metricDescriptor.Type) } + if metricDescriptor.DisplayName == "Stored bytes" { + fmt.Printf("\n start pre \n %+v \n\n\n\n", startTime.Format(time.RFC3339Nano)) + fmt.Printf("\n\n end pre \n %+v \n\n\n\n", endTime.Format(time.RFC3339Nano)) + } + if c.metricsIngestDelay && metricDescriptor.Metadata != nil && metricDescriptor.Metadata.IngestDelay != "" { @@ -277,10 +282,14 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri return } level.Debug(c.logger).Log("msg", "adding ingest delay", "descriptor", metricDescriptor.Type, "delay", ingestDelay) - endTime.Add(ingestDelayDuration) - startTime.Add(ingestDelayDuration) + endTime = endTime.Add(ingestDelayDuration * -1) + startTime = startTime.Add(ingestDelayDuration * -1) } + if metricDescriptor.DisplayName == "Stored bytes" { + fmt.Printf("\n start post \n %+v \n\n\n\n", startTime.Format(time.RFC3339Nano)) + fmt.Printf("\n\n end post \n %+v \n\n\n\n", endTime.Format(time.RFC3339Nano)) + } for _, ef := range c.metricsFilters { if strings.Contains(metricDescriptor.Type, ef.Prefix) { filter = fmt.Sprintf("%s AND (%s)", filter, ef.Modifier) @@ -356,6 +365,7 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri } func (c *MonitoringCollector) reportTimeSeriesMetrics( + page *monitoring.ListTimeSeriesResponse, metricDescriptor *monitoring.MetricDescriptor, ch chan<- prometheus.Metric, From 1ad81b9280cfc6a029c9e8bd2ecfb956e2d27a08 Mon Sep 17 00:00:00 2001 From: eitah Date: Thu, 7 Apr 2022 18:16:03 +0200 Subject: [PATCH 2/3] Drop print statements Signed-off-by: eitah --- collectors/monitoring_collector.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/collectors/monitoring_collector.go b/collectors/monitoring_collector.go index 369278f8..c5c9fa08 100644 --- a/collectors/monitoring_collector.go +++ b/collectors/monitoring_collector.go @@ -266,11 +266,6 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri metricDescriptor.Type) } - if metricDescriptor.DisplayName == "Stored bytes" { - fmt.Printf("\n start pre \n %+v \n\n\n\n", startTime.Format(time.RFC3339Nano)) - fmt.Printf("\n\n end pre \n %+v \n\n\n\n", endTime.Format(time.RFC3339Nano)) - } - if c.metricsIngestDelay && metricDescriptor.Metadata != nil && metricDescriptor.Metadata.IngestDelay != "" { @@ -286,10 +281,6 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri startTime = startTime.Add(ingestDelayDuration * -1) } - if metricDescriptor.DisplayName == "Stored bytes" { - fmt.Printf("\n start post \n %+v \n\n\n\n", startTime.Format(time.RFC3339Nano)) - fmt.Printf("\n\n end post \n %+v \n\n\n\n", endTime.Format(time.RFC3339Nano)) - } for _, ef := range c.metricsFilters { if strings.Contains(metricDescriptor.Type, ef.Prefix) { filter = fmt.Sprintf("%s AND (%s)", filter, ef.Modifier) @@ -365,7 +356,6 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri } func (c *MonitoringCollector) reportTimeSeriesMetrics( - page *monitoring.ListTimeSeriesResponse, metricDescriptor *monitoring.MetricDescriptor, ch chan<- prometheus.Metric, From 83381f1cdfc515c7bf5d35985611544b5d187290 Mon Sep 17 00:00:00 2001 From: "E. Itah" Date: Thu, 7 Apr 2022 19:59:12 +0200 Subject: [PATCH 3/3] Update README.md Alphabetize readme Signed-off-by: eitah --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fc3f9795..785e241d 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,13 @@ If you are still using the legacy [Access scopes][access-scopes], the `https://w | Flag | Required | Default | Description | | --------------------------------- | -------- | ------- | ----------- | | `google.project-id` | No | GCloud SDK auto-discovery | Comma seperated list of Google Project IDs | +| `monitoring.metrics-ingest-delay` | No | | Offsets metric collection by a delay appropriate for each metric type, e.g. because bigquery metrics are slow to appear | | `monitoring.metrics-type-prefixes | Yes | | Comma separated Google Stackdriver Monitoring Metric Type prefixes (see [example][metrics-prefix-example] and [available metrics][metrics-list]) | | `monitoring.metrics-interval` | No | `5m` | Metric's timestamp interval to request from the Google Stackdriver Monitoring Metrics API. Only the most recent data point is used | | `monitoring.metrics-offset` | No | `0s` | Offset (into the past) for the metric's timestamp interval to request from the Google Stackdriver Monitoring Metrics API, to handle latency in published metrics | | `monitoring.filters` | No | | Formatted string to allow filtering on certain metrics type | | `web.listen-address` | No | `:9255` | Address to listen on for web interface and telemetry | | `web.telemetry-path` | No | `/metrics` | Path under which to expose Prometheus metrics | -| `monitoring.metrics-ingest-delay` | No | | Offsets metric collection by a delay appropriate for each metric type, e.g. because bigquery metrics are slow to appear | ### Metrics