Skip to content

Commit fbf4cc6

Browse files
committed
chore: Comment auth examples to get rid of common pkg deps
Signed-off-by: Jorge Turrado <[email protected]>
1 parent a5ae203 commit fbf4cc6

File tree

3 files changed

+101
-112
lines changed

3 files changed

+101
-112
lines changed

api/prometheus/v1/example_test.go

Lines changed: 101 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"os"
2323
"time"
2424

25-
"github.com/prometheus/common/config"
26-
2725
"github.com/prometheus/client_golang/api"
2826
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
2927
)
@@ -133,111 +131,117 @@ func ExampleAPI_queryRangeWithUserAgent() {
133131
fmt.Printf("Result:\n%v\n", result)
134132
}
135133

134+
// NOTE: This example is commented to avoid adding unnecessary dependencies to client_golang.
135+
// To run the example, please uncomment the commented lines.
136136
func ExampleAPI_queryRangeWithBasicAuth() {
137-
client, err := api.NewClient(api.Config{
138-
Address: DemoPrometheusURL,
139-
// We can use amazing github.com/prometheus/common/config helper!
140-
RoundTripper: config.NewBasicAuthRoundTripper(
141-
config.NewInlineSecret("me"),
142-
config.NewInlineSecret("definitely_me"),
143-
api.DefaultRoundTripper,
144-
),
145-
})
146-
if err != nil {
147-
fmt.Printf("Error creating client: %v\n", err)
148-
os.Exit(1)
149-
}
137+
// client, err := api.NewClient(api.Config{
138+
// Address: DemoPrometheusURL,
139+
// // We can use amazing github.com/prometheus/common/config helper!
140+
// RoundTripper: config.NewBasicAuthRoundTripper(
141+
// config.NewInlineSecret("me"),
142+
// config.NewInlineSecret("definitely_me"),
143+
// api.DefaultRoundTripper,
144+
// ),
145+
// })
146+
// if err != nil {
147+
// fmt.Printf("Error creating client: %v\n", err)
148+
// os.Exit(1)
149+
// }
150150

151-
v1api := v1.NewAPI(client)
152-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
153-
defer cancel()
154-
r := v1.Range{
155-
Start: time.Now().Add(-time.Hour),
156-
End: time.Now(),
157-
Step: time.Minute,
158-
}
159-
result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r)
160-
if err != nil {
161-
fmt.Printf("Error querying Prometheus: %v\n", err)
162-
os.Exit(1)
163-
}
164-
if len(warnings) > 0 {
165-
fmt.Printf("Warnings: %v\n", warnings)
166-
}
167-
fmt.Printf("Result:\n%v\n", result)
151+
// v1api := v1.NewAPI(client)
152+
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
153+
// defer cancel()
154+
// r := v1.Range{
155+
// Start: time.Now().Add(-time.Hour),
156+
// End: time.Now(),
157+
// Step: time.Minute,
158+
// }
159+
// result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r)
160+
// if err != nil {
161+
// fmt.Printf("Error querying Prometheus: %v\n", err)
162+
// os.Exit(1)
163+
// }
164+
// if len(warnings) > 0 {
165+
// fmt.Printf("Warnings: %v\n", warnings)
166+
// }
167+
// fmt.Printf("Result:\n%v\n", result)
168168
}
169169

170+
// NOTE: This example is commented to avoid adding unnecessary dependencies to client_golang.
171+
// To run the example, please uncomment the commented lines.
170172
func ExampleAPI_queryRangeWithAuthBearerToken() {
171-
client, err := api.NewClient(api.Config{
172-
Address: DemoPrometheusURL,
173-
// We can use amazing github.com/prometheus/common/config helper!
174-
RoundTripper: config.NewAuthorizationCredentialsRoundTripper(
175-
"Bearer",
176-
config.NewInlineSecret("secret_token"),
177-
api.DefaultRoundTripper,
178-
),
179-
})
180-
if err != nil {
181-
fmt.Printf("Error creating client: %v\n", err)
182-
os.Exit(1)
183-
}
173+
// client, err := api.NewClient(api.Config{
174+
// Address: DemoPrometheusURL,
175+
// // We can use amazing github.com/prometheus/common/config helper!
176+
// RoundTripper: config.NewAuthorizationCredentialsRoundTripper(
177+
// "Bearer",
178+
// config.NewInlineSecret("secret_token"),
179+
// api.DefaultRoundTripper,
180+
// ),
181+
// })
182+
// if err != nil {
183+
// fmt.Printf("Error creating client: %v\n", err)
184+
// os.Exit(1)
185+
// }
184186

185-
v1api := v1.NewAPI(client)
186-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
187-
defer cancel()
188-
r := v1.Range{
189-
Start: time.Now().Add(-time.Hour),
190-
End: time.Now(),
191-
Step: time.Minute,
192-
}
193-
result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r)
194-
if err != nil {
195-
fmt.Printf("Error querying Prometheus: %v\n", err)
196-
os.Exit(1)
197-
}
198-
if len(warnings) > 0 {
199-
fmt.Printf("Warnings: %v\n", warnings)
200-
}
201-
fmt.Printf("Result:\n%v\n", result)
187+
// v1api := v1.NewAPI(client)
188+
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
189+
// defer cancel()
190+
// r := v1.Range{
191+
// Start: time.Now().Add(-time.Hour),
192+
// End: time.Now(),
193+
// Step: time.Minute,
194+
// }
195+
// result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r)
196+
// if err != nil {
197+
// fmt.Printf("Error querying Prometheus: %v\n", err)
198+
// os.Exit(1)
199+
// }
200+
// if len(warnings) > 0 {
201+
// fmt.Printf("Warnings: %v\n", warnings)
202+
// }
203+
// fmt.Printf("Result:\n%v\n", result)
202204
}
203205

