Skip to content

Commit

Permalink
use string to give more flexibility on filter to allow devs use AND/OR
Browse files Browse the repository at this point in the history
Signed-off-by: vrunoa <vruno.alassia@gmail.com>
  • Loading branch information
vrunoa committed Nov 8, 2021
1 parent b00863c commit 719623e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions collectors/monitoring_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ var (
).Envar("STACKDRIVER_EXPORTER_DROP_DELEGATED_PROJECTS").Default("false").Bool()

monitoringExtraFilters = kingpin.Flag(
"monitoring.extra.filter", "Extra filters. i.e: resource.labels.subscription_id=monitoring.regex.full_match(\"my-subs-prefix.*\")").Strings()
"monitoring.extra.filters", "Extra filters. i.e: resource.labels.subscription_id=monitoring.regex.full_match(\"my-subs-prefix.*\")").Default("").String()
)

type MonitoringCollector struct {
projectID string
metricsTypePrefixes []string
monitoringExtraFilters []string
monitoringExtraFilters string
metricsInterval time.Duration
metricsOffset time.Duration
monitoringService *monitoring.Service
Expand Down Expand Up @@ -243,10 +243,8 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri
c.projectID,
metricDescriptor.Type)
}
if len(c.monitoringExtraFilters) > 0 {
for _, extraFilter := range c.monitoringExtraFilters {
filter = fmt.Sprintf("%s AND %s", filter, extraFilter)
}
if *monitoringExtraFilters != ""{
filter = fmt.Sprintf("%s AND (%s)", filter, *monitoringExtraFilters)
}
level.Debug(c.logger).Log("msg", "retrieving Google Stackdriver Monitoring metrics with filter", "filter", filter)

Expand Down

0 comments on commit 719623e

Please sign in to comment.