Skip to content

Commit

Permalink
Merge branch 'main' of github.com:QuantumEnigmaa/loki into fix-netpols
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumEnigmaa committed Jan 31, 2024
2 parents 0700f43 + 7a04da8 commit 6fcf4c1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/loghttp/push/otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func otlpToLokiPushRequest(ld plog.Logs, userID string, tenantsRetention Tenants
res := rls.At(i).Resource()
resAttrs := res.Attributes()

if v, _ := resAttrs.Get(attrServiceName); v.AsString() == "" {
if v, ok := resAttrs.Get(attrServiceName); !ok || v.AsString() == "" {
resAttrs.PutStr(attrServiceName, "unknown_service")
}
resourceAttributesAsStructuredMetadata := make(push.LabelsAdapter, 0, resAttrs.Len())
Expand Down
72 changes: 72 additions & 0 deletions pkg/loghttp/push/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,78 @@ func TestOTLPToLokiPushRequest(t *testing.T) {
mostRecentEntryTimestamp: now,
},
},
{
name: "no resource attributes defined",
otlpConfig: DefaultOTLPConfig,
generateLogs: func() plog.Logs {
ld := plog.NewLogs()
ld.ResourceLogs().AppendEmpty()
ld.ResourceLogs().At(0).ScopeLogs().AppendEmpty().LogRecords().AppendEmpty().Body().SetStr("test body")
ld.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).SetTimestamp(pcommon.Timestamp(now.UnixNano()))
return ld
},
expectedPushRequest: logproto.PushRequest{
Streams: []logproto.Stream{
{
Labels: `{service_name="unknown_service"}`,
Entries: []logproto.Entry{
{
Timestamp: now,
Line: "test body",
StructuredMetadata: push.LabelsAdapter{},
},
},
},
},
},
expectedStats: Stats{
numLines: 1,
logLinesBytes: map[time.Duration]int64{
time.Hour: 9,
},
structuredMetadataBytes: map[time.Duration]int64{
time.Hour: 0,
},
streamLabelsSize: 27,
mostRecentEntryTimestamp: now,
},
},
{
name: "service.name not defined in resource attributes",
otlpConfig: DefaultOTLPConfig,
generateLogs: func() plog.Logs {
ld := plog.NewLogs()
ld.ResourceLogs().AppendEmpty().Resource().Attributes().PutStr("service.namespace", "foo")
ld.ResourceLogs().At(0).ScopeLogs().AppendEmpty().LogRecords().AppendEmpty().Body().SetStr("test body")
ld.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).SetTimestamp(pcommon.Timestamp(now.UnixNano()))
return ld
},
expectedPushRequest: logproto.PushRequest{
Streams: []logproto.Stream{
{
Labels: `{service_name="unknown_service", service_namespace="foo"}`,
Entries: []logproto.Entry{
{
Timestamp: now,
Line: "test body",
StructuredMetadata: push.LabelsAdapter{},
},
},
},
},
},
expectedStats: Stats{
numLines: 1,
logLinesBytes: map[time.Duration]int64{
time.Hour: 9,
},
structuredMetadataBytes: map[time.Duration]int64{
time.Hour: 0,
},
streamLabelsSize: 47,
mostRecentEntryTimestamp: now,
},
},
{
name: "resource attributes and scope attributes stored as structured metadata",
otlpConfig: DefaultOTLPConfig,
Expand Down
2 changes: 1 addition & 1 deletion production/helm/loki/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Entries should include a reference to the pull request that introduced the chang

[//]: # (<AUTOMATED_UPDATES_LOCATOR> : do not remove this line. This locator is used by the CI pipeline to automatically create a changelog entry for each new Loki release. Add other chart versions and respective changelog entries bellow this line.)

## 5.42.1
## 5.42.2

- [BUGFIX] Added condition for `egress-discovery` networkPolicies and ciliumNetworkPolicies.

Expand Down

0 comments on commit 6fcf4c1

Please sign in to comment.