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]: enable gofumpt linter for pkg #36348

Merged
merged 1 commit into from
Nov 13, 2024
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
6 changes: 3 additions & 3 deletions pkg/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func writeMetrics(filePath string, metrics pmetric.Metrics, opts ...WriteMetrics
if err != nil {
return err
}
return os.WriteFile(filePath, b, 0600)
return os.WriteFile(filePath, b, 0o600)
}

// ReadLogs reads a plog.Logs from the specified YAML or JSON file.
Expand Down Expand Up @@ -137,7 +137,7 @@ func writeLogs(filePath string, logs plog.Logs) error {
if err := enc.Encode(jsonVal); err != nil {
return err
}
return os.WriteFile(filePath, b.Bytes(), 0600)
return os.WriteFile(filePath, b.Bytes(), 0o600)
}

// ReadTraces reads a ptrace.Traces from the specified YAML or JSON file.
Expand Down Expand Up @@ -188,5 +188,5 @@ func writeTraces(filePath string, traces ptrace.Traces) error {
if err := enc.Encode(jsonVal); err != nil {
return err
}
return os.WriteFile(filePath, b.Bytes(), 0600)
return os.WriteFile(filePath, b.Bytes(), 0o600)
}
2 changes: 1 addition & 1 deletion pkg/golden/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func testMetrics() pmetric.MetricSlice {

dp = dps.AppendEmpty()
attributes = pcommon.NewMap()
setDPDoubleVal(dp, 2, attributes, time.Date(1997, 07, 27, 1, 1, 1, 1, &time.Location{}))
setDPDoubleVal(dp, 2, attributes, time.Date(1997, 0o7, 27, 1, 1, 1, 1, &time.Location{}))
Copy link
Member

Choose a reason for hiding this comment

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

I like how the formatter has exposed that the "07" is actually interpreted in octal.

return slice
}

