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

fix(deps): update module gopkg.in/yaml.v2 to v3 #15038

Closed
wants to merge 7 commits into from
Closed
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
24 changes: 20 additions & 4 deletions clients/cmd/docker-driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"fmt"
"io"
"net/url"
"os"
"strconv"
Expand All @@ -17,7 +18,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/logentry/stages"
"github.com/grafana/loki/v3/clients/pkg/promtail/client"
Expand Down Expand Up @@ -319,7 +320,11 @@ func parsePipeline(logCtx logger.Info) (PipelineConfig, error) {
}
}
if okString {
if err := yaml.UnmarshalStrict([]byte(pipelineString), &pipeline.PipelineStages); err != nil {
decoder := yaml.NewDecoder(bytes.NewReader([]byte(pipelineString)))
decoder.KnownFields(true)

err := decoder.Decode(&pipeline)
if err != nil && !errors.Is(err, io.EOF) {
return pipeline, err
}
}
Expand Down Expand Up @@ -363,7 +368,11 @@ func parseInt(key string, logCtx logger.Info, set func(i int)) error {

func relabelConfig(config string, lbs model.LabelSet) (model.LabelSet, error) {
relabelConfig := make([]*relabel.Config, 0)
if err := yaml.UnmarshalStrict([]byte(config), &relabelConfig); err != nil {
decoder := yaml.NewDecoder(bytes.NewReader([]byte(config)))
decoder.KnownFields(true)

err := decoder.Decode(&relabelConfig)
if err != nil && !errors.Is(err, io.EOF) {
return nil, err
}
relabed, _ := relabel.Process(labels.FromMap(util.ModelLabelSetToMap(lbs)), relabelConfig...)
Expand All @@ -389,5 +398,12 @@ func loadConfig(filename string, cfg interface{}) error {
return errors.Wrap(err, "Error reading config file")
}

return yaml.UnmarshalStrict(buf, cfg)
decoder := yaml.NewDecoder(bytes.NewReader(buf))
decoder.KnownFields(true)

err = decoder.Decode(cfg)
if err != nil && !errors.Is(err, io.EOF) {
return err
}
return nil
}
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

util_log "github.com/grafana/loki/v3/pkg/util/log"
)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/logfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

util_log "github.com/grafana/loki/v3/pkg/util/log"
)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

util_log "github.com/grafana/loki/v3/pkg/util/log"
)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

util_log "github.com/grafana/loki/v3/pkg/util/log"
)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/logentry/stages/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/promtail/api"
)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/prometheus/common/config"
"github.com/stretchr/testify/require"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var clientConfig = Config{}
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/client/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/fatih/color"
"github.com/go-kit/log"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/promtail/api"
"github.com/grafana/loki/v3/clients/pkg/promtail/limit"
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/promtail/client"
"github.com/grafana/loki/v3/clients/pkg/promtail/limit"
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
dskitflagext "github.com/grafana/dskit/flagext"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/promtail/client"

Expand Down
12 changes: 9 additions & 3 deletions clients/pkg/promtail/positions/positions.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package positions

import (
"bytes"
"errors"
"flag"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
Expand All @@ -12,7 +15,7 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
yaml "gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v3"
)

const (
Expand Down Expand Up @@ -224,8 +227,11 @@ func readPositionsFile(cfg Config, logger log.Logger) (map[string]string, error)
}

