Updating server dependancies (#5249)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
ca3211bc04
Коммит
701d1ab638
47
vendor/github.com/prometheus/common/expfmt/decode.go
сгенерированный
поставляемый
47
vendor/github.com/prometheus/common/expfmt/decode.go
сгенерированный
поставляемый
@@ -31,6 +31,7 @@ type Decoder interface {
|
||||
Decode(*dto.MetricFamily) error
|
||||
}
|
||||
|
||||
// DecodeOptions contains options used by the Decoder and in sample extraction.
|
||||
type DecodeOptions struct {
|
||||
// Timestamp is added to each value from the stream that has no explicit timestamp set.
|
||||
Timestamp model.Time
|
||||
@@ -142,6 +143,8 @@ func (d *textDecoder) Decode(v *dto.MetricFamily) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SampleDecoder wraps a Decoder to extract samples from the metric families
|
||||
// decoded by the wrapped Decoder.
|
||||
type SampleDecoder struct {
|
||||
Dec Decoder
|
||||
Opts *DecodeOptions
|
||||
@@ -149,37 +152,51 @@ type SampleDecoder struct {
|
||||
f dto.MetricFamily
|
||||
}
|
||||
|
||||
// Decode calls the Decode method of the wrapped Decoder and then extracts the
|
||||
// samples from the decoded MetricFamily into the provided model.Vector.
|
||||
func (sd *SampleDecoder) Decode(s *model.Vector) error {
|
||||
if err := sd.Dec.Decode(&sd.f); err != nil {
|
||||
err := sd.Dec.Decode(&sd.f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*s = extractSamples(&sd.f, sd.Opts)
|
||||
return nil
|
||||
*s, err = extractSamples(&sd.f, sd.Opts)
|
||||
return err
|
||||
}
|
||||
|
||||
// Extract samples builds a slice of samples from the provided metric families.
|
||||
func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) model.Vector {
|
||||
var all model.Vector
|
||||
// ExtractSamples builds a slice of samples from the provided metric
|
||||
// families. If an error occurs during sample extraction, it continues to
|
||||
// extract from the remaining metric families. The returned error is the last
|
||||
// error that has occured.
|
||||
func ExtractSamples(o *DecodeOptions, fams ...*dto.MetricFamily) (model.Vector, error) {
|
||||
var (
|
||||
all model.Vector
|
||||
lastErr error
|
||||
)
|
||||
for _, f := range fams {
|
||||
all = append(all, extractSamples(f, o)...)
|
||||
some, err := extractSamples(f, o)
|
||||
if err != nil {
|
||||
lastErr = err
|
||||
continue
|
||||
}
|
||||
all = append(all, some...)
|
||||
}
|
||||
return all
|
||||
return all, lastErr
|
||||
}
|
||||
|
||||
func extractSamples(f *dto.MetricFamily, o *DecodeOptions) model.Vector {
|
||||
func extractSamples(f *dto.MetricFamily, o *DecodeOptions) (model.Vector, error) {
|
||||
switch f.GetType() {
|
||||
case dto.MetricType_COUNTER:
|
||||
return extractCounter(o, f)
|
||||
return extractCounter(o, f), nil
|
||||
case dto.MetricType_GAUGE:
|
||||
return extractGauge(o, f)
|
||||
return extractGauge(o, f), nil
|
||||
case dto.MetricType_SUMMARY:
|
||||
return extractSummary(o, f)
|
||||
return extractSummary(o, f), nil
|
||||
case dto.MetricType_UNTYPED:
|
||||
return extractUntyped(o, f)
|
||||
return extractUntyped(o, f), nil
|
||||
case dto.MetricType_HISTOGRAM:
|
||||
return extractHistogram(o, f)
|
||||
return extractHistogram(o, f), nil
|
||||
}
|
||||
panic("expfmt.extractSamples: unknown metric family type")
|
||||
return nil, fmt.Errorf("expfmt.extractSamples: unknown metric family type %v", f.GetType())
|
||||
}
|
||||
|
||||
func extractCounter(o *DecodeOptions, f *dto.MetricFamily) model.Vector {
|
||||
|
||||
68
vendor/github.com/prometheus/common/expfmt/decode_test.go
сгенерированный
поставляемый
68
vendor/github.com/prometheus/common/expfmt/decode_test.go
сгенерированный
поставляемый
@@ -21,6 +21,9 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/proto"
|
||||
dto "github.com/prometheus/client_model/go"
|
||||
|
||||
"github.com/prometheus/common/model"
|
||||
)
|
||||
|
||||
@@ -365,3 +368,68 @@ func BenchmarkDiscriminatorHTTPHeader(b *testing.B) {
|
||||
testDiscriminatorHTTPHeader(b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractSamples(t *testing.T) {
|
||||
var (
|
||||
goodMetricFamily1 = &dto.MetricFamily{
|
||||
Name: proto.String("foo"),
|
||||
Help: proto.String("Help for foo."),
|
||||
Type: dto.MetricType_COUNTER.Enum(),
|
||||
Metric: []*dto.Metric{
|
||||
&dto.Metric{
|
||||
Counter: &dto.Counter{
|
||||
Value: proto.Float64(4711),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
goodMetricFamily2 = &dto.MetricFamily{
|
||||
Name: proto.String("bar"),
|
||||
Help: proto.String("Help for bar."),
|
||||
Type: dto.MetricType_GAUGE.Enum(),
|
||||
Metric: []*dto.Metric{
|
||||
&dto.Metric{
|
||||
Gauge: &dto.Gauge{
|
||||
Value: proto.Float64(3.14),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
badMetricFamily = &dto.MetricFamily{
|
||||
Name: proto.String("bad"),
|
||||
Help: proto.String("Help for bad."),
|
||||
Type: dto.MetricType(42).Enum(),
|
||||
Metric: []*dto.Metric{
|
||||
&dto.Metric{
|
||||
Gauge: &dto.Gauge{
|
||||
Value: proto.Float64(2.7),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
opts = &DecodeOptions{
|
||||
Timestamp: 42,
|
||||
}
|
||||
)
|
||||
|
||||
got, err := ExtractSamples(opts, goodMetricFamily1, goodMetricFamily2)
|
||||
if err != nil {
|
||||
t.Error("Unexpected error from ExtractSamples:", err)
|
||||
}
|
||||
want := model.Vector{
|
||||
&model.Sample{Metric: model.Metric{model.MetricNameLabel: "foo"}, Value: 4711, Timestamp: 42},
|
||||
&model.Sample{Metric: model.Metric{model.MetricNameLabel: "bar"}, Value: 3.14, Timestamp: 42},
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("unexpected samples extracted, got: %v, want: %v", got, want)
|
||||
}
|
||||
|
||||
got, err = ExtractSamples(opts, goodMetricFamily1, badMetricFamily, goodMetricFamily2)
|
||||
if err == nil {
|
||||
t.Error("Expected error from ExtractSamples")
|
||||
}
|
||||
if !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("unexpected samples extracted, got: %v, want: %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
7
vendor/github.com/prometheus/common/expfmt/expfmt.go
сгенерированный
поставляемый
7
vendor/github.com/prometheus/common/expfmt/expfmt.go
сгенерированный
поставляемый
@@ -11,14 +11,15 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// A package for reading and writing Prometheus metrics.
|
||||
// Package expfmt contains tools for reading and writing Prometheus metrics.
|
||||
package expfmt
|
||||
|
||||
// Format specifies the HTTP content type of the different wire protocols.
|
||||
type Format string
|
||||
|
||||
// Constants to assemble the Content-Type values for the different wire protocols.
|
||||
const (
|
||||
TextVersion = "0.0.4"
|
||||
|
||||
TextVersion = "0.0.4"
|
||||
ProtoType = `application/vnd.google.protobuf`
|
||||
ProtoProtocol = `io.prometheus.client.MetricFamily`
|
||||
ProtoFmt = ProtoType + "; proto=" + ProtoProtocol + ";"
|
||||
|
||||
11
vendor/github.com/prometheus/common/log/syslog_formatter.go
сгенерированный
поставляемый
11
vendor/github.com/prometheus/common/log/syslog_formatter.go
сгенерированный
поставляемый
@@ -23,6 +23,8 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ logrus.Formatter = (*syslogger)(nil)
|
||||
|
||||
func init() {
|
||||
setSyslogFormatter = func(appname, local string) error {
|
||||
if appname == "" {
|
||||
@@ -43,7 +45,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
var ceeTag = []byte("@cee:")
|
||||
var prefixTag []byte
|
||||
|
||||
type syslogger struct {
|
||||
wrap logrus.Formatter
|
||||
@@ -56,6 +58,11 @@ func newSyslogger(appname string, facility string, fmter logrus.Formatter) (*sys
|
||||
return nil, err
|
||||
}
|
||||
out, err := syslog.New(priority, appname)
|
||||
_, isJSON := fmter.(*logrus.JSONFormatter)
|
||||
if isJSON {
|
||||
// add cee tag to json formatted syslogs
|
||||
prefixTag = []byte("@cee:")
|
||||
}
|
||||
return &syslogger{
|
||||
out: out,
|
||||
wrap: fmter,
|
||||
@@ -92,7 +99,7 @@ func (s *syslogger) Format(e *logrus.Entry) ([]byte, error) {
|
||||
}
|
||||
// only append tag to data sent to syslog (line), not to what
|
||||
// is returned
|
||||
line := string(append(ceeTag, data...))
|
||||
line := string(append(prefixTag, data...))
|
||||
|
||||
switch e.Level {
|
||||
case logrus.PanicLevel:
|
||||
|
||||
52
vendor/github.com/prometheus/common/log/syslog_formatter_test.go
сгенерированный
поставляемый
Обычный файл
52
vendor/github.com/prometheus/common/log/syslog_formatter_test.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,52 @@
|
||||
// Copyright 2015 The Prometheus Authors
|
||||
// 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.
|
||||
|
||||
// +build !windows,!nacl,!plan9
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log/syslog"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetFacility(t *testing.T) {
|
||||
testCases := []struct {
|
||||
facility string
|
||||
expectedPriority syslog.Priority
|
||||
expectedErr error
|
||||
}{
|
||||
{"0", syslog.LOG_LOCAL0, nil},
|
||||
{"1", syslog.LOG_LOCAL1, nil},
|
||||
{"2", syslog.LOG_LOCAL2, nil},
|
||||
{"3", syslog.LOG_LOCAL3, nil},
|
||||
{"4", syslog.LOG_LOCAL4, nil},
|
||||
{"5", syslog.LOG_LOCAL5, nil},
|
||||
{"6", syslog.LOG_LOCAL6, nil},
|
||||
{"7", syslog.LOG_LOCAL7, nil},
|
||||
{"8", syslog.LOG_LOCAL0, errors.New("invalid local(8) for syslog")},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
priority, err := getFacility(tc.facility)
|
||||
if err != tc.expectedErr {
|
||||
if err.Error() != tc.expectedErr.Error() {
|
||||
t.Errorf("want %s, got %s", tc.expectedErr.Error(), err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if priority != tc.expectedPriority {
|
||||
t.Errorf("want %q, got %q", tc.expectedPriority, priority)
|
||||
}
|
||||
}
|
||||
}
|
||||
2
vendor/github.com/prometheus/common/model/metric.go
сгенерированный
поставляемый
2
vendor/github.com/prometheus/common/model/metric.go
сгенерированный
поставляемый
@@ -44,7 +44,7 @@ func (m Metric) Before(o Metric) bool {
|
||||
|
||||
// Clone returns a copy of the Metric.
|
||||
func (m Metric) Clone() Metric {
|
||||
clone := Metric{}
|
||||
clone := make(Metric, len(m))
|
||||
for k, v := range m {
|
||||
clone[k] = v
|
||||
}
|
||||
|
||||
7
vendor/github.com/prometheus/common/route/route.go
сгенерированный
поставляемый
7
vendor/github.com/prometheus/common/route/route.go
сгенерированный
поставляемый
@@ -33,18 +33,19 @@ func WithParam(ctx context.Context, p, v string) context.Context {
|
||||
return context.WithValue(ctx, param(p), v)
|
||||
}
|
||||
|
||||
type contextFn func(r *http.Request) (context.Context, error)
|
||||
// ContextFunc returns a new context for a request.
|
||||
type ContextFunc func(r *http.Request) (context.Context, error)
|
||||
|
||||
// Router wraps httprouter.Router and adds support for prefixed sub-routers
|
||||
// and per-request context injections.
|
||||
type Router struct {
|
||||
rtr *httprouter.Router
|
||||
prefix string
|
||||
ctxFn contextFn
|
||||
ctxFn ContextFunc
|
||||
}
|
||||
|
||||
// New returns a new Router.
|
||||
func New(ctxFn contextFn) *Router {
|
||||
func New(ctxFn ContextFunc) *Router {
|
||||
if ctxFn == nil {
|
||||
ctxFn = func(r *http.Request) (context.Context, error) {
|
||||
return context.Background(), nil
|
||||
|
||||
2
vendor/github.com/prometheus/common/route/route_test.go
сгенерированный
поставляемый
2
vendor/github.com/prometheus/common/route/route_test.go
сгенерированный
поставляемый
@@ -29,7 +29,7 @@ func TestRedirect(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextFn(t *testing.T) {
|
||||
func TestContextFunc(t *testing.T) {
|
||||
router := New(func(r *http.Request) (context.Context, error) {
|
||||
return context.WithValue(context.Background(), "testkey", "testvalue"), nil
|
||||
})
|
||||
|
||||
Ссылка в новой задаче
Block a user