Skip to content
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)
Copy link

Copilot AI Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate query names may be appended multiple times if encountered repeatedly, resulting in redundant entries in the error message.

Suggested change
duplicateQueries = append(duplicateQueries, query.Name)
if _, added := addedDuplicates[query.Name]; !added {
duplicateQueries = append(duplicateQueries, query.Name)
addedDuplicates[query.Name] = struct{}{}
}

Copilot uses AI. Check for mistakes.
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