Files
zeekay fe8b5cb8f7 fix(metrics): restore prometheus/client_golang for custom collectors
luxfi/metric v1.5.8 lacks the custom-collector API (Desc/NewDesc/
MustNewConstMetric/GaugeValue/DescribeByCollect, Collector with
Describe/Collect, and exposes CounterVec/HistogramVec as interfaces).
The prior prometheus->luxfi/metric rename therefore left ~16 files
non-compiling. Revert the rename so the const-metric collectors and
Vec instruments use their native prometheus types again; single
exposition surface preserved. Also refresh stale first-party go.sum
hashes and bump luxfi/zap v0.5.0 -> v0.6.0 (graph-resolved patch line).
2026-06-24 23:53:05 -07:00

98 lines
2.3 KiB
Go

// Copyright 2021 Hanzo AI Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package state
import (
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/hanzoai/docdb/build/version"
)
// metricsCollector exposes provider's state as Prometheus metric.
type metricsCollector struct {
p *Provider
addUUID bool
}
// newMetricsCollector creates a new metricsCollector.
//
// If addUUID is true, then the "uuid" label is added.
func newMetricsCollector(p *Provider, addUUID bool) *metricsCollector {
return &metricsCollector{
p: p,
addUUID: addUUID,
}
}
// Describe implements [prometheus.Collector].
func (mc *metricsCollector) Describe(ch chan<- *prometheus.Desc) {
prometheus.DescribeByCollect(mc, ch)
}
// Collect implements [prometheus.Collector].
// It exposes a single metric with various labels.
func (mc *metricsCollector) Collect(ch chan<- prometheus.Metric) {
info := version.Get()
constLabels := prometheus.Labels{
"version": info.Version,
"commit": info.Commit,
"branch": info.Branch,
"dirty": strconv.FormatBool(info.Dirty),
"package": info.Package,
"dev": strconv.FormatBool(info.DevBuild),
}
labels := []string{
"postgresql",
"documentdb",
"telemetry",
"update_available",
}
if mc.addUUID {
labels = append(labels, "uuid")
}
s := mc.p.Get()
values := []string{
s.PostgreSQLVersion,
s.DocumentDBVersion,
s.TelemetryString(),
strconv.FormatBool(s.UpdateAvailable),
}
if mc.addUUID {
values = append(values, s.UUID)
}
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc(
"docdb_up",
"DocDB instance state.",
labels,
constLabels,
),
prometheus.GaugeValue,
1,
values...,
)
}
// check interfaces
var (
_ prometheus.Collector = (*metricsCollector)(nil)
)