From ccf82b18546530e566958db0bb4b60f3e712aab5 Mon Sep 17 00:00:00 2001 From: chuanshuo Date: Thu, 9 May 2024 17:34:07 +0800 Subject: [PATCH] improved code more clean (#1511) * improved code more clean Signed-off-by: chuanshuo * improved code more clean Signed-off-by: chuanshuo --------- Signed-off-by: chuanshuo --- prometheus/registry.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/prometheus/registry.go b/prometheus/registry.go index 5e2ced2..c6fd2f5 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -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 {