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

Feat: logspipelineprocessor: read/address body fields in pipeline operators directly if body is json #416

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6a6dd23
chore: signozlogspipelineprocessor: get test started for JSON body fi…
raj-k-singh Sep 26, 2024
c2ffb39
chore: bring over a copy of stanza entry.Field to enhance body field
raj-k-singh Sep 27, 2024
05b017e
chore: use signozstanzaentry.Field in add operator
raj-k-singh Sep 27, 2024
d7918ed
chore: bring in copies of body_field.go and body_field_test.go from s…
raj-k-singh Sep 27, 2024
fc9f142
chore: stash current state of work
raj-k-singh Sep 27, 2024
8be1e7a
chore: experiment with caching parsed body json into a temp entry att…
raj-k-singh Oct 4, 2024
5c411c2
chore: get all tests passing
raj-k-singh Oct 4, 2024
d550ca0
chore: go mod tidy
raj-k-singh Oct 4, 2024
823ea15
chore: some cleanup
raj-k-singh Oct 7, 2024
b3c0f35
chore: refactor signozlogspipeline processor test a little
raj-k-singh Oct 7, 2024
a0f502b
chore: bring in copies of needed stanza helpers from otel collector c…
raj-k-singh Oct 7, 2024
1db48d6
feat: use signozstanzaentry.Field in grok parser to enable parsing ou…
raj-k-singh Oct 7, 2024
7cbf667
chore: add test validating regex parser can read from JSON body field
raj-k-singh Oct 7, 2024
f01065a
chore: update regex parser to parse from JSON body fields
raj-k-singh Oct 7, 2024
6241820
chore: update JSON parser to read from JSON body
raj-k-singh Oct 7, 2024
a3b86c7
chore: update time parser to parse from json body field
raj-k-singh Oct 7, 2024
93d14ad
chore: update sev parser to parse from json body field
raj-k-singh Oct 7, 2024
bc27b5d
chore: update trace parser to parse from json body field
raj-k-singh Oct 7, 2024
e78134b
chore: also validate spanId parsing from JSON body
raj-k-singh Oct 8, 2024
3fae4f0
chore: some cleanups
raj-k-singh Oct 8, 2024
0aeed7a
Merge branch 'main' into feat/logspipelineprocessor-address-body-fiel…
raj-k-singh Oct 10, 2024
e3feb55
chore: signozlogspipelineprocessor: use jsoniter for parsing body JSON
raj-k-singh Oct 10, 2024
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
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/apache/thrift v0.20.0
github.com/aws/aws-sdk-go v1.53.11
github.com/cenkalti/backoff/v4 v4.3.0
github.com/expr-lang/expr v1.16.9
github.com/gogo/protobuf v1.3.2
github.com/golang-migrate/migrate/v4 v4.15.1
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
Expand Down Expand Up @@ -181,6 +182,7 @@ require (
google.golang.org/grpc v1.64.1
google.golang.org/protobuf v1.34.1
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.2.0
)