var p File
err = yaml.UnmarshalStrict(buf, &p)
if err != nil {
decoder := yaml.NewDecoder(bytes.NewReader(buf))
decoder.KnownFields(true)

err = decoder.Decode(p)
if err != nil && !errors.Is(err, io.EOF) {
// return empty if cfg option enabled
if cfg.IgnoreInvalidYaml {
level.Debug(logger).Log("msg", "ignoring invalid positions file", "file", cleanfn, "error", err)
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/positions/write_positions_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"path/filepath"

renameio "github.com/google/renameio/v2"
yaml "gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v3"
)

func writePositionFile(filename string, positions map[string]string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"path/filepath"

yaml "gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v3"
)

// writePositionFile is a fall back for Windows because renameio does not support Windows.
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/scrapeconfig/scrapeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/prometheus/prometheus/discovery/kubernetes"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

// todo add full example.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/promtail/client/fake"
"github.com/grafana/loki/v3/clients/pkg/promtail/positions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/logentry/stages"
"github.com/grafana/loki/v3/clients/pkg/promtail/api"
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/syslog/syslogtarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/clients/pkg/promtail/client/fake"
"github.com/grafana/loki/v3/clients/pkg/promtail/scrapeconfig"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ require (
golang.org/x/time v0.8.0
google.golang.org/api v0.209.0
google.golang.org/grpc v1.68.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/klog/v2 v2.130.1
)
Expand Down Expand Up @@ -147,6 +146,7 @@ require (
golang.org/x/oauth2 v0.24.0
golang.org/x/text v0.20.0
google.golang.org/protobuf v1.35.2
gopkg.in/yaml.v2 v2.4.0
gotest.tools v2.2.0+incompatible
k8s.io/apimachinery v0.31.3
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078
Expand Down
12 changes: 6 additions & 6 deletions integration/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import (
"github.com/grafana/dskit/multierror"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/integration/util"

"github.com/grafana/loki/v3/pkg/loki"
"github.com/grafana/loki/v3/pkg/storage"
"github.com/grafana/loki/v3/pkg/storage/config"
"github.com/grafana/loki/v3/pkg/util/cfg"
util_log "github.com/grafana/loki/v3/pkg/util/log"
"github.com/grafana/loki/v3/pkg/validation"
Expand Down Expand Up @@ -363,8 +362,9 @@ func (c *Component) writeConfig() error {
func (c *Component) MergedConfig() ([]byte, error) {
var sb bytes.Buffer

periodStart := config.DayTime{Time: c.cluster.initedAt.Add(-24 * time.Hour)}
additionalPeriodStart := config.DayTime{Time: c.cluster.initedAt.Add(-7 * 24 * time.Hour)}
// Quote the time strings to ensure they're treated as strings in YAML 1.2
periodStart := fmt.Sprintf("%q", time.Unix(int64(c.cluster.initedAt)/1000, 0).Format("2006-01-02"))
additionalPeriodStart := fmt.Sprintf("%q", time.Unix(int64(c.cluster.initedAt)/1000, 0).Add(-6*24*time.Hour).Format("2006-01-02"))

if err := configTemplate.Execute(&sb, map[string]interface{}{
"dataPath": c.dataPath,
Expand All @@ -385,8 +385,8 @@ func (c *Component) MergedConfig() ([]byte, error) {
var buf bytes.Buffer
if err := template.Must(template.New("schema").Parse(periodCfg)).
Execute(&buf, map[string]interface{}{
"curPeriodStart": periodStart.String(),
"additionalPeriodStart": additionalPeriodStart.String(),
"curPeriodStart": periodStart,
"additionalPeriodStart": additionalPeriodStart,
"schemaVer": c.cluster.schemaVer,
}); err != nil {
return nil, errors.New("error building schema_config")
Expand Down
2 changes: 1 addition & 1 deletion integration/util/merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"dario.cat/mergo"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

// YAMLMerger takes a set of given YAML fragments and merges them into a single YAML document.
Expand Down
4 changes: 2 additions & 2 deletions pkg/logcli/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/grafana/dskit/user"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/pkg/logcli/client"
"github.com/grafana/loki/v3/pkg/logcli/output"
Expand Down Expand Up @@ -567,7 +567,7 @@ func LoadSchemaUsingObjectClient(oc chunk.ObjectClient, name string) (*config.Sc
defer rdr.Close()

decoder := yaml.NewDecoder(rdr)
decoder.SetStrict(true)
decoder.KnownFields(true)
section := schemaConfigSection{}
err = decoder.Decode(&section)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/loghttp/push/otlp_config_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package push

import (
"bytes"
"testing"

"github.com/grafana/dskit/flagext"
"github.com/prometheus/prometheus/model/relabel"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

var defaultGlobalOTLPConfig = GlobalOTLPConfig{}
Expand Down Expand Up @@ -153,7 +154,10 @@ log_attributes:
} {
t.Run(tc.name, func(t *testing.T) {
cfg := OTLPConfig{}
err := yaml.UnmarshalStrict(tc.yamlConfig, &cfg)
decoder := yaml.NewDecoder(bytes.NewReader(tc.yamlConfig))
decoder.KnownFields(true)

err := decoder.Decode(&cfg)
if tc.expectedErr != nil {
require.ErrorIs(t, err, tc.expectedErr)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/loki/config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"reflect"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)

func yamlMarshalUnmarshal(in interface{}) (map[interface{}]interface{}, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/loki/runtime_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/go-kit/log/level"
"github.com/grafana/dskit/kv"
"github.com/grafana/dskit/runtimeconfig"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/pkg/runtime"
util_log "github.com/grafana/loki/v3/pkg/util/log"
Expand Down Expand Up @@ -42,7 +42,7 @@ func loadRuntimeConfig(r io.Reader) (interface{}, error) {
overrides := &runtimeConfigValues{}

decoder := yaml.NewDecoder(r)
decoder.SetStrict(true)
decoder.KnownFields(true)
if err := decoder.Decode(&overrides); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/limits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/prometheus/prometheus/promql"
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/pkg/logproto"
"github.com/grafana/loki/v3/pkg/logql/syntax"
Expand Down
2 changes: 1 addition & 1 deletion pkg/querier/queryrange/split_by_interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/loki/v3/pkg/loghttp"
"github.com/grafana/loki/v3/pkg/logproto"
Expand Down
2 changes: 1 addition & 1 deletion pkg/ruler/base/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/atomic"
"google.golang.org/grpc"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/grafana/dskit/tenant"

Expand Down
2 changes: 1 addition & 1 deletion pkg/ruler/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/pkg/errors"
"github.com/prometheus/prometheus/config"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

ruler "github.com/grafana/loki/v3/pkg/ruler/base"
"github.com/grafana/loki/v3/pkg/ruler/storage/cleaner"
Expand Down
Loading
Loading