Skip to content

Commit

Permalink
fix when k8s meta is empty (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryRomanov authored Dec 17, 2024
1 parent 1da9776 commit 72cd123
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
31 changes: 21 additions & 10 deletions plugin/input/file/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,28 @@ func newMetaInformation(filename, symlink string, inode inodeID, offset int64, p
}

func (m metaInformation) GetData() map[string]any {
return map[string]any{
"filename": m.filename,
"symlink": m.symlink,
"inode": m.inode,
"offset": m.offset,
"pod_name": m.k8sMetadata.PodName,
"namespace": m.k8sMetadata.Namespace,
"container_name": m.k8sMetadata.ContainerName,
"container_id": m.k8sMetadata.ContainerID,
"pod": m.k8sMetadata.Pod,
data := map[string]any{
"filename": m.filename,
"symlink": m.symlink,
"inode": m.inode,
"offset": m.offset,
}

if m.k8sMetadata != nil {
data["pod_name"] = m.k8sMetadata.PodName
data["namespace"] = m.k8sMetadata.Namespace
data["container_name"] = m.k8sMetadata.ContainerName
data["container_id"] = m.k8sMetadata.ContainerID
data["pod"] = m.k8sMetadata.Pod
} else {
data["pod_name"] = nil
data["namespace"] = nil
data["container_name"] = nil
data["container_id"] = nil
data["pod"] = nil
}

return data
}

/*{ meta-params
Expand Down
19 changes: 19 additions & 0 deletions plugin/input/file/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,25 @@ func TestGetData(t *testing.T) {
"container_id": "4e0301b633eaa2bfdcafdeba59ba0c72a3815911a6a820bf273534b0f32d98e0",
},
},
{
name: "No k8s data",
metaInfo: metaInformation{
filename: "/container.log",
symlink: "/k8s-logs/container.log",
inode: 12345,
offset: 0,
},
expected: map[string]any{
"filename": "/container.log",
"symlink": "/k8s-logs/container.log",
"inode": uint64(12345),
"offset": int64(0),
"pod_name": nil,
"namespace": nil,
"container_name": nil,
"container_id": nil,
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 72cd123

Please sign in to comment.