From 2317e2d5a691711d60dae1597f6a8dac669e8e36 Mon Sep 17 00:00:00 2001 From: utukj Date: Wed, 28 Sep 2022 14:26:51 +0100 Subject: [PATCH 1/2] replaced crypto/sha with https://github.com/minio/sha256-simd Signed-off-by: utukj --- go.mod | 2 +- internal/cortex/chunk/schema_util.go | 3 +- pkg/block/metadata/hash.go | 3 +- pkg/reloader/reloader.go | 55 ++++++++++++++-------------- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/go.mod b/go.mod index 26abbafcc4..046906dc17 100644 --- a/go.mod +++ b/go.mod @@ -100,6 +100,7 @@ require ( require ( github.com/efficientgo/core v1.0.0-rc.0 + github.com/minio/sha256-simd v1.0.0 go.opentelemetry.io/otel v1.10.0 go.opentelemetry.io/otel/bridge/opentracing v1.10.0 go.opentelemetry.io/otel/sdk v1.9.0 @@ -200,7 +201,6 @@ require ( github.com/mattn/go-runewidth v0.0.13 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect github.com/minio/md5-simd v1.1.2 // indirect - github.com/minio/sha256-simd v1.0.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/internal/cortex/chunk/schema_util.go b/internal/cortex/chunk/schema_util.go index e18a8e8000..74906a732f 100644 --- a/internal/cortex/chunk/schema_util.go +++ b/internal/cortex/chunk/schema_util.go @@ -4,7 +4,6 @@ package chunk import ( - "crypto/sha256" "encoding/base64" "encoding/binary" "encoding/hex" @@ -13,6 +12,8 @@ import ( "strings" "sync" + "github.com/minio/sha256-simd" + "fmt" "github.com/pkg/errors" diff --git a/pkg/block/metadata/hash.go b/pkg/block/metadata/hash.go index 424d8868f5..36bdea694e 100644 --- a/pkg/block/metadata/hash.go +++ b/pkg/block/metadata/hash.go @@ -4,13 +4,14 @@ package metadata import ( - "crypto/sha256" "encoding/hex" "fmt" "io" "os" "path/filepath" + "github.com/minio/sha256-simd" + "github.com/go-kit/log" "github.com/pkg/errors" diff --git a/pkg/reloader/reloader.go b/pkg/reloader/reloader.go index 2941aaad42..6f2962249f 100644 --- a/pkg/reloader/reloader.go +++ b/pkg/reloader/reloader.go @@ -6,57 +6,56 @@ // // Reloader type is useful when you want to: // -// * Watch on changes against certain file e.g (`cfgFile`). -// * Optionally, specify different output file for watched `cfgFile` (`cfgOutputFile`). -// This will also try decompress the `cfgFile` if needed and substitute ALL the envvars using Kubernetes substitution format: (`$(var)`) -// * Watch on changes against certain directories (`watchedDirs`). +// - Watch on changes against certain file e.g (`cfgFile`). +// - Optionally, specify different output file for watched `cfgFile` (`cfgOutputFile`). +// This will also try decompress the `cfgFile` if needed and substitute ALL the envvars using Kubernetes substitution format: (`$(var)`) +// - Watch on changes against certain directories (`watchedDirs`). // // Once any of those two changes, Prometheus on given `reloadURL` will be notified, causing Prometheus to reload configuration and rules. // // This and below for reloader: // -// u, _ := url.Parse("http://localhost:9090") -// rl := reloader.New(nil, nil, &reloader.Options{ -// ReloadURL: reloader.ReloadURLFromBase(u), -// CfgFile: "/path/to/cfg", -// CfgOutputFile: "/path/to/cfg.out", -// WatchedDirs: []string{"/path/to/dirs"}, -// WatchInterval: 3 * time.Minute, -// RetryInterval: 5 * time.Second, -// }) +// u, _ := url.Parse("http://localhost:9090") +// rl := reloader.New(nil, nil, &reloader.Options{ +// ReloadURL: reloader.ReloadURLFromBase(u), +// CfgFile: "/path/to/cfg", +// CfgOutputFile: "/path/to/cfg.out", +// WatchedDirs: []string{"/path/to/dirs"}, +// WatchInterval: 3 * time.Minute, +// RetryInterval: 5 * time.Second, +// }) // // The url of reloads can be generated with function ReloadURLFromBase(). // It will append the default path of reload into the given url: // -// u, _ := url.Parse("http://localhost:9090") -// reloader.ReloadURLFromBase(u) // It will return "http://localhost:9090/-/reload" +// u, _ := url.Parse("http://localhost:9090") +// reloader.ReloadURLFromBase(u) // It will return "http://localhost:9090/-/reload" // // Start watching changes and stopped until the context gets canceled: // -// ctx, cancel := context.WithCancel(context.Background()) -// go func() { -// if err := rl.Watch(ctx); err != nil { -// log.Fatal(err) -// } -// }() -// // ... -// cancel() +// ctx, cancel := context.WithCancel(context.Background()) +// go func() { +// if err := rl.Watch(ctx); err != nil { +// log.Fatal(err) +// } +// }() +// // ... +// cancel() // // Reloader will make a schedule to check the given config files and dirs of sum of hash with the last result, // even if it is no changes. // // A basic example of configuration template with environment variables: // -// global: -// external_labels: -// replica: '$(HOSTNAME)' +// global: +// external_labels: +// replica: '$(HOSTNAME)' package reloader import ( "bytes" "compress/gzip" "context" - "crypto/sha256" "hash" "io" "net/http" @@ -69,6 +68,8 @@ import ( "sync" "time" + "github.com/minio/sha256-simd" + "github.com/fsnotify/fsnotify" "github.com/go-kit/log" "github.com/go-kit/log/level" From 6c73ea0f0edb09c6adacfdbb70c62f758bae7c72 Mon Sep 17 00:00:00 2001 From: utukj Date: Thu, 29 Sep 2022 09:28:13 +0100 Subject: [PATCH 2/2] fixed import grouping Signed-off-by: utukj --- internal/cortex/chunk/schema_util.go | 4 +- pkg/block/metadata/hash.go | 3 +- pkg/reloader/reloader.go | 55 ++++++++++++++-------------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/internal/cortex/chunk/schema_util.go b/internal/cortex/chunk/schema_util.go index 74906a732f..a2c52369bd 100644 --- a/internal/cortex/chunk/schema_util.go +++ b/internal/cortex/chunk/schema_util.go @@ -8,14 +8,12 @@ import ( "encoding/binary" "encoding/hex" "encoding/json" + "fmt" "strconv" "strings" "sync" "github.com/minio/sha256-simd" - - "fmt" - "github.com/pkg/errors" "github.com/prometheus/common/model" "github.com/prometheus/prometheus/model/labels" diff --git a/pkg/block/metadata/hash.go b/pkg/block/metadata/hash.go index 36bdea694e..0daf1bf799 100644 --- a/pkg/block/metadata/hash.go +++ b/pkg/block/metadata/hash.go @@ -10,9 +10,8 @@ import ( "os" "path/filepath" - "github.com/minio/sha256-simd" - "github.com/go-kit/log" + "github.com/minio/sha256-simd" "github.com/pkg/errors" "github.com/thanos-io/thanos/pkg/runutil" diff --git a/pkg/reloader/reloader.go b/pkg/reloader/reloader.go index 6f2962249f..fe062e456a 100644 --- a/pkg/reloader/reloader.go +++ b/pkg/reloader/reloader.go @@ -6,50 +6,50 @@ // // Reloader type is useful when you want to: // -// - Watch on changes against certain file e.g (`cfgFile`). -// - Optionally, specify different output file for watched `cfgFile` (`cfgOutputFile`). -// This will also try decompress the `cfgFile` if needed and substitute ALL the envvars using Kubernetes substitution format: (`$(var)`) -// - Watch on changes against certain directories (`watchedDirs`). +// * Watch on changes against certain file e.g (`cfgFile`). +// * Optionally, specify different output file for watched `cfgFile` (`cfgOutputFile`). +// This will also try decompress the `cfgFile` if needed and substitute ALL the envvars using Kubernetes substitution format: (`$(var)`) +// * Watch on changes against certain directories (`watchedDirs`). // // Once any of those two changes, Prometheus on given `reloadURL` will be notified, causing Prometheus to reload configuration and rules. // // This and below for reloader: // -// u, _ := url.Parse("http://localhost:9090") -// rl := reloader.New(nil, nil, &reloader.Options{ -// ReloadURL: reloader.ReloadURLFromBase(u), -// CfgFile: "/path/to/cfg", -// CfgOutputFile: "/path/to/cfg.out", -// WatchedDirs: []string{"/path/to/dirs"}, -// WatchInterval: 3 * time.Minute, -// RetryInterval: 5 * time.Second, -// }) +// u, _ := url.Parse("http://localhost:9090") +// rl := reloader.New(nil, nil, &reloader.Options{ +// ReloadURL: reloader.ReloadURLFromBase(u), +// CfgFile: "/path/to/cfg", +// CfgOutputFile: "/path/to/cfg.out", +// WatchedDirs: []string{"/path/to/dirs"}, +// WatchInterval: 3 * time.Minute, +// RetryInterval: 5 * time.Second, +// }) // // The url of reloads can be generated with function ReloadURLFromBase(). // It will append the default path of reload into the given url: // -// u, _ := url.Parse("http://localhost:9090") -// reloader.ReloadURLFromBase(u) // It will return "http://localhost:9090/-/reload" +// u, _ := url.Parse("http://localhost:9090") +// reloader.ReloadURLFromBase(u) // It will return "http://localhost:9090/-/reload" // // Start watching changes and stopped until the context gets canceled: // -// ctx, cancel := context.WithCancel(context.Background()) -// go func() { -// if err := rl.Watch(ctx); err != nil { -// log.Fatal(err) -// } -// }() -// // ... -// cancel() +// ctx, cancel := context.WithCancel(context.Background()) +// go func() { +// if err := rl.Watch(ctx); err != nil { +// log.Fatal(err) +// } +// }() +// // ... +// cancel() // // Reloader will make a schedule to check the given config files and dirs of sum of hash with the last result, // even if it is no changes. // // A basic example of configuration template with environment variables: // -// global: -// external_labels: -// replica: '$(HOSTNAME)' +// global: +// external_labels: +// replica: '$(HOSTNAME)' package reloader import ( @@ -68,11 +68,10 @@ import ( "sync" "time" - "github.com/minio/sha256-simd" - "github.com/fsnotify/fsnotify" "github.com/go-kit/log" "github.com/go-kit/log/level" + "github.com/minio/sha256-simd" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto"