Compare commits

..

No commits in common. "v3" and "v3.8.8" have entirely different histories.
v3 ... v3.8.8

View File

@ -22,97 +22,88 @@ func PrometheusCompat(b bool) meter.Option {
func NewMeter(opts ...meter.Option) meter.Meter { func NewMeter(opts ...meter.Option) meter.Meter {
m := &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)} m := &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)}
if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok { if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok && v {
m.prometheusCompat = v m.prometheusCompat = true
} }
return m return m
} }
func (m *victoriametricsMeter) Name() string { func (r *victoriametricsMeter) Name() string {
return m.opts.Name return r.opts.Name
} }
func (m *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter { func (r *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter {
options := m.opts options := r.opts
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
nm := &victoriametricsMeter{set: m.set, opts: options, prometheusCompat: m.prometheusCompat} return &victoriametricsMeter{set: r.set, opts: options}
if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok {
m.prometheusCompat = v
}
return nm
} }
func (m *victoriametricsMeter) buildName(name string, labels ...string) string { func (r *victoriametricsMeter) buildName(name string, labels ...string) string {
nl := len(m.opts.Labels) + len(labels) nl := len(r.opts.Labels) + len(labels)
if nl == 0 { if nl == 0 {
return name return name
} }
nlabels := make([]string, 0, nl) nlabels := make([]string, 0, nl)
nlabels = append(nlabels, m.opts.Labels...) nlabels = append(nlabels, r.opts.Labels...)
nlabels = append(nlabels, labels...) nlabels = append(nlabels, labels...)
return meter.BuildName(name, nlabels...) return meter.BuildName(name, nlabels...)
} }
func (m *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter { func (r *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter {
return m.set.GetOrCreateCounter(m.buildName(name, labels...)) return r.set.GetOrCreateCounter(r.buildName(name, labels...))
} }
func (m *victoriametricsMeter) FloatCounter(name string, labels ...string) meter.FloatCounter { func (r *victoriametricsMeter) FloatCounter(name string, labels ...string) meter.FloatCounter {
return m.set.GetOrCreateFloatCounter(m.buildName(name, labels...)) return r.set.GetOrCreateFloatCounter(r.buildName(name, labels...))
} }
func (m *victoriametricsMeter) Gauge(name string, f func() float64, labels ...string) meter.Gauge { func (r *victoriametricsMeter) Gauge(name string, f func() float64, labels ...string) meter.Gauge {
return m.set.GetOrCreateGauge(m.buildName(name, labels...), f) return r.set.GetOrCreateGauge(r.buildName(name, labels...), f)
} }
func (m *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram { func (r *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram {
if m.prometheusCompat { if r.prometheusCompat {
return m.set.GetOrCreateCompatibleHistogram(m.buildName(name, labels...)) return r.set.GetOrCreateCompatibleHistogram(r.buildName(name, labels...))
} }
return m.set.GetOrCreateHistogram(m.buildName(name, labels...)) return r.set.GetOrCreateHistogram(r.buildName(name, labels...))
} }
func (m *victoriametricsMeter) Summary(name string, labels ...string) meter.Summary { func (r *victoriametricsMeter) Summary(name string, labels ...string) meter.Summary {
return m.set.GetOrCreateSummary(m.buildName(name, labels...)) return r.set.GetOrCreateSummary(r.buildName(name, labels...))
} }
func (m *victoriametricsMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) meter.Summary { func (r *victoriametricsMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) meter.Summary {
return m.set.GetOrCreateSummaryExt(m.buildName(name, labels...), window, quantiles) return r.set.GetOrCreateSummaryExt(r.buildName(name, labels...), window, quantiles)
} }
func (m *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter { func (r *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter {
nm := &victoriametricsMeter{opts: m.opts} m := &victoriametricsMeter{opts: r.opts}
for _, o := range opts {
o(&nm.opts)
}
nm.set = metrics.NewSet()
if v, ok := nm.opts.Context.Value(prometheusCompatKey{}).(bool); ok {
nm.prometheusCompat = v
}
return nm
}
func (m *victoriametricsMeter) Init(opts ...meter.Option) error {
for _, o := range opts { for _, o := range opts {
o(&m.opts) o(&m.opts)
} }
if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok { m.set = metrics.NewSet()
m.prometheusCompat = v return m
} }
func (r *victoriametricsMeter) Init(opts ...meter.Option) error {
for _, o := range opts {
o(&r.opts)
}
return nil return nil
} }
func (m *victoriametricsMeter) Write(w io.Writer, opts ...meter.Option) error { func (r *victoriametricsMeter) Write(w io.Writer, opts ...meter.Option) error {
options := m.opts options := r.opts
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
m.set.WritePrometheus(w) r.set.WritePrometheus(w)
if options.WriteProcessMetrics { if options.WriteProcessMetrics {
metrics.WriteProcessMetrics(w) metrics.WriteProcessMetrics(w)
} }
@ -123,10 +114,10 @@ func (m *victoriametricsMeter) Write(w io.Writer, opts ...meter.Option) error {
return nil return nil
} }
func (m *victoriametricsMeter) Options() meter.Options { func (r *victoriametricsMeter) Options() meter.Options {
return m.opts return r.opts
} }
func (m *victoriametricsMeter) String() string { func (r *victoriametricsMeter) String() string {
return "victoriametrics" return "victoriametrics"
} }