-
Notifications
You must be signed in to change notification settings - Fork 2
[processor/sllogformat] skip with warning for empty log lines #242
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ package sllogformatprocessor // import "github.com/open-telemetry/opentelemetry- | |
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "regexp" | ||
| "strconv" | ||
| "strings" | ||
|
|
@@ -27,6 +28,8 @@ import ( | |
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| var skipLine = errors.New("skipping line: message body contains no printable characters; log line is empty. ") | ||
|
||
|
|
||
| type StreamTokenReq struct { | ||
| Stream string `json:"stream"` | ||
| Logbasename string `json:"logbasename"` | ||
|
|
@@ -388,7 +391,8 @@ type ConfigResult struct { | |
|
|
||
| func (c *Config) MatchProfile(log *zap.Logger, rl plog.ResourceLogs, ils plog.ScopeLogs, lr plog.LogRecord) (*ConfigResult, *StreamTokenReq, error) { | ||
| var id, ret string | ||
| for _, profile := range c.Profiles { | ||
| reasons := []string{} | ||
| for idx, profile := range c.Profiles { | ||
| req := newStreamTokenReq() | ||
| gen := ConfigResult{} | ||
| parser := Parser{ | ||
|
|
@@ -399,16 +403,19 @@ func (c *Config) MatchProfile(log *zap.Logger, rl plog.ResourceLogs, ils plog.Sc | |
| } | ||
| id, gen.ServiceGroup = parser.EvalElem(profile.ServiceGroup) | ||
| if gen.ServiceGroup == "" { | ||
| reasons = append(reasons, "service_group") | ||
| continue | ||
|
||
| } | ||
| req.Ids[id] = gen.ServiceGroup | ||
| id, gen.Host = parser.EvalElem(profile.Host) | ||
| if gen.Host == "" { | ||
| reasons = append(reasons, "host") | ||
| continue | ||
| } | ||
| req.Ids[id] = gen.Host | ||
| id, gen.Logbasename = parser.EvalElem(profile.Logbasename) | ||
| if gen.Logbasename == "" { | ||
| reasons = append(reasons, "logbasename") | ||
| continue | ||
| } | ||
| if lr.SeverityNumber() == plog.SeverityNumberUnspecified { | ||
|
|
@@ -420,6 +427,7 @@ func (c *Config) MatchProfile(log *zap.Logger, rl plog.ResourceLogs, ils plog.Sc | |
| if profile.Severity != nil { | ||
| _, sevText := parser.EvalElem(profile.Severity) | ||
| if sevText == "" { | ||
| reasons = append(reasons, "severity") | ||
| continue | ||
| } | ||
| sevText = strings.ToUpper(sevText) | ||
|
|
@@ -447,6 +455,10 @@ func (c *Config) MatchProfile(log *zap.Logger, rl plog.ResourceLogs, ils plog.Sc | |
| } | ||
| _, gen.Message = parser.EvalElem(profile.Message) | ||
| if gen.Message == "" { | ||
| if idx >= len(c.Profiles)-1 { | ||
| return nil, nil, skipLine | ||
| } | ||
| reasons = append(reasons, "message") | ||
| continue | ||
| } | ||
| // FORMAT MESSAGE | ||
|
|
@@ -480,5 +492,5 @@ func (c *Config) MatchProfile(log *zap.Logger, rl plog.ResourceLogs, ils plog.Sc | |
| gen.Format = profile.Format | ||
| return &gen, &req, nil | ||
| } | ||
| return nil, nil, errors.New("No matching profile for log record") | ||
| return nil, nil, fmt.Errorf("No matching profile for log record, failed to find %v", reasons) | ||
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.