Skip to content

Commit

Permalink
fix: update regex parsing for container logs to support windows file
Browse files Browse the repository at this point in the history
seperator
  • Loading branch information
squ1d123 committed Oct 4, 2024
1 parent fb37793 commit 7572554
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
27 changes: 27 additions & 0 deletions .chloggen/error-filelog-windows-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: filelogreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Supports `add_metadata_from_filepath` for Windows filepaths

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35558]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
2 changes: 1 addition & 1 deletion pkg/stanza/operator/parser/container/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const recombineInternalID = "recombine_container_internal"
const dockerPattern = "^\\{"
const crioPattern = "^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$"
const containerdPattern = "^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$"
const logpathPattern = "^.*\\/(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\\-]+)\\/(?P<container_name>[^\\._]+)\\/(?P<restart_count>\\d+)\\.log$"
const logpathPattern = "^.*(\\/|\\\\)(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\\-]+)(\\/|\\\\)(?P<container_name>[^\\._]+)(\\/|\\\\)(?P<restart_count>\\d+)\\.log$"
const logPathField = "log.file.path"
const crioTimeLayout = "2006-01-02T15:04:05.999999999Z07:00"
const goTimeLayout = "2006-01-02T15:04:05.999Z"
Expand Down
41 changes: 41 additions & 0 deletions pkg/stanza/operator/parser/container/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,47 @@ func TestRecombineProcess(t *testing.T) {
},
},
},
{
"containerd_multiple_with_auto_detection_and_metadata_from_file_path_windows",
func() (operator.Operator, error) {
cfg := NewConfigWithID("test_id")
cfg.AddMetadataFromFilePath = true
set := componenttest.NewNopTelemetrySettings()
return cfg.Build(set)
},
[]*entry.Entry{
{
Body: `2024-04-13T07:59:37.505201169Z stdout P standalone containerd line which i`,
Attributes: map[string]any{
"log.file.path": "C:\\var\\log\\pods\\some_kube-scheduler-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d3\\kube-scheduler44\\1.log",
},
},
{
Body: `2024-04-13T07:59:37.505201169Z stdout F s awesome!`,
Attributes: map[string]any{
"log.file.path": "C:\\var\\log\\pods\\some_kube-scheduler-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d3\\kube-scheduler44\\1.log",
},
},
},
[]*entry.Entry{
{
Attributes: map[string]any{
"log.iostream": "stdout",
"logtag": "P",
"log.file.path": "C:\\var\\log\\pods\\some_kube-scheduler-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d3\\kube-scheduler44\\1.log",
},
Body: "standalone containerd line which is awesome!",
Resource: map[string]any{
"k8s.pod.name": "kube-scheduler-kind-control-plane",
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d3",
"k8s.container.name": "kube-scheduler44",
"k8s.container.restart_count": "1",
"k8s.namespace.name": "some",
},
Timestamp: time.Date(2024, time.April, 13, 7, 59, 37, 505201169, time.UTC),
},
},
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 7572554

Please sign in to comment.