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

Check if query names are unique across jobs #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"strings"

"cloud.google.com/go/cloudsqlconn"
"cloud.google.com/go/cloudsqlconn/mysql/mysql"
Expand Down Expand Up @@ -36,6 +37,22 @@ func NewExporter(logger log.Logger, configFile string) (*Exporter, error) {
return nil, err
}

// Validate config file before, this will otherwise break Prometheus metrics ("was collected before with the same name and label values")
uniqueQueries := make(map[string]struct{})
var duplicateQueries []string
for _, job := range cfg.Jobs {
for _, query := range job.Queries {
if _, ok := uniqueQueries[query.Name]; ok {
duplicateQueries = append(duplicateQueries, query.Name)
continue
}
uniqueQueries[query.Name] = struct{}{}
}
}
if len(duplicateQueries) > 0 {
return nil, fmt.Errorf("invalid config file, query name is not unique across jobs: %v", strings.Join(duplicateQueries, ", "))
}

var queryDurationHistogramBuckets []float64
if len(cfg.Configuration.HistogramBuckets) == 0 {
queryDurationHistogramBuckets = DefaultQueryDurationHistogramBuckets
Expand Down
Loading