require (
Expand Down Expand Up @@ -274,7 +276,6 @@ require (
github.com/envoyproxy/go-control-plane v0.12.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.0.4 // indirect
github.com/euank/go-kmsg-parser v2.0.0+incompatible // indirect
github.com/expr-lang/expr v1.16.9 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-faster/city v1.0.1 // indirect
Expand Down Expand Up @@ -497,7 +498,7 @@ require (
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/json-iterator/go v1.1.12
github.com/klauspost/compress v1.17.8 // indirect
github.com/leodido/ragel-machinery v0.0.0-20190525184631-5f46317e436b // indirect
github.com/leoluk/perflib_exporter v0.2.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns=
Expand Down
25 changes: 13 additions & 12 deletions pkg/parser/grok/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
"path/filepath"
"testing"

signozstanzaentry "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/entry"
signozstanzahelper "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/operatortest"
)

Expand All @@ -43,15 +44,15 @@ func TestParserGoldenConfig(t *testing.T) {
Name: "parse_from_simple",
Expect: func() *Config {
cfg := NewConfig()
cfg.ParseFrom = entry.NewBodyField("from")
cfg.ParseFrom = signozstanzaentry.Field{signozstanzaentry.NewBodyField("from")}
return cfg
}(),
},
{
Name: "parse_to_simple",
Expect: func() *Config {
cfg := NewConfig()
cfg.ParseTo = entry.RootableField{Field: entry.NewBodyField("log")}
cfg.ParseTo = signozstanzaentry.RootableField{Field: signozstanzaentry.Field{signozstanzaentry.NewBodyField("log")}}
return cfg
}(),
},
Expand All @@ -67,8 +68,8 @@ func TestParserGoldenConfig(t *testing.T) {
Name: "timestamp",
Expect: func() *Config {
cfg := NewConfig()
parseField := entry.NewBodyField("timestamp_field")
newTime := helper.TimeParser{
parseField := signozstanzaentry.Field{signozstanzaentry.NewBodyField("timestamp_field")}
newTime := signozstanzahelper.TimeParser{
LayoutType: "strptime",
Layout: "%Y-%m-%d",
ParseFrom: &parseField,
Expand All @@ -81,8 +82,8 @@ func TestParserGoldenConfig(t *testing.T) {
Name: "severity",
Expect: func() *Config {
cfg := NewConfig()
parseField := entry.NewBodyField("severity_field")
severityParser := helper.NewSeverityConfig()
parseField := signozstanzaentry.Field{signozstanzaentry.NewBodyField("severity_field")}
severityParser := signozstanzahelper.NewSeverityConfig()
severityParser.ParseFrom = &parseField
mapping := map[string]interface{}{
"critical": "5xx",
Expand All @@ -108,8 +109,8 @@ func TestParserGoldenConfig(t *testing.T) {
Expect: func() *Config {
cfg := NewConfig()
cfg.Pattern = "a=%{NOTSPACE:data}"
parseField := entry.NewBodyField("logger_name_field")
loggerNameParser := helper.NewScopeNameParser()
parseField := signozstanzaentry.Field{signozstanzaentry.NewBodyField("logger_name_field")}
loggerNameParser := signozstanzahelper.NewScopeNameParser()
loggerNameParser.ParseFrom = parseField
cfg.ScopeNameParser = &loggerNameParser
return cfg
Expand All @@ -119,23 +120,23 @@ func TestParserGoldenConfig(t *testing.T) {
Name: "parse_to_attributes",
Expect: func() *Config {
p := NewConfig()
p.ParseTo = entry.RootableField{Field: entry.NewAttributeField()}
p.ParseTo = signozstanzaentry.RootableField{Field: signozstanzaentry.Field{entry.NewAttributeField()}}
return p
}(),
},
{
Name: "parse_to_body",
Expect: func() *Config {
p := NewConfig()
p.ParseTo = entry.RootableField{Field: entry.NewBodyField()}
p.ParseTo = signozstanzaentry.RootableField{Field: signozstanzaentry.Field{signozstanzaentry.NewBodyField()}}
return p
}(),
},
{
Name: "parse_to_resource",
Expect: func() *Config {
p := NewConfig()
p.ParseTo = entry.RootableField{Field: entry.NewResourceField()}
p.ParseTo = signozstanzaentry.RootableField{Field: signozstanzaentry.Field{entry.NewResourceField()}}
return p
}(),
},
Expand Down
8 changes: 4 additions & 4 deletions pkg/parser/grok/grok.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"

signozlogspipelinestanzaoperator "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/operator"
signozstanzahelper "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/operator/helper"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"github.com/vjeantet/grok"
"go.opentelemetry.io/collector/component"
)
Expand All @@ -27,13 +27,13 @@ func NewConfig() *Config {
// NewConfigWithID creates a new grok parser config with default values
func NewConfigWithID(operatorID string) *Config {
return &Config{
ParserConfig: helper.NewParserConfig(operatorID, operatorType),
ParserConfig: signozstanzahelper.NewParserConfig(operatorID, operatorType),
}
}

// Config is the configuration of a grok parser operator.
type Config struct {
helper.ParserConfig `mapstructure:",squash"`
signozstanzahelper.ParserConfig `mapstructure:",squash"`

// grok pattern
Pattern string `mapstructure:"pattern"`
Expand Down Expand Up @@ -102,7 +102,7 @@ func (c Config) Build(set component.TelemetrySettings) (operator.Operator, error

// Parser is an operator that parses grok in an entry.
type Parser struct {
helper.ParserOperator
signozstanzahelper.ParserOperator
grok *grok.Grok
pattern string
cache cache
Expand Down
11 changes: 6 additions & 5 deletions processor/signozlogspipelineprocessor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"go.opentelemetry.io/collector/confmap/confmaptest"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"

signozlogspipelinestanzaadapter "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/adapter"
signozstanzaentry "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/entry"
signozlogspipelinestanzaoperator "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/operator"
signozstanzahelper "github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/operator/helper"
"github.com/SigNoz/signoz-otel-collector/processor/signozlogspipelineprocessor/stanza/operator/operators/regex"
)

Expand All @@ -31,12 +32,12 @@ func TestLoadConfig(t *testing.T) {
Builder: func() *regex.Config {
cfg := regex.NewConfig()
cfg.Regex = "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$"
sevField := entry.NewAttributeField("sev")
sevCfg := helper.NewSeverityConfig()
sevField := signozstanzaentry.Field{entry.NewAttributeField("sev")}
sevCfg := signozstanzahelper.NewSeverityConfig()
sevCfg.ParseFrom = &sevField
cfg.SeverityConfig = &sevCfg
timeField := entry.NewAttributeField("time")
timeCfg := helper.NewTimeParser()
timeField := signozstanzaentry.Field{entry.NewAttributeField("time")}
timeCfg := signozstanzahelper.NewTimeParser()
timeCfg.Layout = "%Y-%m-%d %H:%M:%S"
timeCfg.ParseFrom = &timeField
cfg.TimeParser = &timeCfg
Expand Down
Loading