Skip to content

Commit

Permalink
improved code more clean (#1511)
Browse files Browse the repository at this point in the history
* improved code more clean

Signed-off-by: chuanshuo <lilijreey@126.com>

* improved code more clean

Signed-off-by: chuanshuo <lilijreey@126.com>

---------

Signed-off-by: chuanshuo <lilijreey@126.com>
  • Loading branch information
lilijreey committed May 9, 2024
1 parent 853c5de commit ccf82b1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions prometheus/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,17 @@ func (r *Registry) Register(c Collector) error {
if dimHash != desc.dimHash {
return fmt.Errorf("a previously registered descriptor with the same fully-qualified name as %s has different label names or a different help string", desc)
}
} else {
// ...then check the new descriptors already seen.
if dimHash, exists := newDimHashesByName[desc.fqName]; exists {
if dimHash != desc.dimHash {
return fmt.Errorf("descriptors reported by collector have inconsistent label names or help strings for the same fully-qualified name, offender is %s", desc)
}
} else {
newDimHashesByName[desc.fqName] = desc.dimHash
continue
}

// ...then check the new descriptors already seen.
if dimHash, exists := newDimHashesByName[desc.fqName]; exists {
if dimHash != desc.dimHash {
return fmt.Errorf("descriptors reported by collector have inconsistent label names or help strings for the same fully-qualified name, offender is %s", desc)
}
continue
}
newDimHashesByName[desc.fqName] = desc.dimHash
}
// A Collector yielding no Desc at all is considered unchecked.
if len(newDescIDs) == 0 {
Expand Down

0 comments on commit ccf82b1

Please sign in to comment.