Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make metrics optional #136

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ users:

# Setup the /metrics prometheus endpoint.
metrics:
# Enable the metrics.
enabled: true

# App name that will be used in the metrics.
name: my-wishlist

Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ type User struct {

// Metrics configuration.
type Metrics struct {
Enabled bool `yaml:"enabled"`
Name string `yaml:"name"`
Address string `yaml:"address"`
}
11 changes: 7 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ func Serve(config *Config) error {
Middlewares: []wish.Middleware{
listingMiddleware(config, relay),
cmdsMiddleware(config.Endpoints),
promwish.Middleware(
FirstNonEmpty(config.Metrics.Address, "localhost:9222"),
FirstNonEmpty(config.Metrics.Name, "wishlist"),
),
},
},
}, config.Endpoints...) {
if endpoint.Name == "list" && config.Metrics.Enabled {
endpoint.Middlewares = append(endpoint.Middlewares, promwish.Middleware(
FirstNonEmpty(config.Metrics.Address, "localhost:9222"),
FirstNonEmpty(config.Metrics.Name, "wishlist"),
))
}

if !endpoint.Valid() || !endpoint.ShouldListen() {
continue
}
Expand Down