Skip to content

Commit 205417f

Browse files
authored
Revert "Add feature to filter project ID at call-time (#164)" (#316)
This reverts commit bc18b73. Signed-off-by: Ben Rottke <[email protected]>
1 parent bc18b73 commit 205417f

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

README.md

+2-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/prometheus-community/stackdriver_exporter)
88
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
99

10-
A [Prometheus][prometheus] exporter for [Google Stackdriver Monitoring][stackdriver] metrics. It acts as a proxy that requests Stackdriver API for the metric's time-series every time prometheus scrapes it.
10+
A [Prometheus][prometheus] exporter for [Google Stackdriver Monitoring][stackdriver] metrics. It acts as a proxy that requests Stackdriver API for the metric's time-series everytime prometheus scrapes it.
1111

1212
## Installation
1313

@@ -167,7 +167,7 @@ stackdriver_exporter \
167167

168168
The `stackdriver_exporter` collects all metrics type prefixes by default.
169169

170-
For advanced uses, the metric prefixes can be filtered by using a repeatable URL param called `collect`. In the Prometheus configuration you can use this syntax under the [scrape config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<scrape_config>).
170+
For advanced uses, the collection can be filtered by using a repeatable URL param called `collect`. In the Prometheus configuration you can use you can use this syntax under the [scrape config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#<scrape_config>).
171171

172172

173173
```yaml
@@ -177,17 +177,6 @@ params:
177177
- compute.googleapis.com/instance/disk
178178
```
179179
180-
The GCP projects to collect metrics from can also be filtered, using the `project_ids` URL param:
181-
```yaml
182-
params:
183-
project_ids:
184-
- project-a
185-
- project-b
186-
collect:
187-
- compute.googleapis.com/instance/cpu
188-
- compute.googleapis.com/instance/disk
189-
```
190-
191180
### What to know about Aggregating DELTA Metrics
192181
193182
Treating DELTA Metrics as a gauge produces data which is wildly inaccurate/not very useful (see https://github.com/prometheus-community/stackdriver_exporter/issues/116). However, aggregating the DELTA metrics overtime is not a perfect solution and is intended to produce data which mirrors GCP's data as close as possible.

stackdriver_exporter.go

+15-19
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,17 @@ type handler struct {
180180

181181
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
182182
collectParams := r.URL.Query()["collect"]
183-
projectIDsParam := r.URL.Query()["project_ids"]
183+
filters := make(map[string]bool)
184+
for _, param := range collectParams {
185+
filters[param] = true
186+
}
184187

185-
projectFilters := make(map[string]bool)
186-
for _, projID := range projectIDsParam {
187-
projectFilters[projID] = true
188+
if len(filters) > 0 {
189+
h.innerHandler(filters).ServeHTTP(w, r)
190+
return
188191
}
189192

190-
h.innerHandler(collectParams, projectFilters).ServeHTTP(w, r)
193+
h.handler.ServeHTTP(w, r)
191194
}
192195

193196
func newHandler(projectIDs []string, metricPrefixes []string, metricExtraFilters []collectors.MetricFilter, m *monitoring.Service, logger log.Logger, additionalGatherer prometheus.Gatherer) *handler {
@@ -200,20 +203,16 @@ func newHandler(projectIDs []string, metricPrefixes []string, metricExtraFilters
200203
m: m,
201204
}
202205

203-
h.handler = h.innerHandler(nil, nil)
206+
h.handler = h.innerHandler(nil)
204207
return h
205208
}
206209

207-
func (h *handler) innerHandler(metricFilters []string, projectFilters map[string]bool) http.Handler {
210+
func (h *handler) innerHandler(filters map[string]bool) http.Handler {
208211
registry := prometheus.NewRegistry()
209212

210213
for _, project := range h.projectIDs {
211-
if len(projectFilters) > 0 && !projectFilters[project] {
212-
continue
213-
}
214-
215214
monitoringCollector, err := collectors.NewMonitoringCollector(project, h.m, collectors.MonitoringCollectorOptions{
216-
MetricTypePrefixes: h.filterMetricTypePrefixes(metricFilters),
215+
MetricTypePrefixes: h.filterMetricTypePrefixes(filters),
217216
ExtraFilters: h.metricsExtraFilters,
218217
RequestInterval: *monitoringMetricsInterval,
219218
RequestOffset: *monitoringMetricsOffset,
@@ -244,16 +243,13 @@ func (h *handler) innerHandler(metricFilters []string, projectFilters map[string
244243

245244
// filterMetricTypePrefixes filters the initial list of metric type prefixes, with the ones coming from an individual
246245
// prometheus collect request.
247-
func (h *handler) filterMetricTypePrefixes(filters []string) []string {
246+
func (h *handler) filterMetricTypePrefixes(filters map[string]bool) []string {
248247
filteredPrefixes := h.metricsPrefixes
249248
if len(filters) > 0 {
250249
filteredPrefixes = nil
251-
for _, calltimePrefix := range filters {
252-
for _, preconfiguredPrefix := range h.metricsPrefixes {
253-
if strings.HasPrefix(calltimePrefix, preconfiguredPrefix) {
254-
filteredPrefixes = append(filteredPrefixes, calltimePrefix)
255-
break
256-
}
250+
for _, prefix := range h.metricsPrefixes {
251+
if filters[prefix] {
252+
filteredPrefixes = append(filteredPrefixes, prefix)
257253
}
258254
}
259255
}

0 commit comments

Comments
 (0)