Skip to content
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,18 @@ target:
data_source_name: 'sqlserver://prom_user:prom_password@dbserver1.example.com:1433'

# Collectors (referenced by name) to execute on the target.
collectors: [pricing_data_freshness]
# Glob patterns are supported (see <https://pkg.go.dev/path/filepath#Match> for syntax).
collectors: [pricing_data_freshness, pricing_*]

# Collector definition files.
# Glob patterns are supported (see <https://pkg.go.dev/path/filepath#Match> for syntax).
collector_files:
- "*.collector.yml"
```

**NOTE:** The `collectors` and `collector_files` configurations support [Glob pattern matching](https://pkg.go.dev/path/filepath#Match).
To match names with literal pattern terms in them, e.g. `collector_*1*`, these must be escaped: `collector_\*1\*`.

### Collectors

Collectors may be defined inline, in the exporter configuration file, under `collectors`, or they may be defined in
Expand Down
19 changes: 14 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,22 @@ func checkCollectorRefs(collectorRefs []string, ctx string) error {
func resolveCollectorRefs(
collectorRefs []string, collectors map[string]*CollectorConfig, ctx string,
) ([]*CollectorConfig, error) {
resolved := make([]*CollectorConfig, 0, len(collectorRefs))
found := make(map[*CollectorConfig]bool)
for _, cref := range collectorRefs {
c, found := collectors[cref]
if !found {
return nil, fmt.Errorf("unknown collector %q referenced in %s", cref, ctx)
for k, c := range collectors {
matched, err := filepath.Match(cref, k)
if err != nil {
return nil, fmt.Errorf("bad collector %q referenced in %s: %w", cref, ctx, err)
}
if !matched {
return nil, fmt.Errorf("unknown collector %q referenced in %s", cref, ctx)
}
found[c] = true
}
resolved = append(resolved, c)
}
resolved := make([]*CollectorConfig, 0, len(found))
for k := range found {
resolved = append(resolved, k)
}
return resolved, nil
}
Expand Down
4 changes: 3 additions & 1 deletion examples/sql_exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ target:
data_source_name: 'sqlserver://prom_user:prom_password@dbserver1.example.com:1433'

# Collectors (referenced by name) to execute on the target.
collectors: [mssql_standard]
# Glob patterns are supported (see <https://pkg.go.dev/path/filepath#Match> for syntax).
collectors: [mssql_*]

# Collector files specifies a list of globs. One collector definition is read from each matching file.
# Glob patterns are supported (see <https://pkg.go.dev/path/filepath#Match> for syntax).
collector_files:
- "*.collector.yml"