206+
// NOTE: This example is commented to avoid adding unnecessary dependencies to client_golang.
207+
// To run the example, please uncomment the commented lines.
204208
func ExampleAPI_queryRangeWithAuthBearerTokenHeadersRoundTripper() {
205-
client, err := api.NewClient(api.Config{
206-
Address: DemoPrometheusURL,
207-
// We can use amazing github.com/prometheus/common/config helper!
208-
RoundTripper: config.NewHeadersRoundTripper(
209-
&config.Headers{
210-
Headers: map[string]config.Header{
211-
"Authorization": {
212-
Values: []string{"Bearer secret"},
213-
},
214-
},
215-
},
216-
api.DefaultRoundTripper,
217-
),
218-
})
219-
if err != nil {
220-
fmt.Printf("Error creating client: %v\n", err)
221-
os.Exit(1)
222-
}
209+
// client, err := api.NewClient(api.Config{
210+
// Address: DemoPrometheusURL,
211+
// // We can use amazing github.com/prometheus/common/config helper!
212+
// RoundTripper: config.NewHeadersRoundTripper(
213+
// &config.Headers{
214+
// Headers: map[string]config.Header{
215+
// "Authorization": {
216+
// Values: []string{"Bearer secret"},
217+
// },
218+
// },
219+
// },
220+
// api.DefaultRoundTripper,
221+
// ),
222+
// })
223+
// if err != nil {
224+
// fmt.Printf("Error creating client: %v\n", err)
225+
// os.Exit(1)
226+
// }
223227

224-
v1api := v1.NewAPI(client)
225-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
226-
defer cancel()
227-
r := v1.Range{
228-
Start: time.Now().Add(-time.Hour),
229-
End: time.Now(),
230-
Step: time.Minute,
231-
}
232-
result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r)
233-
if err != nil {
234-
fmt.Printf("Error querying Prometheus: %v\n", err)
235-
os.Exit(1)
236-
}
237-
if len(warnings) > 0 {
238-
fmt.Printf("Warnings: %v\n", warnings)
239-
}
240-
fmt.Printf("Result:\n%v\n", result)
228+
// v1api := v1.NewAPI(client)
229+
// ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
230+
// defer cancel()
231+
// r := v1.Range{
232+
// Start: time.Now().Add(-time.Hour),
233+
// End: time.Now(),
234+
// Step: time.Minute,
235+
// }
236+
// result, warnings, err := v1api.QueryRange(ctx, "rate(prometheus_tsdb_head_samples_appended_total[5m])", r)
237+
// if err != nil {
238+
// fmt.Printf("Error querying Prometheus: %v\n", err)
239+
// os.Exit(1)
240+
// }
241+
// if len(warnings) > 0 {
242+
// fmt.Printf("Warnings: %v\n", warnings)
243+
// }
244+
// fmt.Printf("Result:\n%v\n", result)
241245
}
242246

243247
func ExampleAPI_series() {

go.mod

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,11 @@ require (
1818
)
1919

2020
require (
21-
github.com/jpillora/backoff v1.0.0 // indirect
2221
github.com/kr/pretty v0.3.1 // indirect
2322
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2423
github.com/modern-go/reflect2 v1.0.2 // indirect
2524
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
26-
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
2725
go.yaml.in/yaml/v2 v2.4.3 // indirect
28-
golang.org/x/net v0.46.0 // indirect
29-
golang.org/x/oauth2 v0.32.0 // indirect
30-
golang.org/x/text v0.30.0 // indirect
3126
)
3227

3328
exclude github.com/prometheus/client_golang v1.12.1

go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
99
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
1010
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1111
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
12-
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
13-
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
1412
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
1513
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
1614
github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co=
@@ -28,8 +26,6 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
2826
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
2927
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
3028
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
31-
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
32-
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
3329
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
3430
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3531
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -50,14 +46,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
5046
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
5147
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
5248
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
53-
golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
54-
golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
55-
golang.org/x/oauth2 v0.32.0 h1:jsCblLleRMDrxMN29H3z/k1KliIvpLgCkE6R8FXXNgY=
56-
golang.org/x/oauth2 v0.32.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA=
5749
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
5850
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
59-
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
60-
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
6151
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
6252
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
6353
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)