Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add pkg/util/log package #5187

Merged
merged 3 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Main

* [5187](https://github.com/grafana/loki/pull/5187) **aknuds1** Rename metric `cortex_experimental_features_in_use_total` to `loki_experimental_features_in_use_total` and metric `log_messages_total` to `loki_log_messages_total`.
aknuds1 marked this conversation as resolved.
Show resolved Hide resolved
* [5170](https://github.com/grafana/loki/pull/5170) **chaudum** Fix deadlock in Promtail caused when targets got removed from a target group by the discovery manager.
* [5163](https://github.com/grafana/loki/pull/5163) **chaudum** Fix regression in fluentd plugin introduced with #5107 that caused `NoMethodError` when parsing non-string values of log lines.
* [5144](https://github.com/grafana/loki/pull/5144) **dannykopping** Ruler: fix remote write basic auth credentials.
Expand Down
3 changes: 2 additions & 1 deletion clients/cmd/docker-driver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"reflect"
"testing"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/docker/docker/daemon/logger"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"

"github.com/grafana/loki/clients/pkg/logentry/stages"

util_log "github.com/grafana/loki/pkg/util/log"
)

var jobRename = `
Expand Down
3 changes: 2 additions & 1 deletion clients/cmd/docker-driver/loki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/docker/docker/daemon/logger"
"github.com/stretchr/testify/require"

util_log "github.com/grafana/loki/pkg/util/log"
)

func Test_loki_LogWhenClosed(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion clients/cmd/docker-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
_ "net/http/pprof"
"os"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/docker/go-plugins-helpers/sdk"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand All @@ -15,6 +14,7 @@ import (

"github.com/grafana/loki/pkg/util"
_ "github.com/grafana/loki/pkg/util/build"
util_log "github.com/grafana/loki/pkg/util/log"
)

const socketAddress = "/run/docker/plugins/loki.sock"
Expand Down
12 changes: 6 additions & 6 deletions clients/cmd/promtail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"k8s.io/klog"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/flagext"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -22,9 +21,10 @@ import (
"github.com/grafana/loki/clients/pkg/promtail"
"github.com/grafana/loki/clients/pkg/promtail/config"

logutil "github.com/grafana/loki/pkg/util"
"github.com/grafana/loki/pkg/util"
_ "github.com/grafana/loki/pkg/util/build"
"github.com/grafana/loki/pkg/util/cfg"
util_log "github.com/grafana/loki/pkg/util/log"
)

func init() {
Expand Down Expand Up @@ -81,7 +81,7 @@ func main() {
fmt.Println("Invalid log level")
os.Exit(1)
}
util_log.InitLogger(&config.ServerConfig.Config)
util_log.InitLogger(&config.ServerConfig.Config, prometheus.DefaultRegisterer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)


// Use Stderr instead of files for the klog.
klog.SetOutput(os.Stderr)
Expand All @@ -97,20 +97,20 @@ func main() {
}

if config.printConfig {
err := logutil.PrintConfig(os.Stderr, &config)
err := util.PrintConfig(os.Stderr, &config)
if err != nil {
level.Error(util_log.Logger).Log("msg", "failed to print config to stderr", "err", err.Error())
}
}

if config.logConfig {
err := logutil.LogConfig(&config)
err := util.LogConfig(&config)
if err != nil {
level.Error(util_log.Logger).Log("msg", "failed to log config object", "err", err.Error())
}
}

p, err := promtail.New(config.Config, config.dryRun)
p, err := promtail.New(config.Config, config.dryRun, prometheus.DefaultRegisterer)
if err != nil {
level.Error(util_log.Logger).Log("msg", "error creating promtail", "error", err)
os.Exit(1)
Expand Down
5 changes: 3 additions & 2 deletions clients/pkg/logentry/stages/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
ww "github.com/weaveworks/common/server"

util_log "github.com/grafana/loki/pkg/util/log"
)

// Not all these are tested but are here to make sure the different types marshal without error
Expand Down Expand Up @@ -39,7 +40,7 @@ func Test_dropStage_Process(t *testing.T) {
// Enable debug logging
cfg := &ww.Config{}
require.Nil(t, cfg.LogLevel.Set("debug"))
util_log.InitLogger(cfg)
util_log.InitLogger(cfg, nil)
Debug = true

tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"

util_log "github.com/grafana/loki/pkg/util/log"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testJSONYamlSingleStageWithoutSource = `
Expand Down
5 changes: 3 additions & 2 deletions clients/pkg/logentry/stages/labelallow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
ww "github.com/weaveworks/common/server"

util_log "github.com/grafana/loki/pkg/util/log"
)

func Test_addLabelStage_Process(t *testing.T) {
// Enable debug logging
cfg := &ww.Config{}
require.Nil(t, cfg.LogLevel.Set("debug"))
util_log.InitLogger(cfg)
util_log.InitLogger(cfg, nil)
Debug = true

tests := []struct {
Expand Down
5 changes: 3 additions & 2 deletions clients/pkg/logentry/stages/labeldrop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
ww "github.com/weaveworks/common/server"

util_log "github.com/grafana/loki/pkg/util/log"
)

func Test_dropLabelStage_Process(t *testing.T) {
// Enable debug logging
cfg := &ww.Config{}
require.Nil(t, cfg.LogLevel.Set("debug"))
util_log.InitLogger(cfg)
util_log.InitLogger(cfg, nil)
Debug = true

tests := []struct {
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testLabelsYaml = `
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/logfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testLogfmtYamlSingleStageWithoutSource = `
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testMatchYaml = `
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -15,6 +14,8 @@ import (
"github.com/stretchr/testify/assert"

"github.com/grafana/loki/clients/pkg/logentry/metric"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testMetricYaml = `
Expand Down
8 changes: 4 additions & 4 deletions clients/pkg/logentry/stages/multiline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
ww "github.com/weaveworks/common/server"

"github.com/grafana/loki/clients/pkg/promtail/api"

"github.com/grafana/loki/pkg/logproto"
util_log "github.com/grafana/loki/pkg/util/log"
)

func Test_multilineStage_Process(t *testing.T) {
// Enable debug logging
cfg := &ww.Config{}
require.Nil(t, cfg.LogLevel.Set("debug"))
util_log.InitLogger(cfg)
util_log.InitLogger(cfg, nil)
Debug = true

mcfg := &MultilineConfig{Expression: ptrFromString("^START"), MaxWaitTime: ptrFromString("3s")}
Expand Down Expand Up @@ -52,7 +52,7 @@ func Test_multilineStage_MultiStreams(t *testing.T) {
// Enable debug logging
cfg := &ww.Config{}
require.Nil(t, cfg.LogLevel.Set("debug"))
util_log.InitLogger(cfg)
util_log.InitLogger(cfg, nil)
Debug = true

mcfg := &MultilineConfig{Expression: ptrFromString("^START"), MaxWaitTime: ptrFromString("3s")}
Expand Down Expand Up @@ -97,7 +97,7 @@ func Test_multilineStage_MaxWaitTime(t *testing.T) {
// Enable debug logging
cfg := &ww.Config{}
require.Nil(t, cfg.LogLevel.Set("debug"))
util_log.InitLogger(cfg)
util_log.InitLogger(cfg, nil)
Debug = true

maxWait := 2 * time.Second
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testOutputYaml = `
Expand Down
4 changes: 2 additions & 2 deletions clients/pkg/logentry/stages/pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
json "github.com/json-iterator/go"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
Expand All @@ -16,6 +15,7 @@ import (

"github.com/grafana/loki/pkg/logproto"
"github.com/grafana/loki/pkg/logqlmodel"
util_log "github.com/grafana/loki/pkg/util/log"
)

// Not all these are tested but are here to make sure the different types marshal without error
Expand Down Expand Up @@ -105,7 +105,7 @@ func Test_packStage_Run(t *testing.T) {
// Enable debug logging
cfg := &ww.Config{}
require.Nil(t, cfg.LogLevel.Set("debug"))
util_log.InitLogger(cfg)
util_log.InitLogger(cfg, nil)
Debug = true

tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/grafana/loki/clients/pkg/promtail/client/fake"

"github.com/grafana/loki/pkg/logproto"
util_log "github.com/grafana/loki/pkg/util/log"
)

var (
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/go-kit/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testRegexYamlSingleStageWithoutSource = `
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"

util_log "github.com/grafana/loki/pkg/util/log"
)

var testReplaceYamlSingleStageWithoutSource = `
Expand Down
3 changes: 2 additions & 1 deletion clients/pkg/logentry/stages/static_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"testing"
"time"

util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"

util_log "github.com/grafana/loki/pkg/util/log"
)

func Test_staticLabelStage_Process(t *testing.T) {
Expand Down
Loading