Expand Down
68 changes: 42 additions & 26 deletions pkg/ottl/boolean_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func Test_newComparisonEvaluator(t *testing.T) {

JanFirst2023 := time.Date(2023, 1, 1, 0, 0, 0, 0, time.Local)

var tests = []struct {
tests := []struct {
name string
l any
r any
Expand Down Expand Up @@ -159,16 +159,16 @@ func Test_newComparisonEvaluator(t *testing.T) {
{name: "compare not greater than equal to durations", l: "dur1", r: "dur2", op: ">=", want: false, item: map[string]time.Duration{"dur1": oneMillisecond, "dur2": threeSeconds}},
{name: "compare equal times", l: "time1", r: "time2", op: "==", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": JanFirst2023}},
{name: "compare unequal times", l: "time1", r: "time2", op: "==", want: false, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2023, 1, 2, 0, 0, 0, 0, time.Local)}},
{name: "compare for not equal times", l: "time1", r: "time2", op: "!=", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2002, 11, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare for equal times using not equal", l: "time1", r: "time2", op: "!=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 11, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2002, 11, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare less than times", l: "time1", r: "time2", op: "<", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2023, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare not less than times", l: "time1", r: "time2", op: "<", want: false, item: map[string]time.Time{"time1": time.Date(2023, 6, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2023, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare less than equal to times", l: "time1", r: "time2", op: "<=", want: true, item: map[string]time.Time{"time1": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare not less than equal to times", l: "time1", r: "time2", op: "<=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(1999, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare not greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare greater than w/ times", l: "time1", r: "time2", op: ">", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare not greater than w/ times", l: "time1", r: "time2", op: ">", want: false, item: map[string]time.Time{"time1": time.Date(2002, 3, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
{name: "compare for not equal times", l: "time1", r: "time2", op: "!=", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2002, 11, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare for equal times using not equal", l: "time1", r: "time2", op: "!=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 11, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2002, 11, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare less than times", l: "time1", r: "time2", op: "<", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2023, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare not less than times", l: "time1", r: "time2", op: "<", want: false, item: map[string]time.Time{"time1": time.Date(2023, 6, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2023, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare less than equal to times", l: "time1", r: "time2", op: "<=", want: true, item: map[string]time.Time{"time1": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare not less than equal to times", l: "time1", r: "time2", op: "<=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(1999, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare not greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare greater than w/ times", l: "time1", r: "time2", op: ">", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
{name: "compare not greater than w/ times", l: "time1", r: "time2", op: ">", want: false, item: map[string]time.Time{"time1": time.Date(2002, 3, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -220,6 +220,7 @@ func True() (ExprFunc[any], error) {
return true, nil
}, nil
}

func False() (ExprFunc[any], error) {
return func(_ context.Context, _ any) (any, error) {
return false, nil
Expand All @@ -243,7 +244,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
want bool
expr *booleanExpression
}{
{"a", false,
{
"a", false,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -264,7 +266,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"b", true,
{
"b", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -285,7 +288,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"c", false,
{
"c", false,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand Down Expand Up @@ -314,7 +318,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"d", true,
{
"d", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -337,7 +342,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"e", true,
{
"e", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -360,7 +366,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"f", false,
{
"f", false,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -383,7 +390,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"g", true,
{
"g", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand Down Expand Up @@ -416,7 +424,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"h", true,
{
"h", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand Down Expand Up @@ -455,7 +464,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"i", true,
{
"i", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -467,7 +477,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"j", false,
{
"j", false,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -479,7 +490,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"k", true,
{
"k", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -497,7 +509,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"l", false,
{
"l", false,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand Down Expand Up @@ -537,7 +550,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"m", false,
{
"m", false,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand Down Expand Up @@ -573,7 +587,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"n", true,
{
"n", true,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand All @@ -586,7 +601,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
},
},
},
{"o", false,
{
"o", false,
&booleanExpression{
Left: &term{
Left: &booleanValue{
Expand Down
22 changes: 10 additions & 12 deletions pkg/ottl/context_inferrer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ package ottl // import "github.com/open-telemetry/opentelemetry-collector-contri

import "math"

var (
defaultContextInferPriority = []string{
"log",
"metric",
"datapoint",
"spanevent",
"span",
"resource",
"scope",
"instrumentation_scope",
}
)
var defaultContextInferPriority = []string{
"log",
"metric",
"datapoint",
"spanevent",
"span",
"resource",
"scope",
"instrumentation_scope",
}

// contextInferrer is an interface used to infer the OTTL context from statements paths.
type contextInferrer interface {
Expand Down
8 changes: 5 additions & 3 deletions pkg/ottl/contexts/ottldatapoint/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ const (
contextName = "DataPoint"
)

var _ internal.ResourceContext = (*TransformContext)(nil)
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
var (
_ internal.ResourceContext = (*TransformContext)(nil)
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
)

type TransformContext struct {
dataPoint any
Expand Down
8 changes: 5 additions & 3 deletions pkg/ottl/contexts/ottllog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ const (
contextName = "Log"
)

var _ internal.ResourceContext = (*TransformContext)(nil)
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
var (
_ internal.ResourceContext = (*TransformContext)(nil)
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
)

type TransformContext struct {
logRecord plog.LogRecord
Expand Down
8 changes: 5 additions & 3 deletions pkg/ottl/contexts/ottlmetric/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal"
)

var _ internal.ResourceContext = TransformContext{}
var _ internal.InstrumentationScopeContext = TransformContext{}
var _ internal.MetricContext = TransformContext{}
var (
_ internal.ResourceContext = TransformContext{}
_ internal.InstrumentationScopeContext = TransformContext{}
_ internal.MetricContext = TransformContext{}
)

type TransformContext struct {
metric pmetric.Metric
Expand Down
6 changes: 4 additions & 2 deletions pkg/ottl/contexts/ottlresource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
)

var _ internal.ResourceContext = (*TransformContext)(nil)
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
var (
_ internal.ResourceContext = (*TransformContext)(nil)
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
)

type TransformContext struct {
resource pcommon.Resource
Expand Down
8 changes: 5 additions & 3 deletions pkg/ottl/contexts/ottlscope/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
)

var _ internal.ResourceContext = (*TransformContext)(nil)
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
var (
_ internal.ResourceContext = (*TransformContext)(nil)
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
)

type TransformContext struct {
instrumentationScope pcommon.InstrumentationScope
Expand Down
8 changes: 5 additions & 3 deletions pkg/ottl/contexts/ottlspan/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
)

var _ internal.ResourceContext = (*TransformContext)(nil)
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
var (
_ internal.ResourceContext = (*TransformContext)(nil)
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
)

type TransformContext struct {
span ptrace.Span
Expand Down
Loading