diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5670d6079..a7a40c1be 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - name: install Go uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 with: diff --git a/expfmt/decode.go b/expfmt/decode.go index b2b89b017..25cfaa216 100644 --- a/expfmt/decode.go +++ b/expfmt/decode.go @@ -75,14 +75,14 @@ func ResponseFormat(h http.Header) Format { func NewDecoder(r io.Reader, format Format) Decoder { switch format.FormatType() { case TypeProtoDelim: - return &protoDecoder{r: r} + return &protoDecoder{r: bufio.NewReader(r)} } return &textDecoder{r: r} } // protoDecoder implements the Decoder interface for protocol buffers. type protoDecoder struct { - r io.Reader + r protodelim.Reader } // Decode implements the Decoder interface. @@ -90,7 +90,7 @@ func (d *protoDecoder) Decode(v *dto.MetricFamily) error { opts := protodelim.UnmarshalOptions{ MaxSize: -1, } - if err := opts.UnmarshalFrom(bufio.NewReader(d.r), v); err != nil { + if err := opts.UnmarshalFrom(d.r, v); err != nil { return err } if !model.IsValidMetricName(model.LabelValue(v.GetName())) { diff --git a/expfmt/decode_test.go b/expfmt/decode_test.go index e5e245d3b..19560ffc5 100644 --- a/expfmt/decode_test.go +++ b/expfmt/decode_test.go @@ -15,10 +15,12 @@ package expfmt import ( "bufio" + "bytes" "errors" "io" "math" "net/http" + "os" "reflect" "sort" "strings" @@ -414,6 +416,31 @@ func TestProtoDecoder(t *testing.T) { } } +func TestProtoMultiMessageDecoder(t *testing.T) { + data, err := os.ReadFile("testdata/protobuf-multimessage") + if err != nil { + t.Fatalf("Reading file failed: %v", err) + } + + buf := bytes.NewReader(data) + decoder := NewDecoder(buf, fmtProtoDelim) + var metrics []*dto.MetricFamily + for { + var mf dto.MetricFamily + if err := decoder.Decode(&mf); err != nil { + if errors.Is(err, io.EOF) { + break + } + t.Fatalf("Unmarshalling failed: %v", err) + } + metrics = append(metrics, &mf) + } + + if len(metrics) != 6 { + t.Fatalf("Expected %d metrics but got %d!", 6, len(metrics)) + } +} + func testDiscriminatorHTTPHeader(t testing.TB) { scenarios := []struct { input map[string]string diff --git a/expfmt/testdata/protobuf-multimessage b/expfmt/testdata/protobuf-multimessage new file mode 100644 index 000000000..d9fa9fe14 Binary files /dev/null and b/expfmt/testdata/protobuf-multimessage differ diff --git a/sigv4/go.mod b/sigv4/go.mod index 3304d6254..cf23cdfbf 100644 --- a/sigv4/go.mod +++ b/sigv4/go.mod @@ -5,7 +5,7 @@ go 1.21 replace github.com/prometheus/common => ../ require ( - github.com/aws/aws-sdk-go v1.50.31 + github.com/aws/aws-sdk-go v1.51.11 github.com/prometheus/client_golang v1.19.0 github.com/prometheus/common v0.48.0 github.com/stretchr/testify v1.9.0 diff --git a/sigv4/go.sum b/sigv4/go.sum index 2d1abf7bf..5f12db289 100644 --- a/sigv4/go.sum +++ b/sigv4/go.sum @@ -1,5 +1,5 @@ -github.com/aws/aws-sdk-go v1.50.31 h1:gx2NRLLEDUmQFC4YUsfMUKkGCwpXVO8ijUecq/nOQGA= -github.com/aws/aws-sdk-go v1.50.31/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.51.11 h1:El5VypsMIz7sFwAAj/j06JX9UGs4KAbAIEaZ57bNY4s= +github.com/aws/aws-sdk-go v1.51.11/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= diff --git a/version/info.go b/version/info.go index 044032c70..197d95e5c 100644 --- a/version/info.go +++ b/version/info.go @@ -17,6 +17,7 @@ import ( "bytes" "fmt" "runtime" + "runtime/debug" "strings" "text/template" ) @@ -31,6 +32,9 @@ var ( GoVersion = runtime.Version() GoOS = runtime.GOOS GoArch = runtime.GOARCH + + computedRevision string + computedTags string ) // versionInfoTmpl contains the template used by Info. @@ -74,3 +78,48 @@ func Info() string { func BuildContext() string { return fmt.Sprintf("(go=%s, platform=%s, user=%s, date=%s, tags=%s)", GoVersion, GoOS+"/"+GoArch, BuildUser, BuildDate, GetTags()) } + +func GetRevision() string { + if Revision != "" { + return Revision + } + return computedRevision +} + +func GetTags() string { + return computedTags +} + +func init() { + computedRevision, computedTags = computeRevision() +} + +func computeRevision() (string, string) { + var ( + rev = "unknown" + tags = "unknown" + modified bool + ) + + buildInfo, ok := debug.ReadBuildInfo() + if !ok { + return rev, tags + } + for _, v := range buildInfo.Settings { + if v.Key == "vcs.revision" { + rev = v.Value + } + if v.Key == "vcs.modified" { + if v.Value == "true" { + modified = true + } + } + if v.Key == "-tags" { + tags = v.Value + } + } + if modified { + return rev + "-modified", tags + } + return rev, tags +} diff --git a/version/info_default.go b/version/info_default.go deleted file mode 100644 index 684996f10..000000000 --- a/version/info_default.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2022 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. - -//go:build !go1.18 -// +build !go1.18 - -package version - -func GetRevision() string { - return Revision -} - -func getTags() string { - return "unknown" // Not available prior to Go 1.18 -} diff --git a/version/info_go118.go b/version/info_go118.go deleted file mode 100644 index 992623c6c..000000000 --- a/version/info_go118.go +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2022 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. - -//go:build go1.18 -// +build go1.18 - -package version - -import "runtime/debug" - -var ( - computedRevision string - computedTags string -) - -func GetRevision() string { - if Revision != "" { - return Revision - } - return computedRevision -} - -func GetTags() string { - return computedTags -} - -func init() { - computedRevision, computedTags = computeRevision() -} - -func computeRevision() (string, string) { - var ( - rev = "unknown" - tags = "unknown" - modified bool - ) - - buildInfo, ok := debug.ReadBuildInfo() - if !ok { - return rev, tags - } - for _, v := range buildInfo.Settings { - if v.Key == "vcs.revision" { - rev = v.Value - } - if v.Key == "vcs.modified" { - if v.Value == "true" { - modified = true - } - } - if v.Key == "-tags" { - tags = v.Value - } - } - if modified { - return rev + "-modified", tags - } - return rev, tags -}