Skip to content

Commit 28807d3

Browse files
authored
[filelogreceiver] fix: update logpath regex to include rotated files in container parser (#38440)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Extends log file path pattern in container parser to include rotated log files which are currently being rejected, leading to dropped logs. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #35137 <!--Describe what testing was performed and which tests were added.--> #### Testing Added two test cases to include rotated file log path examples.
1 parent b8218ac commit 28807d3

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: filelogreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Extend container parser log file path pattern to include rotated files."
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35137]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

pkg/stanza/operator/parser/container/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
dockerPattern = "^\\{"
3131
crioPattern = "^(?P<time>[^ Z]+) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$"
3232
containerdPattern = "^(?P<time>[^ ^Z]+Z) (?P<stream>stdout|stderr) (?P<logtag>[^ ]*) ?(?P<log>.*)$"
33-
logpathPattern = "^.*(\\/|\\\\)(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\\-]+)(\\/|\\\\)(?P<container_name>[^\\._]+)(\\/|\\\\)(?P<restart_count>\\d+)\\.log$"
33+
logpathPattern = "^.*(\\/|\\\\)(?P<namespace>[^_]+)_(?P<pod_name>[^_]+)_(?P<uid>[a-f0-9\\-]+)(\\/|\\\\)(?P<container_name>[^\\._]+)(\\/|\\\\)(?P<restart_count>\\d+)\\.log(\\.\\d{8}-\\d{6})?$"
3434
logPathField = attrs.LogFilePath
3535
crioTimeLayout = "2006-01-02T15:04:05.999999999Z07:00"
3636
goTimeLayout = "2006-01-02T15:04:05.999Z"

pkg/stanza/operator/parser/container/parser_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,41 @@ func TestRecombineProcess(t *testing.T) {
222222
},
223223
},
224224
},
225+
{
226+
"crio_standalone_with_auto_detection_and_metadata_from_rotated_file_path",
227+
func() (operator.Operator, error) {
228+
cfg := NewConfigWithID("test_id")
229+
cfg.AddMetadataFromFilePath = true
230+
set := componenttest.NewNopTelemetrySettings()
231+
return cfg.Build(set)
232+
},
233+
[]*entry.Entry{
234+
{
235+
Body: `2024-04-13T07:59:37.505201169-10:00 stdout F standalone crio line which is awesome!`,
236+
Attributes: map[string]any{
237+
attrs.LogFilePath: "/var/log/pods/some_kube-scheduler-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d3/kube-scheduler44/1.log.20250219-233547",
238+
},
239+
},
240+
},
241+
[]*entry.Entry{
242+
{
243+
Attributes: map[string]any{
244+
"log.iostream": "stdout",
245+
"logtag": "F",
246+
attrs.LogFilePath: "/var/log/pods/some_kube-scheduler-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d3/kube-scheduler44/1.log.20250219-233547",
247+
},
248+
Body: "standalone crio line which is awesome!",
249+
Resource: map[string]any{
250+
"k8s.pod.name": "kube-scheduler-kind-control-plane",
251+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d3",
252+
"k8s.container.name": "kube-scheduler44",
253+
"k8s.container.restart_count": "1",
254+
"k8s.namespace.name": "some",
255+
},
256+
Timestamp: time.Date(2024, time.April, 13, 7, 59, 37, 505201169, time.FixedZone("", -10*60*60)),
257+
},
258+
},
259+
},
225260
{
226261
"containerd_standalone_with_auto_detection_and_metadata_from_file_path",
227262
func() (operator.Operator, error) {
@@ -257,6 +292,41 @@ func TestRecombineProcess(t *testing.T) {
257292
},
258293
},
259294
},
295+
{
296+
"containerd_standalone_with_auto_detection_and_metadata_from_rotated_file_path",
297+
func() (operator.Operator, error) {
298+
cfg := NewConfigWithID("test_id")
299+
cfg.AddMetadataFromFilePath = true
300+
set := componenttest.NewNopTelemetrySettings()
301+
return cfg.Build(set)
302+
},
303+
[]*entry.Entry{
304+
{
305+
Body: `2024-04-13T07:59:37.505201169Z stdout F standalone containerd line which is awesome!`,
306+
Attributes: map[string]any{
307+
attrs.LogFilePath: "/var/log/pods/some_kube-scheduler-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d3/kube-scheduler44/1.log.20250219-233547",
308+
},
309+
},
310+
},
311+
[]*entry.Entry{
312+
{
313+
Attributes: map[string]any{
314+
"log.iostream": "stdout",
315+
"logtag": "F",
316+
attrs.LogFilePath: "/var/log/pods/some_kube-scheduler-kind-control-plane_49cc7c1fd3702c40b2686ea7486091d3/kube-scheduler44/1.log.20250219-233547",
317+
},
318+
Resource: map[string]any{
319+
"k8s.pod.name": "kube-scheduler-kind-control-plane",
320+
"k8s.pod.uid": "49cc7c1fd3702c40b2686ea7486091d3",
321+
"k8s.container.name": "kube-scheduler44",
322+
"k8s.container.restart_count": "1",
323+
"k8s.namespace.name": "some",
324+
},
325+
Body: "standalone containerd line which is awesome!",
326+
Timestamp: time.Date(2024, time.April, 13, 7, 59, 37, 505201169, time.UTC),
327+
},
328+
},
329+
},
260330
{
261331
"crio_multiple_with_auto_detection_and_metadata_from_file_path",
262332
func() (operator.Operator, error) {

0 commit comments

Comments
 (0)