Compare commits

...

5 Commits

Author SHA1 Message Date
Lukas Vogel 1321e11795
Merge e7ef5df93d into 76b74e25d5 2024-11-20 14:58:12 +01:00
Ivan Goncharov 76b74e25d5
fix: add very small delay between observations to make test more realistic (and faster) (#1691) 2024-11-20 14:47:38 +01:00
Kemal Akkoyun 6a9004890f
Add codeowners (#1688)
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2024-11-19 18:14:03 +01:00
Kemal Akkoyun 7d0a0fbb72
fix: replace fmt.Errorf with errors.New (#1689)
```shell
prometheus/process_collector_darwin.go:28:25: fmt.Errorf can be replaced with errors.New (perfsprint)
var notImplementedErr = fmt.Errorf("not implemented")
```

Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
2024-11-19 18:13:52 +01:00
Lukas Vogel e7ef5df93d registry: drop duplicate checks
In processMetrics drop duplicate checks. If the metricFamily exists we
already have a type check with the call to checkMetricConsistency. The
help string is already checked in the checkDescConsistency albeit only
if pedantic mode is enabled. However this is probably what is desired
anyway.
2024-09-05 15:01:23 +02:00
4 changed files with 4 additions and 49 deletions

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
* @ArthurSens @bwplotka @kakkoyun @vesari

View File

@ -382,6 +382,7 @@ func TestHistogramAtomicObserve(t *testing.T) {
return return
default: default:
his.Observe(1) his.Observe(1)
time.Sleep(time.Nanosecond)
} }
} }
} }

View File

@ -25,7 +25,7 @@ import (
// notImplementedErr is returned by stub functions that replace cgo functions, when cgo // notImplementedErr is returned by stub functions that replace cgo functions, when cgo
// isn't available. // isn't available.
var notImplementedErr = fmt.Errorf("not implemented") var notImplementedErr = errors.New("not implemented")
type memoryInfo struct { type memoryInfo struct {
vsize uint64 // Virtual memory size in bytes vsize uint64 // Virtual memory size in bytes

View File

@ -634,54 +634,7 @@ func processMetric(
return fmt.Errorf("error collecting metric %v: %w", desc, err) return fmt.Errorf("error collecting metric %v: %w", desc, err)
} }
metricFamily, ok := metricFamiliesByName[desc.fqName] metricFamily, ok := metricFamiliesByName[desc.fqName]
if ok { // Existing name. if !ok { // New name.
if metricFamily.GetHelp() != desc.help {
return fmt.Errorf(
"collected metric %s %s has help %q but should have %q",
desc.fqName, dtoMetric, desc.help, metricFamily.GetHelp(),
)
}
// TODO(beorn7): Simplify switch once Desc has type.
switch metricFamily.GetType() {
case dto.MetricType_COUNTER:
if dtoMetric.Counter == nil {
return fmt.Errorf(
"collected metric %s %s should be a Counter",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_GAUGE:
if dtoMetric.Gauge == nil {
return fmt.Errorf(
"collected metric %s %s should be a Gauge",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_SUMMARY:
if dtoMetric.Summary == nil {
return fmt.Errorf(
"collected metric %s %s should be a Summary",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_UNTYPED:
if dtoMetric.Untyped == nil {
return fmt.Errorf(
"collected metric %s %s should be Untyped",
desc.fqName, dtoMetric,
)
}
case dto.MetricType_HISTOGRAM:
if dtoMetric.Histogram == nil {
return fmt.Errorf(
"collected metric %s %s should be a Histogram",
desc.fqName, dtoMetric,
)
}
default:
panic("encountered MetricFamily with invalid type")
}
} else { // New name.
metricFamily = &dto.MetricFamily{} metricFamily = &dto.MetricFamily{}
metricFamily.Name = proto.String(desc.fqName) metricFamily.Name = proto.String(desc.fqName)
metricFamily.Help = proto.String(desc.help) metricFamily.Help = proto.String(desc.help)