Files
zeekayandHanzo Dev c16ed9fe26 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 02:34:35 -07:00

146 lines
4.1 KiB
Go

// Copyright The OpenTelemetry 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.
package grok
import (
"path/filepath"
"testing"
o11ystanzaentry "github.com/hanzoai/otel-collector/processor/o11ylogspipelineprocessor/stanza/entry"
o11ystanzahelper "github.com/hanzoai/otel-collector/processor/o11ylogspipelineprocessor/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/operatortest"
)
func TestParserGoldenConfig(t *testing.T) {
operatortest.ConfigUnmarshalTests{
DefaultConfig: NewConfig(),
TestsFile: filepath.Join(".", "testdata", "config.yaml"),
Tests: []operatortest.ConfigUnmarshalTest{
{
Name: "default",
Expect: NewConfig(),
},
{
Name: "cache",
Expect: func() *Config {
cfg := NewConfig()
cfg.Cache.Size = 50
return cfg
}(),
},
{
Name: "parse_from_simple",
Expect: func() *Config {
cfg := NewConfig()
cfg.ParseFrom = o11ystanzaentry.Field{FieldInterface: o11ystanzaentry.NewBodyField("from")}
return cfg
}(),
},
{
Name: "parse_to_simple",
Expect: func() *Config {
cfg := NewConfig()
cfg.ParseTo = o11ystanzaentry.RootableField{FieldInterface: o11ystanzaentry.NewBodyField("log")}
return cfg
}(),
},
{
Name: "on_error_drop",
Expect: func() *Config {
cfg := NewConfig()
cfg.OnError = "drop"
return cfg
}(),
},
{
Name: "timestamp",
Expect: func() *Config {
cfg := NewConfig()
parseField := o11ystanzaentry.Field{FieldInterface: o11ystanzaentry.NewBodyField("timestamp_field")}
newTime := o11ystanzahelper.TimeParser{
LayoutType: "strptime",
Layout: "%Y-%m-%d",
ParseFrom: &parseField,
}
cfg.TimeParser = &newTime
return cfg
}(),
},
{
Name: "severity",
Expect: func() *Config {
cfg := NewConfig()
parseField := o11ystanzaentry.Field{FieldInterface: o11ystanzaentry.NewBodyField("severity_field")}
severityParser := o11ystanzahelper.NewSeverityConfig()
severityParser.ParseFrom = &parseField
mapping := map[string]any{
"critical": "5xx",
"error": "4xx",
"info": "3xx",
"debug": "2xx",
}
severityParser.Mapping = mapping
cfg.SeverityConfig = &severityParser
return cfg
}(),
},
{
Name: "pattern",
Expect: func() *Config {
cfg := NewConfig()
cfg.Pattern = "a=%{NOTSPACE:data}"
return cfg
}(),
},
{
Name: "scope_name",
Expect: func() *Config {
cfg := NewConfig()
cfg.Pattern = "a=%{NOTSPACE:data}"
parseField := o11ystanzaentry.Field{FieldInterface: o11ystanzaentry.NewBodyField("logger_name_field")}
loggerNameParser := o11ystanzahelper.NewScopeNameParser()
loggerNameParser.ParseFrom = parseField
cfg.ScopeNameParser = &loggerNameParser
return cfg
}(),
},
{
Name: "parse_to_attributes",
Expect: func() *Config {
p := NewConfig()
p.ParseTo = o11ystanzaentry.RootableField{FieldInterface: entry.NewAttributeField()}
return p
}(),
},
{
Name: "parse_to_body",
Expect: func() *Config {
p := NewConfig()
p.ParseTo = o11ystanzaentry.RootableField{FieldInterface: o11ystanzaentry.NewBodyField()}
return p
}(),
},
{
Name: "parse_to_resource",
Expect: func() *Config {
p := NewConfig()
p.ParseTo = o11ystanzaentry.RootableField{FieldInterface: entry.NewResourceField()}
return p
}(),
},
},
}.Run(t)
}