Hello community, here is the log from the commit of package coredns for openSUSE:Factory checked in at 2019-07-23 22:38:44 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/coredns (Old) and /work/SRC/openSUSE:Factory/.coredns.new.4126 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "coredns" Tue Jul 23 22:38:44 2019 rev:3 rq:717844 version:1.3.1 Changes: -------- --- /work/SRC/openSUSE:Factory/coredns/coredns.changes 2019-06-06 18:18:19.660668364 +0200 +++ /work/SRC/openSUSE:Factory/.coredns.new.4126/coredns.changes 2019-07-23 22:38:46.718954031 +0200 @@ -1,0 +2,22 @@ +Mon Jul 22 18:58:18 CEST 2019 - [email protected] + +- Remove systemd support, not needed on openSUSE Kubic +- Build with pie (security policy) + +------------------------------------------------------------------- +Tue Jul 2 23:55:24 UTC 2019 - Daniel Orf <[email protected]> + +- Update to version 1.3.1: + * log now allows multiple names to be specified + * import was added to give it a README.md to make it’s documentation more discoverable + * kubernetes TTL is also applied to negative responses (NXDOMAIN, etc) + +- Changed included from version 1.3.0: + * EDNS0 handling in the server and make it compliant with https://dnsflagday.net/ + * k8s_external a new plugin that allows external zones to point to Kubernetes in-cluster services. + * rewrite fixes a bug where a rule would eat the first character of a name + * log now supported the metadata labels. It also fixes a bug in the formatting of a plugin logging a info/failure/warning + * forward removes the dynamic read timeout and uses a fixed value now. + * kubernetes now checks if a zone transfer is allowed. Also allow a TTL of 0 to avoid caching in the cache plugin. + +------------------------------------------------------------------- @@ -5,0 +28,5 @@ + +------------------------------------------------------------------- +Tue Mar 26 03:45:07 UTC 2019 - Daniel Orf <[email protected]> + +- Update spec file BuildRequires golang(API) >= 1.11 Old: ---- coredns-1.2.6.tar.xz New: ---- coredns-1.3.1.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ coredns.spec ++++++ --- /var/tmp/diff_new_pack.YW5TNi/_old 2019-07-23 22:38:47.654953837 +0200 +++ /var/tmp/diff_new_pack.YW5TNi/_new 2019-07-23 22:38:47.658953837 +0200 @@ -1,7 +1,7 @@ # # spec file for package coredns # -# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -12,12 +12,13 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # + %define project github.com/coredns/coredns Name: coredns -Version: 1.2.6 +Version: 1.3.1 Release: 0 Summary: DNS server written in Go License: Apache-2.0 @@ -37,8 +38,8 @@ Source10: Corefile Source11: coredns.service BuildRequires: fdupes -BuildRequires: golang(API) >= 1.10 -%if 0%{?suse_version} >= 1210 +BuildRequires: golang(API) >= 1.12 +%if !0%{?is_opensuse} BuildRequires: pkgconfig(systemd) %endif @@ -86,7 +87,7 @@ ln -s $HOME/go/src/github.com/golang/protobuf $HOME/go/src/code.google.com/p/goprotobuf cd $HOME/go/src/%{project} -make %{?_smp_mflags} coredns CHECKS= +make %{?_smp_mflags} coredns CHECKS= BUILDOPTS="-v -buildmode=pie" %check # Too many tests fail due to the restricted permissions in the build enviroment. @@ -97,6 +98,9 @@ # Binaries install -D -m 0755 %{name} %{buildroot}%{_sbindir}/%{name} + +# On openSUSE, we don't need systemd support +%if !0%{?is_opensuse} ln -s service %{buildroot}%{_sbindir}/rccoredns # Configuration @@ -113,9 +117,11 @@ install -m 0644 man/coredns-*.7 %{buildroot}/%{_mandir}/man7 # Configs # Completion +%endif %fdupes %{buildroot}/%{_prefix} +%if !0%{?is_opensuse} %pre %service_add_pre %{name}.service @@ -128,10 +134,12 @@ %postun %service_del_postun %{name}.service +%endif %files # Binaries %{_sbindir}/coredns +%if !0%{?is_opensuse} %{_sbindir}/rccoredns # Manpages %{_mandir}/man1/coredns* @@ -142,6 +150,7 @@ %config(noreplace) %{_sysconfdir}/%{name}/Corefile %{_unitdir}/%{name}.service # Completion +%endif # License %license LICENSE ++++++ _service ++++++ --- /var/tmp/diff_new_pack.YW5TNi/_old 2019-07-23 22:38:47.702953827 +0200 +++ /var/tmp/diff_new_pack.YW5TNi/_new 2019-07-23 22:38:47.702953827 +0200 @@ -3,8 +3,8 @@ <param name="url">https://github.com/coredns/coredns</param> <param name="scm">git</param> <param name="filename">coredns</param> -<param name="versionformat">1.2.6</param> -<param name="revision">v1.2.6</param> +<param name="versionformat">1.3.1</param> +<param name="revision">v1.3.1</param> </service> <service name="tar_scm" mode="disabled"> @@ -12,7 +12,7 @@ <param name="scm">git</param> <param name="filename">mholt-caddy</param> <param name="versionformat"></param> -<param name="revision">v0.10.13</param> +<param name="revision">v0.11.1</param> </service> <service name="tar_scm" mode="disabled"> @@ -20,7 +20,7 @@ <param name="scm">git</param> <param name="filename">miekg-dns</param> <param name="versionformat"></param> -<param name="revision">v1.0.15</param> +<param name="revision">v1.1.3</param> </service> <service name="tar_scm" mode="disabled"> @@ -28,7 +28,7 @@ <param name="scm">git</param> <param name="filename">prometheus-client_golang</param> <param name="versionformat"></param> -<param name="revision">v0.8.0</param> +<param name="revision">v0.9.1</param> </service> <service name="tar_scm" mode="disabled"> @@ -44,7 +44,7 @@ <param name="scm">git</param> <param name="filename">golang-protobuf</param> <param name="versionformat"></param> -<param name="revision">1d3f30b</param> +<param name="revision">v1.1.0</param> </service> <service name="tar_scm" mode="disabled"> @@ -60,7 +60,7 @@ <param name="scm">git</param> <param name="filename">prometheus-common</param> <param name="versionformat"></param> -<param name="revision">4724e92</param> +<param name="revision">7600349</param> </service> <service name="tar_scm" mode="disabled"> @@ -68,7 +68,7 @@ <param name="scm">git</param> <param name="filename">prometheus-client_model</param> <param name="versionformat"></param> -<param name="revision">5c3871d</param> +<param name="revision">99fa1f4</param> </service> <service name="tar_scm" mode="disabled"> ++++++ coredns-1.2.6.tar.xz -> coredns-1.3.1.tar.xz ++++++ ++++ 241745 lines of diff (skipped) ++++++ golang-protobuf.tar.xz ++++++ ++++ 16798 lines of diff (skipped) ++++++ mholt-caddy.tar.xz ++++++ ++++ 62943 lines of diff (skipped) ++++++ miekg-dns.tar.xz ++++++ ++++ 13262 lines of diff (skipped) ++++++ prometheus-client_golang.tar.xz ++++++ ++++ 15210 lines of diff (skipped) ++++++ prometheus-client_model.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-client_model/Makefile new/prometheus-client_model/Makefile --- old/prometheus-client_model/Makefile 2018-07-12 12:51:10.000000000 +0200 +++ new/prometheus-client_model/Makefile 2017-11-17 11:05:41.000000000 +0100 @@ -28,7 +28,7 @@ go: go/metrics.pb.go go/metrics.pb.go: metrics.proto - protoc $< --go_out=import_path=github.com/prometheus/client_model/,paths=source_relative:go/ + protoc $< --go_out=go/ java: src/main/java/io/prometheus/client/Metrics.java pom.xml mvn clean compile package diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-client_model/go/metrics.pb.go new/prometheus-client_model/go/metrics.pb.go --- old/prometheus-client_model/go/metrics.pb.go 2018-07-12 12:51:10.000000000 +0200 +++ new/prometheus-client_model/go/metrics.pb.go 2017-11-17 11:05:41.000000000 +0100 @@ -1,23 +1,34 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. +// Code generated by protoc-gen-go. // source: metrics.proto +// DO NOT EDIT! -package io_prometheus_client // import "github.com/prometheus/client_model/go" +/* +Package io_prometheus_client is a generated protocol buffer package. + +It is generated from these files: + metrics.proto + +It has these top-level messages: + LabelPair + Gauge + Counter + Quantile + Summary + Untyped + Histogram + Bucket + Metric + MetricFamily +*/ +package io_prometheus_client import proto "github.com/golang/protobuf/proto" -import fmt "fmt" import math "math" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal -var _ = fmt.Errorf var _ = math.Inf -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - type MetricType int32 const ( @@ -59,41 +70,16 @@ *x = MetricType(value) return nil } -func (MetricType) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{0} -} type LabelPair struct { - Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` - Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *LabelPair) Reset() { *m = LabelPair{} } func (m *LabelPair) String() string { return proto.CompactTextString(m) } func (*LabelPair) ProtoMessage() {} -func (*LabelPair) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{0} -} -func (m *LabelPair) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_LabelPair.Unmarshal(m, b) -} -func (m *LabelPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_LabelPair.Marshal(b, m, deterministic) -} -func (dst *LabelPair) XXX_Merge(src proto.Message) { - xxx_messageInfo_LabelPair.Merge(dst, src) -} -func (m *LabelPair) XXX_Size() int { - return xxx_messageInfo_LabelPair.Size(m) -} -func (m *LabelPair) XXX_DiscardUnknown() { - xxx_messageInfo_LabelPair.DiscardUnknown(m) -} - -var xxx_messageInfo_LabelPair proto.InternalMessageInfo func (m *LabelPair) GetName() string { if m != nil && m.Name != nil { @@ -110,35 +96,13 @@ } type Gauge struct { - Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Gauge) Reset() { *m = Gauge{} } func (m *Gauge) String() string { return proto.CompactTextString(m) } func (*Gauge) ProtoMessage() {} -func (*Gauge) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{1} -} -func (m *Gauge) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Gauge.Unmarshal(m, b) -} -func (m *Gauge) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Gauge.Marshal(b, m, deterministic) -} -func (dst *Gauge) XXX_Merge(src proto.Message) { - xxx_messageInfo_Gauge.Merge(dst, src) -} -func (m *Gauge) XXX_Size() int { - return xxx_messageInfo_Gauge.Size(m) -} -func (m *Gauge) XXX_DiscardUnknown() { - xxx_messageInfo_Gauge.DiscardUnknown(m) -} - -var xxx_messageInfo_Gauge proto.InternalMessageInfo func (m *Gauge) GetValue() float64 { if m != nil && m.Value != nil { @@ -148,35 +112,13 @@ } type Counter struct { - Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Counter) Reset() { *m = Counter{} } func (m *Counter) String() string { return proto.CompactTextString(m) } func (*Counter) ProtoMessage() {} -func (*Counter) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{2} -} -func (m *Counter) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Counter.Unmarshal(m, b) -} -func (m *Counter) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Counter.Marshal(b, m, deterministic) -} -func (dst *Counter) XXX_Merge(src proto.Message) { - xxx_messageInfo_Counter.Merge(dst, src) -} -func (m *Counter) XXX_Size() int { - return xxx_messageInfo_Counter.Size(m) -} -func (m *Counter) XXX_DiscardUnknown() { - xxx_messageInfo_Counter.DiscardUnknown(m) -} - -var xxx_messageInfo_Counter proto.InternalMessageInfo func (m *Counter) GetValue() float64 { if m != nil && m.Value != nil { @@ -186,36 +128,14 @@ } type Quantile struct { - Quantile *float64 `protobuf:"fixed64,1,opt,name=quantile" json:"quantile,omitempty"` - Value *float64 `protobuf:"fixed64,2,opt,name=value" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Quantile *float64 `protobuf:"fixed64,1,opt,name=quantile" json:"quantile,omitempty"` + Value *float64 `protobuf:"fixed64,2,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Quantile) Reset() { *m = Quantile{} } func (m *Quantile) String() string { return proto.CompactTextString(m) } func (*Quantile) ProtoMessage() {} -func (*Quantile) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{3} -} -func (m *Quantile) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Quantile.Unmarshal(m, b) -} -func (m *Quantile) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Quantile.Marshal(b, m, deterministic) -} -func (dst *Quantile) XXX_Merge(src proto.Message) { - xxx_messageInfo_Quantile.Merge(dst, src) -} -func (m *Quantile) XXX_Size() int { - return xxx_messageInfo_Quantile.Size(m) -} -func (m *Quantile) XXX_DiscardUnknown() { - xxx_messageInfo_Quantile.DiscardUnknown(m) -} - -var xxx_messageInfo_Quantile proto.InternalMessageInfo func (m *Quantile) GetQuantile() float64 { if m != nil && m.Quantile != nil { @@ -232,37 +152,15 @@ } type Summary struct { - SampleCount *uint64 `protobuf:"varint,1,opt,name=sample_count,json=sampleCount" json:"sample_count,omitempty"` - SampleSum *float64 `protobuf:"fixed64,2,opt,name=sample_sum,json=sampleSum" json:"sample_sum,omitempty"` - Quantile []*Quantile `protobuf:"bytes,3,rep,name=quantile" json:"quantile,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + SampleCount *uint64 `protobuf:"varint,1,opt,name=sample_count" json:"sample_count,omitempty"` + SampleSum *float64 `protobuf:"fixed64,2,opt,name=sample_sum" json:"sample_sum,omitempty"` + Quantile []*Quantile `protobuf:"bytes,3,rep,name=quantile" json:"quantile,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Summary) Reset() { *m = Summary{} } func (m *Summary) String() string { return proto.CompactTextString(m) } func (*Summary) ProtoMessage() {} -func (*Summary) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{4} -} -func (m *Summary) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Summary.Unmarshal(m, b) -} -func (m *Summary) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Summary.Marshal(b, m, deterministic) -} -func (dst *Summary) XXX_Merge(src proto.Message) { - xxx_messageInfo_Summary.Merge(dst, src) -} -func (m *Summary) XXX_Size() int { - return xxx_messageInfo_Summary.Size(m) -} -func (m *Summary) XXX_DiscardUnknown() { - xxx_messageInfo_Summary.DiscardUnknown(m) -} - -var xxx_messageInfo_Summary proto.InternalMessageInfo func (m *Summary) GetSampleCount() uint64 { if m != nil && m.SampleCount != nil { @@ -286,35 +184,13 @@ } type Untyped struct { - Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Value *float64 `protobuf:"fixed64,1,opt,name=value" json:"value,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Untyped) Reset() { *m = Untyped{} } func (m *Untyped) String() string { return proto.CompactTextString(m) } func (*Untyped) ProtoMessage() {} -func (*Untyped) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{5} -} -func (m *Untyped) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Untyped.Unmarshal(m, b) -} -func (m *Untyped) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Untyped.Marshal(b, m, deterministic) -} -func (dst *Untyped) XXX_Merge(src proto.Message) { - xxx_messageInfo_Untyped.Merge(dst, src) -} -func (m *Untyped) XXX_Size() int { - return xxx_messageInfo_Untyped.Size(m) -} -func (m *Untyped) XXX_DiscardUnknown() { - xxx_messageInfo_Untyped.DiscardUnknown(m) -} - -var xxx_messageInfo_Untyped proto.InternalMessageInfo func (m *Untyped) GetValue() float64 { if m != nil && m.Value != nil { @@ -324,37 +200,15 @@ } type Histogram struct { - SampleCount *uint64 `protobuf:"varint,1,opt,name=sample_count,json=sampleCount" json:"sample_count,omitempty"` - SampleSum *float64 `protobuf:"fixed64,2,opt,name=sample_sum,json=sampleSum" json:"sample_sum,omitempty"` - Bucket []*Bucket `protobuf:"bytes,3,rep,name=bucket" json:"bucket,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + SampleCount *uint64 `protobuf:"varint,1,opt,name=sample_count" json:"sample_count,omitempty"` + SampleSum *float64 `protobuf:"fixed64,2,opt,name=sample_sum" json:"sample_sum,omitempty"` + Bucket []*Bucket `protobuf:"bytes,3,rep,name=bucket" json:"bucket,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Histogram) Reset() { *m = Histogram{} } func (m *Histogram) String() string { return proto.CompactTextString(m) } func (*Histogram) ProtoMessage() {} -func (*Histogram) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{6} -} -func (m *Histogram) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Histogram.Unmarshal(m, b) -} -func (m *Histogram) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Histogram.Marshal(b, m, deterministic) -} -func (dst *Histogram) XXX_Merge(src proto.Message) { - xxx_messageInfo_Histogram.Merge(dst, src) -} -func (m *Histogram) XXX_Size() int { - return xxx_messageInfo_Histogram.Size(m) -} -func (m *Histogram) XXX_DiscardUnknown() { - xxx_messageInfo_Histogram.DiscardUnknown(m) -} - -var xxx_messageInfo_Histogram proto.InternalMessageInfo func (m *Histogram) GetSampleCount() uint64 { if m != nil && m.SampleCount != nil { @@ -378,36 +232,14 @@ } type Bucket struct { - CumulativeCount *uint64 `protobuf:"varint,1,opt,name=cumulative_count,json=cumulativeCount" json:"cumulative_count,omitempty"` - UpperBound *float64 `protobuf:"fixed64,2,opt,name=upper_bound,json=upperBound" json:"upper_bound,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + CumulativeCount *uint64 `protobuf:"varint,1,opt,name=cumulative_count" json:"cumulative_count,omitempty"` + UpperBound *float64 `protobuf:"fixed64,2,opt,name=upper_bound" json:"upper_bound,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Bucket) Reset() { *m = Bucket{} } func (m *Bucket) String() string { return proto.CompactTextString(m) } func (*Bucket) ProtoMessage() {} -func (*Bucket) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{7} -} -func (m *Bucket) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Bucket.Unmarshal(m, b) -} -func (m *Bucket) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Bucket.Marshal(b, m, deterministic) -} -func (dst *Bucket) XXX_Merge(src proto.Message) { - xxx_messageInfo_Bucket.Merge(dst, src) -} -func (m *Bucket) XXX_Size() int { - return xxx_messageInfo_Bucket.Size(m) -} -func (m *Bucket) XXX_DiscardUnknown() { - xxx_messageInfo_Bucket.DiscardUnknown(m) -} - -var xxx_messageInfo_Bucket proto.InternalMessageInfo func (m *Bucket) GetCumulativeCount() uint64 { if m != nil && m.CumulativeCount != nil { @@ -424,41 +256,19 @@ } type Metric struct { - Label []*LabelPair `protobuf:"bytes,1,rep,name=label" json:"label,omitempty"` - Gauge *Gauge `protobuf:"bytes,2,opt,name=gauge" json:"gauge,omitempty"` - Counter *Counter `protobuf:"bytes,3,opt,name=counter" json:"counter,omitempty"` - Summary *Summary `protobuf:"bytes,4,opt,name=summary" json:"summary,omitempty"` - Untyped *Untyped `protobuf:"bytes,5,opt,name=untyped" json:"untyped,omitempty"` - Histogram *Histogram `protobuf:"bytes,7,opt,name=histogram" json:"histogram,omitempty"` - TimestampMs *int64 `protobuf:"varint,6,opt,name=timestamp_ms,json=timestampMs" json:"timestamp_ms,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Label []*LabelPair `protobuf:"bytes,1,rep,name=label" json:"label,omitempty"` + Gauge *Gauge `protobuf:"bytes,2,opt,name=gauge" json:"gauge,omitempty"` + Counter *Counter `protobuf:"bytes,3,opt,name=counter" json:"counter,omitempty"` + Summary *Summary `protobuf:"bytes,4,opt,name=summary" json:"summary,omitempty"` + Untyped *Untyped `protobuf:"bytes,5,opt,name=untyped" json:"untyped,omitempty"` + Histogram *Histogram `protobuf:"bytes,7,opt,name=histogram" json:"histogram,omitempty"` + TimestampMs *int64 `protobuf:"varint,6,opt,name=timestamp_ms" json:"timestamp_ms,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *Metric) Reset() { *m = Metric{} } func (m *Metric) String() string { return proto.CompactTextString(m) } func (*Metric) ProtoMessage() {} -func (*Metric) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{8} -} -func (m *Metric) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Metric.Unmarshal(m, b) -} -func (m *Metric) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Metric.Marshal(b, m, deterministic) -} -func (dst *Metric) XXX_Merge(src proto.Message) { - xxx_messageInfo_Metric.Merge(dst, src) -} -func (m *Metric) XXX_Size() int { - return xxx_messageInfo_Metric.Size(m) -} -func (m *Metric) XXX_DiscardUnknown() { - xxx_messageInfo_Metric.DiscardUnknown(m) -} - -var xxx_messageInfo_Metric proto.InternalMessageInfo func (m *Metric) GetLabel() []*LabelPair { if m != nil { @@ -510,38 +320,16 @@ } type MetricFamily struct { - Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` - Help *string `protobuf:"bytes,2,opt,name=help" json:"help,omitempty"` - Type *MetricType `protobuf:"varint,3,opt,name=type,enum=io.prometheus.client.MetricType" json:"type,omitempty"` - Metric []*Metric `protobuf:"bytes,4,rep,name=metric" json:"metric,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + Help *string `protobuf:"bytes,2,opt,name=help" json:"help,omitempty"` + Type *MetricType `protobuf:"varint,3,opt,name=type,enum=io.prometheus.client.MetricType" json:"type,omitempty"` + Metric []*Metric `protobuf:"bytes,4,rep,name=metric" json:"metric,omitempty"` + XXX_unrecognized []byte `json:"-"` } func (m *MetricFamily) Reset() { *m = MetricFamily{} } func (m *MetricFamily) String() string { return proto.CompactTextString(m) } func (*MetricFamily) ProtoMessage() {} -func (*MetricFamily) Descriptor() ([]byte, []int) { - return fileDescriptor_metrics_c97c9a2b9560cb8f, []int{9} -} -func (m *MetricFamily) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_MetricFamily.Unmarshal(m, b) -} -func (m *MetricFamily) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_MetricFamily.Marshal(b, m, deterministic) -} -func (dst *MetricFamily) XXX_Merge(src proto.Message) { - xxx_messageInfo_MetricFamily.Merge(dst, src) -} -func (m *MetricFamily) XXX_Size() int { - return xxx_messageInfo_MetricFamily.Size(m) -} -func (m *MetricFamily) XXX_DiscardUnknown() { - xxx_messageInfo_MetricFamily.DiscardUnknown(m) -} - -var xxx_messageInfo_MetricFamily proto.InternalMessageInfo func (m *MetricFamily) GetName() string { if m != nil && m.Name != nil { @@ -572,58 +360,5 @@ } func init() { - proto.RegisterType((*LabelPair)(nil), "io.prometheus.client.LabelPair") - proto.RegisterType((*Gauge)(nil), "io.prometheus.client.Gauge") - proto.RegisterType((*Counter)(nil), "io.prometheus.client.Counter") - proto.RegisterType((*Quantile)(nil), "io.prometheus.client.Quantile") - proto.RegisterType((*Summary)(nil), "io.prometheus.client.Summary") - proto.RegisterType((*Untyped)(nil), "io.prometheus.client.Untyped") - proto.RegisterType((*Histogram)(nil), "io.prometheus.client.Histogram") - proto.RegisterType((*Bucket)(nil), "io.prometheus.client.Bucket") - proto.RegisterType((*Metric)(nil), "io.prometheus.client.Metric") - proto.RegisterType((*MetricFamily)(nil), "io.prometheus.client.MetricFamily") proto.RegisterEnum("io.prometheus.client.MetricType", MetricType_name, MetricType_value) } - -func init() { proto.RegisterFile("metrics.proto", fileDescriptor_metrics_c97c9a2b9560cb8f) } - -var fileDescriptor_metrics_c97c9a2b9560cb8f = []byte{ - // 591 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0x4f, 0x4f, 0xdb, 0x4e, - 0x14, 0xfc, 0x99, 0xd8, 0x09, 0x7e, 0x86, 0x5f, 0xad, 0x15, 0x07, 0xab, 0x2d, 0x25, 0xcd, 0x89, - 0xf6, 0x10, 0x54, 0x04, 0xaa, 0x44, 0xdb, 0x03, 0x50, 0x1a, 0x2a, 0xd5, 0x40, 0x37, 0xc9, 0x81, - 0x5e, 0xac, 0x8d, 0x59, 0x25, 0x56, 0xbd, 0xb6, 0x6b, 0xef, 0x22, 0xe5, 0xdc, 0x43, 0xbf, 0x47, - 0xbf, 0x68, 0xab, 0xfd, 0xe3, 0x18, 0x24, 0xc3, 0xa9, 0xb7, 0xb7, 0xf3, 0x66, 0xde, 0x8e, 0x77, - 0xc7, 0x0b, 0x9b, 0x8c, 0xf2, 0x32, 0x89, 0xab, 0x61, 0x51, 0xe6, 0x3c, 0x47, 0x5b, 0x49, 0x2e, - 0x2b, 0x46, 0xf9, 0x82, 0x8a, 0x6a, 0x18, 0xa7, 0x09, 0xcd, 0xf8, 0xe0, 0x10, 0xdc, 0x2f, 0x64, - 0x46, 0xd3, 0x2b, 0x92, 0x94, 0x08, 0x81, 0x9d, 0x11, 0x46, 0x03, 0xab, 0x6f, 0xed, 0xba, 0x58, - 0xd5, 0x68, 0x0b, 0x9c, 0x5b, 0x92, 0x0a, 0x1a, 0xac, 0x29, 0x50, 0x2f, 0x06, 0xdb, 0xe0, 0x8c, - 0x88, 0x98, 0xdf, 0x69, 0x4b, 0x8d, 0x55, 0xb7, 0x77, 0xa0, 0x77, 0x9a, 0x8b, 0x8c, 0xd3, 0xf2, - 0x01, 0xc2, 0x7b, 0x58, 0xff, 0x2a, 0x48, 0xc6, 0x93, 0x94, 0xa2, 0xa7, 0xb0, 0xfe, 0xc3, 0xd4, - 0x86, 0xb4, 0x5a, 0xdf, 0xdf, 0x7d, 0xa5, 0xfe, 0x65, 0x41, 0x6f, 0x2c, 0x18, 0x23, 0xe5, 0x12, - 0xbd, 0x84, 0x8d, 0x8a, 0xb0, 0x22, 0xa5, 0x51, 0x2c, 0x77, 0x54, 0x13, 0x6c, 0xec, 0x69, 0x4c, - 0x99, 0x40, 0xdb, 0x00, 0x86, 0x52, 0x09, 0x66, 0x26, 0xb9, 0x1a, 0x19, 0x0b, 0x86, 0x8e, 0xee, - 0xec, 0xdf, 0xe9, 0x77, 0x76, 0xbd, 0xfd, 0x17, 0xc3, 0xb6, 0xb3, 0x1a, 0xd6, 0x8e, 0x1b, 0x7f, - 0xf2, 0x43, 0xa7, 0x19, 0x5f, 0x16, 0xf4, 0xe6, 0x81, 0x0f, 0xfd, 0x69, 0x81, 0x7b, 0x9e, 0x54, - 0x3c, 0x9f, 0x97, 0x84, 0xfd, 0x03, 0xb3, 0x07, 0xd0, 0x9d, 0x89, 0xf8, 0x3b, 0xe5, 0xc6, 0xea, - 0xf3, 0x76, 0xab, 0x27, 0x8a, 0x83, 0x0d, 0x77, 0x30, 0x81, 0xae, 0x46, 0xd0, 0x2b, 0xf0, 0x63, - 0xc1, 0x44, 0x4a, 0x78, 0x72, 0x7b, 0xdf, 0xc5, 0x93, 0x06, 0xd7, 0x4e, 0x76, 0xc0, 0x13, 0x45, - 0x41, 0xcb, 0x68, 0x96, 0x8b, 0xec, 0xc6, 0x58, 0x01, 0x05, 0x9d, 0x48, 0x64, 0xf0, 0x67, 0x0d, - 0xba, 0xa1, 0xca, 0x18, 0x3a, 0x04, 0x27, 0x95, 0x31, 0x0a, 0x2c, 0xe5, 0x6a, 0xa7, 0xdd, 0xd5, - 0x2a, 0x69, 0x58, 0xb3, 0xd1, 0x1b, 0x70, 0xe6, 0x32, 0x46, 0x6a, 0xb8, 0xb7, 0xff, 0xac, 0x5d, - 0xa6, 0x92, 0x86, 0x35, 0x13, 0xbd, 0x85, 0x5e, 0xac, 0xa3, 0x15, 0x74, 0x94, 0x68, 0xbb, 0x5d, - 0x64, 0xf2, 0x87, 0x6b, 0xb6, 0x14, 0x56, 0x3a, 0x33, 0x81, 0xfd, 0x98, 0xd0, 0x04, 0x0b, 0xd7, - 0x6c, 0x29, 0x14, 0xfa, 0x8e, 0x03, 0xe7, 0x31, 0xa1, 0x09, 0x02, 0xae, 0xd9, 0xe8, 0x03, 0xb8, - 0x8b, 0xfa, 0xea, 0x83, 0x9e, 0x92, 0x3e, 0x70, 0x30, 0xab, 0x84, 0xe0, 0x46, 0x21, 0xc3, 0xc2, - 0x13, 0x46, 0x2b, 0x4e, 0x58, 0x11, 0xb1, 0x2a, 0xe8, 0xf6, 0xad, 0xdd, 0x0e, 0xf6, 0x56, 0x58, - 0x58, 0x0d, 0x7e, 0x5b, 0xb0, 0xa1, 0x6f, 0xe0, 0x13, 0x61, 0x49, 0xba, 0x6c, 0xfd, 0x83, 0x11, - 0xd8, 0x0b, 0x9a, 0x16, 0xe6, 0x07, 0x56, 0x35, 0x3a, 0x00, 0x5b, 0x7a, 0x54, 0x47, 0xf8, 0xff, - 0x7e, 0xbf, 0xdd, 0x95, 0x9e, 0x3c, 0x59, 0x16, 0x14, 0x2b, 0xb6, 0x0c, 0x9f, 0x7e, 0x53, 0x02, - 0xfb, 0xb1, 0xf0, 0x69, 0x1d, 0x36, 0xdc, 0xd7, 0x21, 0x40, 0x33, 0x09, 0x79, 0xd0, 0x3b, 0xbd, - 0x9c, 0x5e, 0x4c, 0xce, 0xb0, 0xff, 0x1f, 0x72, 0xc1, 0x19, 0x1d, 0x4f, 0x47, 0x67, 0xbe, 0x25, - 0xf1, 0xf1, 0x34, 0x0c, 0x8f, 0xf1, 0xb5, 0xbf, 0x26, 0x17, 0xd3, 0x8b, 0xc9, 0xf5, 0xd5, 0xd9, - 0x47, 0xbf, 0x83, 0x36, 0xc1, 0x3d, 0xff, 0x3c, 0x9e, 0x5c, 0x8e, 0xf0, 0x71, 0xe8, 0xdb, 0x27, - 0x18, 0x5a, 0x5f, 0xb2, 0x6f, 0x47, 0xf3, 0x84, 0x2f, 0xc4, 0x6c, 0x18, 0xe7, 0x6c, 0xaf, 0xe9, - 0xee, 0xe9, 0x6e, 0xc4, 0xf2, 0x1b, 0x9a, 0xee, 0xcd, 0xf3, 0x77, 0x49, 0x1e, 0x35, 0xdd, 0x48, - 0x77, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x45, 0x21, 0x7f, 0x64, 0x2b, 0x05, 0x00, 0x00, -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-client_model/metrics.proto new/prometheus-client_model/metrics.proto --- old/prometheus-client_model/metrics.proto 2018-07-12 12:51:10.000000000 +0200 +++ new/prometheus-client_model/metrics.proto 2017-11-17 11:05:41.000000000 +0100 @@ -15,7 +15,6 @@ package io.prometheus.client; option java_package = "io.prometheus.client"; -option go_package = "github.com/prometheus/client_model/go;io_prometheus_client"; message LabelPair { optional string name = 1; ++++++ prometheus-common.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/MAINTAINERS.md new/prometheus-common/MAINTAINERS.md --- old/prometheus-common/MAINTAINERS.md 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/MAINTAINERS.md 2018-05-18 17:47:59.000000000 +0200 @@ -1 +1 @@ -* Brian Brazil <[email protected]> +* Fabian Reinartz <[email protected]> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/config/http_config_test.go new/prometheus-common/config/http_config_test.go --- old/prometheus-common/config/http_config_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/config/http_config_test.go 2018-05-18 17:47:59.000000000 +0200 @@ -320,6 +320,10 @@ } func TestBearerAuthFileRoundTripper(t *testing.T) { + const ( + newBearerToken = "goodbyeandthankyouforthefish" + ) + fakeRoundTripper := NewRoundTripCheckRequest(func(req *http.Request) { bearer := req.Header.Get("Authorization") if bearer != ExpectedBearer { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/expfmt/decode_test.go new/prometheus-common/expfmt/decode_test.go --- old/prometheus-common/expfmt/decode_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/expfmt/decode_test.go 2018-05-18 17:47:59.000000000 +0200 @@ -259,65 +259,6 @@ }, }, { - in: "\u007f\n\x1drequest_duration_microseconds\x12\x15The response latency.\x18\x04\"E:C\b\x85\x15\x11\xcd\xcc\xccL\x8f\xcb:A\x1a\v\b{\x11\x00\x00\x00\x00\x00\x00Y@\x1a\f\b\x9c\x03\x11\x00\x00\x00\x00\x00\x00^@\x1a\f\b\xd0\x04\x11\x00\x00\x00\x00\x00\x00b@\x1a\f\b\xf4\v\x11\x9a\x99\x99\x99\x99\x99e@", - expected: model.Vector{ - &model.Sample{ - Metric: model.Metric{ - model.MetricNameLabel: "request_duration_microseconds_count", - }, - Value: 2693, - Timestamp:testTime, - }, - &model.Sample{ - Metric: model.Metric{ - "le": "+Inf", - model.MetricNameLabel: "request_duration_microseconds_bucket", - }, - Value: 2693, - Timestamp:testTime, - }, - &model.Sample{ - Metric: model.Metric{ - model.MetricNameLabel: "request_duration_microseconds_sum", - }, - Value: 1756047.3, - Timestamp:testTime, - }, - &model.Sample{ - Metric: model.Metric{ - "le": "172.8", - model.MetricNameLabel: "request_duration_microseconds_bucket", - }, - Value: 1524, - Timestamp:testTime, - }, - &model.Sample{ - Metric: model.Metric{ - "le": "144", - model.MetricNameLabel: "request_duration_microseconds_bucket", - }, - Value: 592, - Timestamp:testTime, - }, - &model.Sample{ - Metric: model.Metric{ - "le": "120", - model.MetricNameLabel: "request_duration_microseconds_bucket", - }, - Value: 412, - Timestamp:testTime, - }, - &model.Sample{ - Metric: model.Metric{ - "le": "100", - model.MetricNameLabel: "request_duration_microseconds_bucket", - }, - Value: 123, - Timestamp:testTime, - }, - }, - }, - { // The metric type is unset in this protobuf, which needs to be handled // correctly by the decoder. in: "\x1c\n\rrequest_count\"\v\x1a\t\t\x00\x00\x00\x00\x00\x00\xf0?", diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/expfmt/encode_test.go new/prometheus-common/expfmt/encode_test.go --- old/prometheus-common/expfmt/encode_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/expfmt/encode_test.go 1970-01-01 01:00:00.000000000 +0100 @@ -1,122 +0,0 @@ -package expfmt - -import ( - "bytes" - "github.com/golang/protobuf/proto" - dto "github.com/prometheus/client_model/go" - "net/http" - "testing" -) - -func TestNegotiate(t *testing.T) { - acceptValuePrefix := "application/vnd.google.protobuf;proto=io.prometheus.client.MetricFamily" - tests := []struct { - name string - acceptHeaderValue string - expectedFmt string - }{ - { - name: "delimited format", - acceptHeaderValue: acceptValuePrefix + ";encoding=delimited", - expectedFmt: string(FmtProtoDelim), - }, - { - name: "text format", - acceptHeaderValue: acceptValuePrefix + ";encoding=text", - expectedFmt: string(FmtProtoText), - }, - { - name: "compact text format", - acceptHeaderValue: acceptValuePrefix + ";encoding=compact-text", - expectedFmt: string(FmtProtoCompact), - }, - { - name: "plain text format", - acceptHeaderValue: "text/plain;version=0.0.4", - expectedFmt: string(FmtText), - }, - } - - for _, test := range tests { - t.Run(test.name, func(t *testing.T) { - h := http.Header{} - h.Add(hdrAccept, test.acceptHeaderValue) - actualFmt := string(Negotiate(h)) - if actualFmt != test.expectedFmt { - t.Errorf("expected Negotiate to return format %s, but got %s instead", test.expectedFmt, actualFmt) - } - }) - } -} - -func TestEncode(t *testing.T) { - var buff bytes.Buffer - delimEncoder := NewEncoder(&buff, FmtProtoDelim) - metric := &dto.MetricFamily{ - Name: proto.String("foo_metric"), - Type: dto.MetricType_UNTYPED.Enum(), - Metric: []*dto.Metric{ - { - Untyped: &dto.Untyped{ - Value: proto.Float64(1.234), - }, - }, - }, - } - - err := delimEncoder.Encode(metric) - if err != nil { - t.Errorf("unexpected error during encode: %s", err.Error()) - } - - out := buff.Bytes() - if len(out) == 0 { - t.Errorf("expected the output bytes buffer to be non-empty") - } - - buff.Reset() - - compactEncoder := NewEncoder(&buff, FmtProtoCompact) - err = compactEncoder.Encode(metric) - if err != nil { - t.Errorf("unexpected error during encode: %s", err.Error()) - } - - out = buff.Bytes() - if len(out) == 0 { - t.Errorf("expected the output bytes buffer to be non-empty") - } - - buff.Reset() - - protoTextEncoder := NewEncoder(&buff, FmtProtoText) - err = protoTextEncoder.Encode(metric) - if err != nil { - t.Errorf("unexpected error during encode: %s", err.Error()) - } - - out = buff.Bytes() - if len(out) == 0 { - t.Errorf("expected the output bytes buffer to be non-empty") - } - - buff.Reset() - - textEncoder := NewEncoder(&buff, FmtText) - err = textEncoder.Encode(metric) - if err != nil { - t.Errorf("unexpected error during encode: %s", err.Error()) - } - - out = buff.Bytes() - if len(out) == 0 { - t.Errorf("expected the output bytes buffer to be non-empty") - } - - expected := "# TYPE foo_metric untyped\n" + - "foo_metric 1.234\n" - - if string(out) != expected { - t.Errorf("expected TextEncoder to return %s, but got %s instead", expected, string(out)) - } -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/expfmt/text_create.go new/prometheus-common/expfmt/text_create.go --- old/prometheus-common/expfmt/text_create.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/expfmt/text_create.go 2018-05-18 17:47:59.000000000 +0200 @@ -14,45 +14,13 @@ package expfmt import ( - "bytes" "fmt" "io" "math" - "strconv" "strings" - "sync" - - "github.com/prometheus/common/model" dto "github.com/prometheus/client_model/go" -) - -// enhancedWriter has all the enhanced write functions needed here. bytes.Buffer -// implements it. -type enhancedWriter interface { - io.Writer - WriteRune(r rune) (n int, err error) - WriteString(s string) (n int, err error) - WriteByte(c byte) error -} - -const ( - initialBufSize = 512 - initialNumBufSize = 24 -) - -var ( - bufPool = sync.Pool{ - New: func() interface{} { - return bytes.NewBuffer(make([]byte, 0, initialBufSize)) - }, - } - numBufPool = sync.Pool{ - New: func() interface{} { - b := make([]byte, 0, initialNumBufSize) - return &b - }, - } + "github.com/prometheus/common/model" ) // MetricFamilyToText converts a MetricFamily proto message into text format and @@ -64,92 +32,37 @@ // will result in invalid text format output. // // This method fulfills the type 'prometheus.encoder'. -func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (written int, err error) { +func MetricFamilyToText(out io.Writer, in *dto.MetricFamily) (int, error) { + var written int + // Fail-fast checks. if len(in.Metric) == 0 { - return 0, fmt.Errorf("MetricFamily has no metrics: %s", in) + return written, fmt.Errorf("MetricFamily has no metrics: %s", in) } name := in.GetName() if name == "" { - return 0, fmt.Errorf("MetricFamily has no name: %s", in) - } - - // Try the interface upgrade. If it doesn't work, we'll use a - // bytes.Buffer from the sync.Pool and write out its content to out in a - // single go in the end. - w, ok := out.(enhancedWriter) - if !ok { - b := bufPool.Get().(*bytes.Buffer) - b.Reset() - w = b - defer func() { - bWritten, bErr := out.Write(b.Bytes()) - written = bWritten - if err == nil { - err = bErr - } - bufPool.Put(b) - }() + return written, fmt.Errorf("MetricFamily has no name: %s", in) } - var n int - // Comments, first HELP, then TYPE. if in.Help != nil { - n, err = w.WriteString("# HELP ") - written += n - if err != nil { - return - } - n, err = w.WriteString(name) - written += n - if err != nil { - return - } - err = w.WriteByte(' ') - written++ - if err != nil { - return - } - n, err = writeEscapedString(w, *in.Help, false) + n, err := fmt.Fprintf( + out, "# HELP %s %s\n", + name, escapeString(*in.Help, false), + ) written += n if err != nil { - return - } - err = w.WriteByte('\n') - written++ - if err != nil { - return + return written, err } } - n, err = w.WriteString("# TYPE ") - written += n - if err != nil { - return - } - n, err = w.WriteString(name) - written += n - if err != nil { - return - } metricType := in.GetType() - switch metricType { - case dto.MetricType_COUNTER: - n, err = w.WriteString(" counter\n") - case dto.MetricType_GAUGE: - n, err = w.WriteString(" gauge\n") - case dto.MetricType_SUMMARY: - n, err = w.WriteString(" summary\n") - case dto.MetricType_UNTYPED: - n, err = w.WriteString(" untyped\n") - case dto.MetricType_HISTOGRAM: - n, err = w.WriteString(" histogram\n") - default: - return written, fmt.Errorf("unknown metric type %s", metricType.String()) - } + n, err := fmt.Fprintf( + out, "# TYPE %s %s\n", + name, strings.ToLower(metricType.String()), + ) written += n if err != nil { - return + return written, err } // Finally the samples, one line for each. @@ -162,8 +75,9 @@ ) } n, err = writeSample( - w, name, "", metric, "", 0, + name, metric, "", "", metric.Counter.GetValue(), + out, ) case dto.MetricType_GAUGE: if metric.Gauge == nil { @@ -172,8 +86,9 @@ ) } n, err = writeSample( - w, name, "", metric, "", 0, + name, metric, "", "", metric.Gauge.GetValue(), + out, ) case dto.MetricType_UNTYPED: if metric.Untyped == nil { @@ -182,8 +97,9 @@ ) } n, err = writeSample( - w, name, "", metric, "", 0, + name, metric, "", "", metric.Untyped.GetValue(), + out, ) case dto.MetricType_SUMMARY: if metric.Summary == nil { @@ -193,26 +109,29 @@ } for _, q := range metric.Summary.Quantile { n, err = writeSample( - w, name, "", metric, - model.QuantileLabel, q.GetQuantile(), + name, metric, + model.QuantileLabel, fmt.Sprint(q.GetQuantile()), q.GetValue(), + out, ) written += n if err != nil { - return + return written, err } } n, err = writeSample( - w, name, "_sum", metric, "", 0, + name+"_sum", metric, "", "", metric.Summary.GetSampleSum(), + out, ) - written += n if err != nil { - return + return written, err } + written += n n, err = writeSample( - w, name, "_count", metric, "", 0, + name+"_count", metric, "", "", float64(metric.Summary.GetSampleCount()), + out, ) case dto.MetricType_HISTOGRAM: if metric.Histogram == nil { @@ -221,42 +140,46 @@ ) } infSeen := false - for _, b := range metric.Histogram.Bucket { + for _, q := range metric.Histogram.Bucket { n, err = writeSample( - w, name, "_bucket", metric, - model.BucketLabel, b.GetUpperBound(), - float64(b.GetCumulativeCount()), + name+"_bucket", metric, + model.BucketLabel, fmt.Sprint(q.GetUpperBound()), + float64(q.GetCumulativeCount()), + out, ) written += n if err != nil { - return + return written, err } - if math.IsInf(b.GetUpperBound(), +1) { + if math.IsInf(q.GetUpperBound(), +1) { infSeen = true } } if !infSeen { n, err = writeSample( - w, name, "_bucket", metric, - model.BucketLabel, math.Inf(+1), + name+"_bucket", metric, + model.BucketLabel, "+Inf", float64(metric.Histogram.GetSampleCount()), + out, ) - written += n if err != nil { - return + return written, err } + written += n } n, err = writeSample( - w, name, "_sum", metric, "", 0, + name+"_sum", metric, "", "", metric.Histogram.GetSampleSum(), + out, ) - written += n if err != nil { - return + return written, err } + written += n n, err = writeSample( - w, name, "_count", metric, "", 0, + name+"_count", metric, "", "", float64(metric.Histogram.GetSampleCount()), + out, ) default: return written, fmt.Errorf( @@ -265,204 +188,116 @@ } written += n if err != nil { - return + return written, err } } - return + return written, nil } -// writeSample writes a single sample in text format to w, given the metric +// writeSample writes a single sample in text format to out, given the metric // name, the metric proto message itself, optionally an additional label name -// with a float64 value (use empty string as label name if not required), and -// the value. The function returns the number of bytes written and any error -// encountered. +// and value (use empty strings if not required), and the value. The function +// returns the number of bytes written and any error encountered. func writeSample( - w enhancedWriter, - name, suffix string, + name string, metric *dto.Metric, - additionalLabelName string, additionalLabelValue float64, + additionalLabelName, additionalLabelValue string, value float64, + out io.Writer, ) (int, error) { var written int - n, err := w.WriteString(name) + n, err := fmt.Fprint(out, name) written += n if err != nil { return written, err } - if suffix != "" { - n, err = w.WriteString(suffix) - written += n - if err != nil { - return written, err - } - } - n, err = writeLabelPairs( - w, metric.Label, additionalLabelName, additionalLabelValue, + n, err = labelPairsToText( + metric.Label, + additionalLabelName, additionalLabelValue, + out, ) written += n if err != nil { return written, err } - err = w.WriteByte(' ') - written++ - if err != nil { - return written, err - } - n, err = writeFloat(w, value) + n, err = fmt.Fprintf(out, " %v", value) written += n if err != nil { return written, err } if metric.TimestampMs != nil { - err = w.WriteByte(' ') - written++ - if err != nil { - return written, err - } - n, err = writeInt(w, *metric.TimestampMs) + n, err = fmt.Fprintf(out, " %v", *metric.TimestampMs) written += n if err != nil { return written, err } } - err = w.WriteByte('\n') - written++ + n, err = out.Write([]byte{'\n'}) + written += n if err != nil { return written, err } return written, nil } -// writeLabelPairs converts a slice of LabelPair proto messages plus the +// labelPairsToText converts a slice of LabelPair proto messages plus the // explicitly given additional label pair into text formatted as required by the -// text format and writes it to 'w'. An empty slice in combination with an empty -// string 'additionalLabelName' results in nothing being written. Otherwise, the -// label pairs are written, escaped as required by the text format, and enclosed -// in '{...}'. The function returns the number of bytes written and any error -// encountered. -func writeLabelPairs( - w enhancedWriter, +// text format and writes it to 'out'. An empty slice in combination with an +// empty string 'additionalLabelName' results in nothing being +// written. Otherwise, the label pairs are written, escaped as required by the +// text format, and enclosed in '{...}'. The function returns the number of +// bytes written and any error encountered. +func labelPairsToText( in []*dto.LabelPair, - additionalLabelName string, additionalLabelValue float64, + additionalLabelName, additionalLabelValue string, + out io.Writer, ) (int, error) { if len(in) == 0 && additionalLabelName == "" { return 0, nil } - var ( - written int - separator byte = '{' - ) + var written int + separator := '{' for _, lp := range in { - err := w.WriteByte(separator) - written++ - if err != nil { - return written, err - } - n, err := w.WriteString(lp.GetName()) - written += n - if err != nil { - return written, err - } - n, err = w.WriteString(`="`) + n, err := fmt.Fprintf( + out, `%c%s="%s"`, + separator, lp.GetName(), escapeString(lp.GetValue(), true), + ) written += n if err != nil { return written, err } - n, err = writeEscapedString(w, lp.GetValue(), true) - written += n - if err != nil { - return written, err - } - err = w.WriteByte('"') - written++ - if err != nil { - return written, err - } separator = ',' } if additionalLabelName != "" { - err := w.WriteByte(separator) - written++ - if err != nil { - return written, err - } - n, err := w.WriteString(additionalLabelName) - written += n - if err != nil { - return written, err - } - n, err = w.WriteString(`="`) - written += n - if err != nil { - return written, err - } - n, err = writeFloat(w, additionalLabelValue) + n, err := fmt.Fprintf( + out, `%c%s="%s"`, + separator, additionalLabelName, + escapeString(additionalLabelValue, true), + ) written += n if err != nil { return written, err } - err = w.WriteByte('"') - written++ - if err != nil { - return written, err - } } - err := w.WriteByte('}') - written++ + n, err := out.Write([]byte{'}'}) + written += n if err != nil { return written, err } return written, nil } -// writeEscapedString replaces '\' by '\\', new line character by '\n', and - if -// includeDoubleQuote is true - '"' by '\"'. var ( - escaper = strings.NewReplacer("\\", `\\`, "\n", `\n`) - quotedEscaper = strings.NewReplacer("\\", `\\`, "\n", `\n`, "\"", `\"`) + escape = strings.NewReplacer("\\", `\\`, "\n", `\n`) + escapeWithDoubleQuote = strings.NewReplacer("\\", `\\`, "\n", `\n`, "\"", `\"`) ) -func writeEscapedString(w enhancedWriter, v string, includeDoubleQuote bool) (int, error) { +// escapeString replaces '\' by '\\', new line character by '\n', and - if +// includeDoubleQuote is true - '"' by '\"'. +func escapeString(v string, includeDoubleQuote bool) string { if includeDoubleQuote { - return quotedEscaper.WriteString(w, v) - } else { - return escaper.WriteString(w, v) + return escapeWithDoubleQuote.Replace(v) } -} - -// writeFloat is equivalent to fmt.Fprint with a float64 argument but hardcodes -// a few common cases for increased efficiency. For non-hardcoded cases, it uses -// strconv.AppendFloat to avoid allocations, similar to writeInt. -func writeFloat(w enhancedWriter, f float64) (int, error) { - switch { - case f == 1: - return 1, w.WriteByte('1') - case f == 0: - return 1, w.WriteByte('0') - case f == -1: - return w.WriteString("-1") - case math.IsNaN(f): - return w.WriteString("NaN") - case math.IsInf(f, +1): - return w.WriteString("+Inf") - case math.IsInf(f, -1): - return w.WriteString("-Inf") - default: - bp := numBufPool.Get().(*[]byte) - *bp = strconv.AppendFloat((*bp)[:0], f, 'g', -1, 64) - written, err := w.Write(*bp) - numBufPool.Put(bp) - return written, err - } -} -// writeInt is equivalent to fmt.Fprint with an int64 argument but uses -// strconv.AppendInt with a byte slice taken from a sync.Pool to avoid -// allocations. -func writeInt(w enhancedWriter, i int64) (int, error) { - bp := numBufPool.Get().(*[]byte) - *bp = strconv.AppendInt((*bp)[:0], i, 10) - written, err := w.Write(*bp) - numBufPool.Put(bp) - return written, err + return escape.Replace(v) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/expfmt/text_create_test.go new/prometheus-common/expfmt/text_create_test.go --- old/prometheus-common/expfmt/text_create_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/expfmt/text_create_test.go 2018-05-18 17:47:59.000000000 +0200 @@ -24,7 +24,7 @@ dto "github.com/prometheus/client_model/go" ) -func TestCreate(t *testing.T) { +func testCreate(t testing.TB) { var scenarios = []struct { in *dto.MetricFamily out string @@ -357,145 +357,17 @@ } -func BenchmarkCreate(b *testing.B) { - mf := &dto.MetricFamily{ - Name: proto.String("request_duration_microseconds"), - Help: proto.String("The response latency."), - Type: dto.MetricType_HISTOGRAM.Enum(), - Metric: []*dto.Metric{ - &dto.Metric{ - Label: []*dto.LabelPair{ - &dto.LabelPair{ - Name: proto.String("name_1"), - Value: proto.String("val with\nnew line"), - }, - &dto.LabelPair{ - Name: proto.String("name_2"), - Value: proto.String("val with \\backslash and \"quotes\""), - }, - &dto.LabelPair{ - Name: proto.String("name_3"), - Value: proto.String("Just a quite long label value to test performance."), - }, - }, - Histogram: &dto.Histogram{ - SampleCount: proto.Uint64(2693), - SampleSum: proto.Float64(1756047.3), - Bucket: []*dto.Bucket{ - &dto.Bucket{ - UpperBound: proto.Float64(100), - CumulativeCount: proto.Uint64(123), - }, - &dto.Bucket{ - UpperBound: proto.Float64(120), - CumulativeCount: proto.Uint64(412), - }, - &dto.Bucket{ - UpperBound: proto.Float64(144), - CumulativeCount: proto.Uint64(592), - }, - &dto.Bucket{ - UpperBound: proto.Float64(172.8), - CumulativeCount: proto.Uint64(1524), - }, - &dto.Bucket{ - UpperBound: proto.Float64(math.Inf(+1)), - CumulativeCount: proto.Uint64(2693), - }, - }, - }, - }, - &dto.Metric{ - Label: []*dto.LabelPair{ - &dto.LabelPair{ - Name: proto.String("name_1"), - Value: proto.String("Björn"), - }, - &dto.LabelPair{ - Name: proto.String("name_2"), - Value: proto.String("佖佥"), - }, - &dto.LabelPair{ - Name: proto.String("name_3"), - Value: proto.String("Just a quite long label value to test performance."), - }, - }, - Histogram: &dto.Histogram{ - SampleCount: proto.Uint64(5699), - SampleSum: proto.Float64(49484343543.4343), - Bucket: []*dto.Bucket{ - &dto.Bucket{ - UpperBound: proto.Float64(100), - CumulativeCount: proto.Uint64(120), - }, - &dto.Bucket{ - UpperBound: proto.Float64(120), - CumulativeCount: proto.Uint64(412), - }, - &dto.Bucket{ - UpperBound: proto.Float64(144), - CumulativeCount: proto.Uint64(596), - }, - &dto.Bucket{ - UpperBound: proto.Float64(172.8), - CumulativeCount: proto.Uint64(1535), - }, - }, - }, - TimestampMs: proto.Int64(1234567890), - }, - }, - } - out := bytes.NewBuffer(make([]byte, 0, 1024)) - - for i := 0; i < b.N; i++ { - _, err := MetricFamilyToText(out, mf) - if err != nil { - b.Fatal(err) - } - out.Reset() - } +func TestCreate(t *testing.T) { + testCreate(t) } -func BenchmarkCreateBuildInfo(b *testing.B) { - mf := &dto.MetricFamily{ - Name: proto.String("benchmark_build_info"), - Help: proto.String("Test the creation of constant 1-value build_info metric."), - Type: dto.MetricType_GAUGE.Enum(), - Metric: []*dto.Metric{ - &dto.Metric{ - Label: []*dto.LabelPair{ - &dto.LabelPair{ - Name: proto.String("version"), - Value: proto.String("1.2.3"), - }, - &dto.LabelPair{ - Name: proto.String("revision"), - Value: proto.String("2e84f5e4eacdffb574035810305191ff390360fe"), - }, - &dto.LabelPair{ - Name: proto.String("go_version"), - Value: proto.String("1.11.1"), - }, - }, - Gauge: &dto.Gauge{ - Value: proto.Float64(1), - }, - }, - }, - } - out := bytes.NewBuffer(make([]byte, 0, 1024)) - +func BenchmarkCreate(b *testing.B) { for i := 0; i < b.N; i++ { - _, err := MetricFamilyToText(out, mf) - if err != nil { - b.Fatal(err) - } - out.Reset() + testCreate(b) } } -func TestCreateError(t *testing.T) { +func testCreateError(t testing.TB) { var scenarios = []struct { in *dto.MetricFamily err string @@ -559,3 +431,13 @@ } } + +func TestCreateError(t *testing.T) { + testCreateError(t) +} + +func BenchmarkCreateError(b *testing.B) { + for i := 0; i < b.N; i++ { + testCreateError(b) + } +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/expfmt/text_parse.go new/prometheus-common/expfmt/text_parse.go --- old/prometheus-common/expfmt/text_parse.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/expfmt/text_parse.go 2018-05-18 17:47:59.000000000 +0200 @@ -359,7 +359,7 @@ } return p.readingValue default: - p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.GetValue())) + p.parseError(fmt.Sprintf("unexpected end of label value %q", p.currentLabelPair.Value)) return nil } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/model/alert_test.go new/prometheus-common/model/alert_test.go --- old/prometheus-common/model/alert_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/model/alert_test.go 2018-05-18 17:47:59.000000000 +0200 @@ -14,8 +14,6 @@ package model import ( - "fmt" - "sort" "strings" "testing" "time" @@ -118,160 +116,3 @@ } } } - -func TestAlert(t *testing.T) { - // Verifying that an alert with no EndsAt field is unresolved and has firing status. - alert := &Alert{ - Labels: LabelSet{"foo": "bar", "lorem": "ipsum"}, - StartsAt: time.Now(), - } - - actual := fmt.Sprint(alert) - expected := "[d181d0f][active]" - - if actual != expected { - t.Errorf("expected %s, but got %s", expected, actual) - } - - actualStatus := string(alert.Status()) - expectedStatus := "firing" - - if actualStatus != expectedStatus { - t.Errorf("expected alertStatus %s, but got %s", expectedStatus, actualStatus) - } - - // Verifying that an alert with an EndsAt time before the current time is resolved and has resolved status. - ts := time.Now() - ts1 := ts.Add(-2 * time.Minute) - ts2 := ts.Add(-1 * time.Minute) - alert = &Alert{ - Labels: LabelSet{"foo": "bar", "lorem": "ipsum"}, - StartsAt: ts1, - EndsAt: ts2, - } - - actual = fmt.Sprint(alert) - expected = "[d181d0f][resolved]" - - if actual != expected { - t.Errorf("expected %s, but got %s", expected, actual) - } - - actualStatus = string(alert.Status()) - expectedStatus = "resolved" - - if actualStatus != expectedStatus { - t.Errorf("expected alertStatus %s, but got %s", expectedStatus, actualStatus) - } -} - -func TestSortAlerts(t *testing.T) { - ts := time.Now() - alerts := Alerts{ - { - Labels: LabelSet{ - "alertname": "InternalError", - "dev": "sda3", - }, - StartsAt: ts.Add(-6 * time.Minute), - EndsAt: ts.Add(-3 * time.Minute), - }, - { - Labels: LabelSet{ - "alertname": "DiskFull", - "dev": "sda1", - }, - StartsAt: ts.Add(-5 * time.Minute), - EndsAt: ts.Add(-4 * time.Minute), - }, - { - Labels: LabelSet{ - "alertname": "OutOfMemory", - "dev": "sda1", - }, - StartsAt: ts.Add(-2 * time.Minute), - EndsAt: ts.Add(-1 * time.Minute), - }, - { - Labels: LabelSet{ - "alertname": "DiskFull", - "dev": "sda2", - }, - StartsAt: ts.Add(-2 * time.Minute), - EndsAt: ts.Add(-3 * time.Minute), - }, - { - Labels: LabelSet{ - "alertname": "OutOfMemory", - "dev": "sda2", - }, - StartsAt: ts.Add(-5 * time.Minute), - EndsAt: ts.Add(-2 * time.Minute), - }, - } - - sort.Sort(alerts) - - expected := []string{ - "DiskFull[5ffe595][resolved]", - "InternalError[09cfd46][resolved]", - "OutOfMemory[d43a602][resolved]", - "DiskFull[5ff4595][resolved]", - "OutOfMemory[d444602][resolved]", - } - - for i := range alerts { - if alerts[i].String() != expected[i] { - t.Errorf("expected alert %s at index %d, but got %s", expected[i], i, alerts[i].String()) - } - } -} - -func TestAlertsStatus(t *testing.T) { - firingAlerts := Alerts{ - { - Labels: LabelSet{ - "foo": "bar", - }, - StartsAt: time.Now(), - }, - { - Labels: LabelSet{ - "bar": "baz", - }, - StartsAt: time.Now(), - }, - } - - actualStatus := firingAlerts.Status() - expectedStatus := AlertFiring - - if actualStatus != expectedStatus { - t.Errorf("expected status %s, but got %s", expectedStatus, actualStatus) - } - - ts := time.Now() - resolvedAlerts := Alerts{ - { - Labels: LabelSet{ - "foo": "bar", - }, - StartsAt: ts.Add(-1 * time.Minute), - EndsAt: ts, - }, - { - Labels: LabelSet{ - "bar": "baz", - }, - StartsAt: ts.Add(-1 * time.Minute), - EndsAt: ts, - }, - } - - actualStatus = resolvedAlerts.Status() - expectedStatus = AlertResolved - - if actualStatus != expectedStatus { - t.Errorf("expected status %s, but got %s", expectedStatus, actualStatus) - } -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/model/metric_test.go new/prometheus-common/model/metric_test.go --- old/prometheus-common/model/metric_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/model/metric_test.go 2018-05-18 17:47:59.000000000 +0200 @@ -119,10 +119,6 @@ mn: "colon:in:the:middle", valid: true, }, - { - mn: "", - valid: false, - }, } for _, s := range scenarios { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/model/time.go new/prometheus-common/model/time.go --- old/prometheus-common/model/time.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/model/time.go 2018-05-18 17:47:59.000000000 +0200 @@ -43,7 +43,7 @@ // (1970-01-01 00:00 UTC) excluding leap seconds. type Time int64 -// Interval describes an interval between two timestamps. +// Interval describes and interval between two timestamps. type Interval struct { Start, End Time } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/model/value_test.go new/prometheus-common/model/value_test.go --- old/prometheus-common/model/value_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/model/value_test.go 2018-05-18 17:47:59.000000000 +0200 @@ -402,7 +402,7 @@ Metric: Metric{ MetricNameLabel: "B", }, - Timestamp: 3, + Timestamp: 1, }, &Sample{ Metric: Metric{ @@ -410,12 +410,6 @@ }, Timestamp: 2, }, - &Sample{ - Metric: Metric{ - MetricNameLabel: "B", - }, - Timestamp: 1, - }, } expected := Vector{ @@ -445,12 +439,6 @@ }, &Sample{ Metric: Metric{ - MetricNameLabel: "B", - }, - Timestamp: 3, - }, - &Sample{ - Metric: Metric{ MetricNameLabel: "C", }, Timestamp: 1, diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/promlog/flag/flag.go new/prometheus-common/promlog/flag/flag.go --- old/prometheus-common/promlog/flag/flag.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/promlog/flag/flag.go 2018-05-18 17:47:59.000000000 +0200 @@ -25,21 +25,9 @@ // LevelFlagHelp is the help description for the log.level flag. const LevelFlagHelp = "Only log messages with the given severity or above. One of: [debug, info, warn, error]" -// FormatFlagName is the canonical flag name to configure the log format -// within Prometheus projects. -const FormatFlagName = "log.format" - -// FormatFlagHelp is the help description for the log.format flag. -const FormatFlagHelp = "Output format of log messages. One of: [logfmt, json]" - // AddFlags adds the flags used by this package to the Kingpin application. // To use the default Kingpin application, call AddFlags(kingpin.CommandLine) -func AddFlags(a *kingpin.Application, config *promlog.Config) { - config.Level = &promlog.AllowedLevel{} +func AddFlags(a *kingpin.Application, logLevel *promlog.AllowedLevel) { a.Flag(LevelFlagName, LevelFlagHelp). - Default("info").SetValue(config.Level) - - config.Format = &promlog.AllowedFormat{} - a.Flag(FormatFlagName, FormatFlagHelp). - Default("logfmt").SetValue(config.Format) + Default("info").SetValue(logLevel) } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/promlog/log.go new/prometheus-common/promlog/log.go --- old/prometheus-common/promlog/log.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/promlog/log.go 2018-05-18 17:47:59.000000000 +0200 @@ -53,43 +53,11 @@ return nil } -// AllowedFormat is a settable identifier for the output format that the logger can have. -type AllowedFormat struct { - s string -} - -func (f *AllowedFormat) String() string { - return f.s -} - -// Set updates the value of the allowed format. -func (f *AllowedFormat) Set(s string) error { - switch s { - case "logfmt", "json": - f.s = s - default: - return errors.Errorf("unrecognized log format %q", s) - } - return nil -} - -// Config is a struct containing configurable settings for the logger -type Config struct { - Level *AllowedLevel - Format *AllowedFormat -} - -// New returns a new leveled oklog logger. Each logged line will be annotated +// New returns a new leveled oklog logger in the logfmt format. Each logged line will be annotated // with a timestamp. The output always goes to stderr. -func New(config *Config) log.Logger { - var l log.Logger - if config.Format.s == "logfmt" { - l = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) - } else { - l = log.NewJSONLogger(log.NewSyncWriter(os.Stderr)) - } - - l = level.NewFilter(l, config.Level.o) +func New(al AllowedLevel) log.Logger { + l := log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr)) + l = level.NewFilter(l, al.o) l = log.With(l, "ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) return l } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/route/route.go new/prometheus-common/route/route.go --- old/prometheus-common/route/route.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/route/route.go 2018-05-18 17:47:59.000000000 +0200 @@ -1,10 +1,10 @@ package route import ( - "context" "net/http" "github.com/julienschmidt/httprouter" + "golang.org/x/net/context" ) type param string diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/prometheus-common/route/route_test.go new/prometheus-common/route/route_test.go --- old/prometheus-common/route/route_test.go 2018-11-26 13:14:08.000000000 +0100 +++ new/prometheus-common/route/route_test.go 2018-05-18 17:47:59.000000000 +0200 @@ -43,43 +43,6 @@ router.ServeHTTP(nil, r) } -func TestContextWithValue(t *testing.T) { - router := New() - router.Get("/test/:foo/", func(w http.ResponseWriter, r *http.Request) { - want := "bar" - got := Param(r.Context(), "foo") - if want != got { - t.Fatalf("Unexpected context value: want %q, got %q", want, got) - } - want = "ipsum" - got = Param(r.Context(), "lorem") - if want != got { - t.Fatalf("Unexpected context value: want %q, got %q", want, got) - } - want = "sit" - got = Param(r.Context(), "dolor") - if want != got { - t.Fatalf("Unexpected context value: want %q, got %q", want, got) - } - }) - - r, err := http.NewRequest("GET", "http://localhost:9090/test/bar/", nil) - if err != nil { - t.Fatalf("Error building test request: %s", err) - } - params := map[string]string{ - "lorem": "ipsum", - "dolor": "sit", - } - - ctx := r.Context() - for p, v := range params { - ctx = WithParam(ctx, p, v) - } - r = r.WithContext(ctx) - router.ServeHTTP(nil, r) -} - func TestInstrumentation(t *testing.T) { var got string cases := []struct {
