-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gcp_errorreporting as a new log form
For now this ensures that on level ERROR or worse the appropriate minimal fields are set, so the information gets scraped by Google Cloud Error Reporting. In turn this requires for StaticFields to allow for object values.
- Loading branch information
1 parent
d26107c
commit 3e15fb4
Showing
8 changed files
with
178 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package log | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestFromParsedWithWithStaticFieldStrings(t *testing.T) { | ||
|
||
spec := Spec() | ||
pConf, err := spec.ParsedConfigFromAny(map[string]any{ | ||
"level": "INFO", | ||
"format": "logfmt", | ||
"add_timestamp": false, | ||
"level_name": "level", | ||
"timestamp_name": "time", | ||
"message_name": "msg", | ||
"static_fields": map[string]any{ | ||
"@service": "benthos", | ||
}, | ||
"file": map[string]any{ | ||
"path": "", | ||
"rotate": false, | ||
"rotate_max_age_days": 0, | ||
}, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
config, err := FromParsed(pConf) | ||
if err != nil { | ||
t.Fatal("Failure in FromParsed:", err) | ||
} | ||
expected := Config{ | ||
LogLevel: "INFO", | ||
Format: "logfmt", | ||
LevelName: "level", | ||
MessageName: "msg", | ||
TimestampName: "time", | ||
StaticFields: map[string]any{ | ||
"@service": "benthos", | ||
}, | ||
} | ||
diff := cmp.Diff(config, expected) | ||
if diff != "" { | ||
t.Fatalf("Unexpected parsed config (-got +want):\n%s\n", diff) | ||
} | ||
} | ||
|
||
func TestFromParsedWithStaticFieldObjects(t *testing.T) { | ||
|
||
spec := Spec() | ||
pConf, err := spec.ParsedConfigFromAny(map[string]any{ | ||
"level": "INFO", | ||
"format": "logfmt", | ||
"add_timestamp": false, | ||
"static_fields": map[string]any{ | ||
"serviceContext": map[string]any{ | ||
"service": "benthos", | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
config, err := FromParsed(pConf) | ||
if err != nil { | ||
t.Fatal("failure in FromParsed:", err) | ||
} | ||
expected := Config{ | ||
LogLevel: "INFO", | ||
Format: "logfmt", | ||
LevelName: "level", | ||
MessageName: "msg", | ||
TimestampName: "time", | ||
StaticFields: map[string]any{ | ||
"serviceContext": map[string]any{ | ||
"service": string("benthos"), | ||
}, | ||
}, | ||
} | ||
diff := cmp.Diff(config, expected) | ||
if diff != "" { | ||
t.Fatalf("Unexpected parsed config (-got +want):\n%s\n", diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters