Skip to content

Commit 3ba14c0

Browse files
authored
Merge pull request #54 from weaveworks/less-logging
Don't log successful requests
2 parents 725356d + 2a49f3e commit 3ba14c0

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

cmd/prism/main.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ var (
5454
Help: "Time (in seconds) spent serving HTTP requests.",
5555
Buckets: prometheus.DefBuckets,
5656
}, []string{"method", "route", "status_code", "ws"})
57-
instr = middleware.Merge(
58-
middleware.Logging,
59-
middleware.Instrument{
60-
Duration: requestDuration,
61-
},
62-
).Wrap
6357
)
6458

6559
func init() {
@@ -82,6 +76,7 @@ type cfg struct {
8276
flushPeriod time.Duration
8377
maxChunkAge time.Duration
8478
numTokens int
79+
logSuccess bool
8580

8681
distributorConfig prism.DistributorConfig
8782
}
@@ -107,6 +102,7 @@ func main() {
107102
flag.IntVar(&cfg.distributorConfig.MinReadSuccesses, "distributor.min-read-successes", 2, "The minimum number of ingesters from which a read must succeed.")
108103
flag.IntVar(&cfg.distributorConfig.MinWriteSuccesses, "distributor.min-write-successes", 2, "The minimum number of ingesters to which a write must succeed.")
109104
flag.DurationVar(&cfg.distributorConfig.HeartbeatTimeout, "distributor.heartbeat-timeout", time.Minute, "The heartbeat timeout after which ingesters are skipped for reads/writes.")
105+
flag.BoolVar(&cfg.logSuccess, "log.success", false, "Log successful requests")
110106
flag.Parse()
111107

112108
chunkStore, err := setupChunkStore(cfg)
@@ -128,7 +124,7 @@ func main() {
128124
return prism.NewIngesterClient(address, cfg.remoteTimeout)
129125
}
130126
defer ring.Stop()
131-
setupDistributor(cfg.distributorConfig, chunkStore)
127+
setupDistributor(cfg.distributorConfig, chunkStore, cfg.logSuccess)
132128
if err != nil {
133129
log.Fatalf("Error initializing distributor: %v", err)
134130
}
@@ -141,11 +137,11 @@ func main() {
141137
log.Fatalf("Could not register ingester: %v", err)
142138
}
143139
defer registration.Unregister()
144-
cfg := ingester.Config{
140+
ingesterCfg := ingester.Config{
145141
FlushCheckPeriod: cfg.flushPeriod,
146142
MaxChunkAge: cfg.maxChunkAge,
147143
}
148-
ing := setupIngester(chunkStore, cfg)
144+
ing := setupIngester(chunkStore, ingesterCfg, cfg.logSuccess)
149145
defer ing.Stop()
150146
default:
151147
log.Fatalf("Mode %s not supported!", cfg.mode)
@@ -192,15 +188,16 @@ func setupChunkStore(cfg cfg) (chunk.Store, error) {
192188
func setupDistributor(
193189
cfg prism.DistributorConfig,
194190
chunkStore chunk.Store,
191+
logSuccess bool,
195192
) {
196193
distributor := prism.NewDistributor(cfg)
197194
prometheus.MustRegister(distributor)
198195

199196
prefix := "/api/prom"
200-
http.Handle(prefix+"/push", instr(prism.AppenderHandler(distributor)))
197+
http.Handle(prefix+"/push", instrument(logSuccess, prism.AppenderHandler(distributor)))
201198

202199
// TODO: Move querier to separate binary.
203-
setupQuerier(distributor, chunkStore, prefix)
200+
setupQuerier(distributor, chunkStore, prefix, logSuccess)
204201
}
205202

206203
// setupQuerier sets up a complete querying pipeline:
@@ -212,6 +209,7 @@ func setupQuerier(
212209
distributor *prism.Distributor,
213210
chunkStore chunk.Store,
214211
prefix string,
212+
logSuccess bool,
215213
) {
216214
querier := prism.MergeQuerier{
217215
Queriers: []prism.Querier{
@@ -240,22 +238,35 @@ func setupQuerier(
240238
api.Register(router.WithPrefix(prefix + "/api/v1"))
241239
http.Handle("/", router)
242240

243-
http.Handle(prefix+"/graph", instr(ui.GraphHandler()))
244-
http.Handle(prefix+"/static/", instr(ui.StaticAssetsHandler(prefix+"/static/")))
241+
http.Handle(prefix+"/graph", instrument(logSuccess, ui.GraphHandler()))
242+
http.Handle(prefix+"/static/", instrument(logSuccess, ui.StaticAssetsHandler(prefix+"/static/")))
245243
}
246244

247245
func setupIngester(
248246
chunkStore chunk.Store,
249247
cfg ingester.Config,
248+
logSuccess bool,
250249
) *ingester.Ingester {
251250
ingester, err := ingester.New(cfg, chunkStore)
252251
if err != nil {
253252
log.Fatal(err)
254253
}
255254
prometheus.MustRegister(ingester)
256255

257-
http.Handle("/push", instr(prism.AppenderHandler(ingester)))
258-
http.Handle("/query", instr(prism.QueryHandler(ingester)))
259-
http.Handle("/label_values", instr(prism.LabelValuesHandler(ingester)))
256+
http.Handle("/push", instrument(logSuccess, prism.AppenderHandler(ingester)))
257+
http.Handle("/query", instrument(logSuccess, prism.QueryHandler(ingester)))
258+
http.Handle("/label_values", instrument(logSuccess, prism.LabelValuesHandler(ingester)))
260259
return ingester
261260
}
261+
262+
// instrument instruments a handler.
263+
func instrument(logSuccess bool, handler http.Handler) http.Handler {
264+
return middleware.Merge(
265+
middleware.Log{
266+
LogSuccess: logSuccess,
267+
},
268+
middleware.Instrument{
269+
Duration: requestDuration,
270+
},
271+
).Wrap(handler)
272+
}

prism-build/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.6.2
1+
FROM golang:1.6.3
22
RUN apt-get update && apt-get install -y python-requests python-yaml file jq && \
33
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
44
RUN go clean -i net && \

vendor/github.com/weaveworks/scope/common/middleware/logging.go

Lines changed: 23 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@
931931
"importpath": "github.com/weaveworks/scope/common/middleware",
932932
"repository": "https://github.com/weaveworks/scope",
933933
"vcs": "git",
934-
"revision": "39be42114193a6daa69b2c5dc066fa23556892b1",
934+
"revision": "382978496727da8b2d2d03888b83404a908bc65a",
935935
"branch": "master",
936936
"path": "/common/middleware",
937937
"notests": true

0 commit comments

Comments
 (0)