Skip to content

Comments

fix: don't fail immediately in resolveCollectorRefs nested loop#208

Merged
burningalchemist merged 1 commit intoburningalchemist:masterfrom
unix-way:fix_resolveCollectorRefs
Mar 23, 2023
Merged

fix: don't fail immediately in resolveCollectorRefs nested loop#208
burningalchemist merged 1 commit intoburningalchemist:masterfrom
unix-way:fix_resolveCollectorRefs

Conversation

@unix-way
Copy link
Contributor

@unix-way unix-way commented Mar 23, 2023

This PR fixes a bug when resolveCollectorRefs() fails immediately in nested loop

for _, cref := range collectorRefs {
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
}
}

Which actually happens every time there is a name mismatch in the slice and the map. For example, we have 3 collector files:

vertica_eon.collector.yml
vertica_ops.collector.yml
vertica_platform.collector.yml

And the following sql_exporter.yml with collectors specified without globbing

target:
  collectors:
    - vertica_ops
    - vertica_platform

collector_files:
  - '*.collector.yml'

In the inner loop, the function will compare vertica_ops against all collector names in the map and return an error when it hits either vertica_eon or vertica_platform, which is an unexpected behavior. The function should continue instead and return an error only if there are no matching collectors.

@burningalchemist
Copy link
Owner

Hi @unix-way, yeah, good catch. Thanks a lot for your contribution! 👍

@burningalchemist burningalchemist merged commit 23ad04f into burningalchemist:master Mar 23, 2023
@hhromic
Copy link
Contributor

hhromic commented Mar 30, 2023

Hi @unix-way !
I introduced this bug in my PR that added globbing support 🙈. Apologies for breaking your setup 😢.
Should have tested it better. Thanks for finding the issue and fixing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants