Skip to content

Commit f0f1d7e

Browse files
committed
Remove bucket_patterns param
This can be achieved in prometheus with a relabel_config.
1 parent d42b01a commit f0f1d7e

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,37 @@ exporter has access to.
116116

117117
This should be all the config required to successfully scrape every bucket:
118118

119-
```
119+
```yml
120120
scrape_configs:
121-
- job_name: 's3'
121+
- job_name: "s3"
122122
metrics_path: /probe
123123
http_sd_configs:
124124
- url: http://127.0.0.1:9340/discovery
125125
```
126126

127-
You can limit the buckets returned with the `bucket_pattern` parameter. Refer to
128-
the documentation for [`path.Match`](https://golang.org/pkg/path/#Match) for the
129-
pattern syntax.
127+
Use `relabel_configs` to select the buckets you want to scrape:
130128

131-
```
129+
```yml
132130
scrape_configs:
133-
- job_name: 's3'
131+
- job_name: "s3"
134132
metrics_path: /probe
135133
http_sd_configs:
136-
# This will only discover buckets with a name that starts with example-
137-
- url: http://127.0.0.1:9340/discovery?bucket_pattern=example-*
134+
- url: http://127.0.0.1:9340/discovery
135+
relabel_configs:
136+
# Keep buckets that start with example-
137+
- source_labels: [__param_bucket]
138+
action: keep
139+
regex: ^example-.*
138140
```
139141

140142
The prefix can be set too, but be mindful that this will apply to all buckets:
141143

142-
```
144+
```yml
143145
scrape_configs:
144-
- job_name: 's3'
146+
- job_name: "s3"
145147
metrics_path: /probe
146148
http_sd_configs:
147-
- url: http://127.0.0.1:9340/discovery?bucket_pattern=example-*
149+
- url: http://127.0.0.1:9340/discovery
148150
params:
149151
prefix: ["thing.txt"]
150152
```

s3_exporter.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"net/http"
66
"os"
7-
"path"
87
"time"
98

109
"github.com/prometheus/client_golang/prometheus"
@@ -173,27 +172,17 @@ type discoveryTarget struct {
173172
}
174173

175174
func discoveryHandler(w http.ResponseWriter, r *http.Request, svc s3iface.S3API) {
176-
// If a bucket pattern isn't specified, then return every bucket
177-
bucketPattern := r.URL.Query().Get("bucket_pattern")
178-
if bucketPattern == "" {
179-
bucketPattern = "*"
180-
}
181-
182175
result, err := svc.ListBuckets(&s3.ListBucketsInput{})
183176
if err != nil {
177+
log.Errorln(err)
184178
http.Error(w, "error listing buckets", http.StatusInternalServerError)
185179
return
186180
}
187181

188182
targets := []discoveryTarget{}
189183
for _, b := range result.Buckets {
190184
name := aws.StringValue(b.Name)
191-
192-
matched, err := path.Match(bucketPattern, name)
193-
if err != nil {
194-
http.Error(w, "bad pattern provided for 'bucket_pattern'", http.StatusBadRequest)
195-
}
196-
if matched {
185+
if name != "" {
197186
t := discoveryTarget{
198187
Targets: []string{r.Host},
199188
Labels: map[string]string{

0 commit comments

Comments
 (0)