forked from mirror/client_golang
Merge pull request #167 from prometheus/nomodel
Remove client_golang/model als direct dependency
This commit is contained in:
commit
8c899cd820
|
@ -12,14 +12,17 @@ import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
metricNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`)
|
metricNameRE = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_:]*$`)
|
||||||
|
labelNameRE = regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// reservedLabelPrefix is a prefix which is not legal in user-supplied
|
||||||
|
// label names.
|
||||||
|
const reservedLabelPrefix = "__"
|
||||||
|
|
||||||
// Labels represents a collection of label name -> value mappings. This type is
|
// Labels represents a collection of label name -> value mappings. This type is
|
||||||
// commonly used with the With(Labels) and GetMetricWith(Labels) methods of
|
// commonly used with the With(Labels) and GetMetricWith(Labels) methods of
|
||||||
// metric vector Collectors, e.g.:
|
// metric vector Collectors, e.g.:
|
||||||
|
@ -133,7 +136,7 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *
|
||||||
for _, val := range labelValues {
|
for _, val := range labelValues {
|
||||||
b.Reset()
|
b.Reset()
|
||||||
b.WriteString(val)
|
b.WriteString(val)
|
||||||
b.WriteByte(model.SeparatorByte)
|
b.WriteByte(separatorByte)
|
||||||
h.Write(b.Bytes())
|
h.Write(b.Bytes())
|
||||||
}
|
}
|
||||||
d.id = h.Sum64()
|
d.id = h.Sum64()
|
||||||
|
@ -144,12 +147,12 @@ func NewDesc(fqName, help string, variableLabels []string, constLabels Labels) *
|
||||||
h.Reset()
|
h.Reset()
|
||||||
b.Reset()
|
b.Reset()
|
||||||
b.WriteString(help)
|
b.WriteString(help)
|
||||||
b.WriteByte(model.SeparatorByte)
|
b.WriteByte(separatorByte)
|
||||||
h.Write(b.Bytes())
|
h.Write(b.Bytes())
|
||||||
for _, labelName := range labelNames {
|
for _, labelName := range labelNames {
|
||||||
b.Reset()
|
b.Reset()
|
||||||
b.WriteString(labelName)
|
b.WriteString(labelName)
|
||||||
b.WriteByte(model.SeparatorByte)
|
b.WriteByte(separatorByte)
|
||||||
h.Write(b.Bytes())
|
h.Write(b.Bytes())
|
||||||
}
|
}
|
||||||
d.dimHash = h.Sum64()
|
d.dimHash = h.Sum64()
|
||||||
|
@ -193,6 +196,6 @@ func (d *Desc) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkLabelName(l string) bool {
|
func checkLabelName(l string) bool {
|
||||||
return model.LabelNameRE.MatchString(l) &&
|
return labelNameRE.MatchString(l) &&
|
||||||
!strings.HasPrefix(l, model.ReservedLabelPrefix)
|
!strings.HasPrefix(l, reservedLabelPrefix)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import (
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/model"
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -49,6 +48,10 @@ type Histogram interface {
|
||||||
Observe(float64)
|
Observe(float64)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// bucketLabel is used for the label that defines the upper bound of a
|
||||||
|
// bucket of a histogram ("le" -> "less or equal").
|
||||||
|
const bucketLabel = "le"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefBuckets are the default Histogram buckets. The default buckets are
|
// DefBuckets are the default Histogram buckets. The default buckets are
|
||||||
// tailored to broadly measure the response time (in seconds) of a
|
// tailored to broadly measure the response time (in seconds) of a
|
||||||
|
@ -57,7 +60,7 @@ var (
|
||||||
DefBuckets = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
|
DefBuckets = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
|
||||||
|
|
||||||
errBucketLabelNotAllowed = fmt.Errorf(
|
errBucketLabelNotAllowed = fmt.Errorf(
|
||||||
"%q is not allowed as label name in histograms", model.BucketLabel,
|
"%q is not allowed as label name in histograms", bucketLabel,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -171,12 +174,12 @@ func newHistogram(desc *Desc, opts HistogramOpts, labelValues ...string) Histogr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, n := range desc.variableLabels {
|
for _, n := range desc.variableLabels {
|
||||||
if n == model.BucketLabel {
|
if n == bucketLabel {
|
||||||
panic(errBucketLabelNotAllowed)
|
panic(errBucketLabelNotAllowed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, lp := range desc.constLabelPairs {
|
for _, lp := range desc.constLabelPairs {
|
||||||
if lp.GetName() == model.BucketLabel {
|
if lp.GetName() == bucketLabel {
|
||||||
panic(errBucketLabelNotAllowed)
|
panic(errBucketLabelNotAllowed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ import (
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const separatorByte byte = 255
|
||||||
|
|
||||||
// A Metric models a single sample value with its meta data being exported to
|
// A Metric models a single sample value with its meta data being exported to
|
||||||
// Prometheus. Implementers of Metric in this package inclued Gauge, Counter,
|
// Prometheus. Implementers of Metric in this package inclued Gauge, Counter,
|
||||||
// Untyped, and Summary. Users can implement their own Metric types, but that
|
// Untyped, and Summary. Users can implement their own Metric types, but that
|
||||||
|
|
|
@ -38,7 +38,6 @@ import (
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/model"
|
|
||||||
"github.com/prometheus/client_golang/text"
|
"github.com/prometheus/client_golang/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -537,7 +536,7 @@ func (r *registry) checkConsistency(metricFamily *dto.MetricFamily, dtoMetric *d
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
buf.WriteString(metricFamily.GetName())
|
buf.WriteString(metricFamily.GetName())
|
||||||
buf.WriteByte(model.SeparatorByte)
|
buf.WriteByte(separatorByte)
|
||||||
h.Write(buf.Bytes())
|
h.Write(buf.Bytes())
|
||||||
// Make sure label pairs are sorted. We depend on it for the consistency
|
// Make sure label pairs are sorted. We depend on it for the consistency
|
||||||
// check. Label pairs must be sorted by contract. But the point of this
|
// check. Label pairs must be sorted by contract. But the point of this
|
||||||
|
@ -547,7 +546,7 @@ func (r *registry) checkConsistency(metricFamily *dto.MetricFamily, dtoMetric *d
|
||||||
for _, lp := range dtoMetric.Label {
|
for _, lp := range dtoMetric.Label {
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
buf.WriteString(lp.GetValue())
|
buf.WriteString(lp.GetValue())
|
||||||
buf.WriteByte(model.SeparatorByte)
|
buf.WriteByte(separatorByte)
|
||||||
h.Write(buf.Bytes())
|
h.Write(buf.Bytes())
|
||||||
}
|
}
|
||||||
metricHash := h.Sum64()
|
metricHash := h.Sum64()
|
||||||
|
|
|
@ -25,10 +25,12 @@ import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
dto "github.com/prometheus/client_model/go"
|
dto "github.com/prometheus/client_model/go"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// quantileLabel is used for the label that defines the quantile in a
|
||||||
|
// summary.
|
||||||
|
const quantileLabel = "quantile"
|
||||||
|
|
||||||
// A Summary captures individual observations from an event or sample stream and
|
// A Summary captures individual observations from an event or sample stream and
|
||||||
// summarizes them in a manner similar to traditional summary statistics: 1. sum
|
// summarizes them in a manner similar to traditional summary statistics: 1. sum
|
||||||
// of observations, 2. observation count, 3. rank estimations.
|
// of observations, 2. observation count, 3. rank estimations.
|
||||||
|
@ -57,7 +59,7 @@ var (
|
||||||
DefObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
|
DefObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001}
|
||||||
|
|
||||||
errQuantileLabelNotAllowed = fmt.Errorf(
|
errQuantileLabelNotAllowed = fmt.Errorf(
|
||||||
"%q is not allowed as label name in summaries", model.QuantileLabel,
|
"%q is not allowed as label name in summaries", quantileLabel,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -172,12 +174,12 @@ func newSummary(desc *Desc, opts SummaryOpts, labelValues ...string) Summary {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, n := range desc.variableLabels {
|
for _, n := range desc.variableLabels {
|
||||||
if n == model.QuantileLabel {
|
if n == quantileLabel {
|
||||||
panic(errQuantileLabelNotAllowed)
|
panic(errQuantileLabelNotAllowed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, lp := range desc.constLabelPairs {
|
for _, lp := range desc.constLabelPairs {
|
||||||
if lp.GetName() == model.QuantileLabel {
|
if lp.GetName() == quantileLabel {
|
||||||
panic(errQuantileLabelNotAllowed)
|
panic(errQuantileLabelNotAllowed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue