Skip to content

Commit

Permalink
wip: per-tenant attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
xperimental committed Oct 10, 2024
1 parent 09daa17 commit 3811195
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 1 deletion.
65 changes: 64 additions & 1 deletion operator/internal/manifests/config_otlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,71 @@ func otlpAttributeConfig(ls *lokiv1.LokiStackSpec) config.OTLPAttributeConfig {
IgnoreGlobalStreamLabels: tenantOTLP.IgnoreGlobalStreamLabels,
}

// TODO stream labels and metadata for tenant
if streamLabels := tenantOTLP.StreamLabels; streamLabels != nil {
regularExpressions, names := collectAttributes(streamLabels.ResourceAttributes)
tenantResult.ResourceAttributes = append(tenantResult.ResourceAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionStreamLabel,
Names: names,
})

for _, re := range regularExpressions {
tenantResult.ResourceAttributes = append(tenantResult.ResourceAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionStreamLabel,
Regex: re,
})
}
}

if structuredMetadata := tenantOTLP.StructuredMetadata; structuredMetadata != nil {
if resAttr := structuredMetadata.ResourceAttributes; len(resAttr) > 0 {
regularExpressions, names := collectAttributes(resAttr)
tenantResult.ResourceAttributes = append(tenantResult.ResourceAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionMetadata,
Names: names,
})

for _, re := range regularExpressions {
tenantResult.ResourceAttributes = append(tenantResult.ResourceAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionMetadata,
Regex: re,
})
}
}

if scopeAttr := structuredMetadata.ScopeAttributes; len(scopeAttr) > 0 {
regularExpressions, names := collectAttributes(scopeAttr)
tenantResult.ScopeAttributes = append(tenantResult.ScopeAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionMetadata,
Names: names,
})

for _, re := range regularExpressions {
tenantResult.ScopeAttributes = append(tenantResult.ScopeAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionMetadata,
Regex: re,
})
}
}

if logAttr := structuredMetadata.LogAttributes; len(logAttr) > 0 {
regularExpressions, names := collectAttributes(logAttr)
tenantResult.LogAttributes = append(tenantResult.LogAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionMetadata,
Names: names,
})

for _, re := range regularExpressions {
tenantResult.LogAttributes = append(tenantResult.LogAttributes, config.OTLPAttribute{
Action: config.OTLPAttributeActionMetadata,
Regex: re,
})
}
}
}

if result.Tenants == nil {
result.Tenants = map[string]*config.OTLPTenantAttributeConfig{}
}
result.Tenants[tenant] = tenantResult
}
}
Expand Down
161 changes: 161 additions & 0 deletions operator/internal/manifests/config_otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,167 @@ func TestOtlpAttributeConfig(t *testing.T) {
},
},
},
{
desc: "tenant stream label",
spec: lokiv1.LokiStackSpec{
Limits: &lokiv1.LimitsSpec{
Tenants: map[string]lokiv1.PerTenantLimitsTemplateSpec{
"test-tenant": {
OTLP: &lokiv1.TenantOTLPSpec{
IgnoreGlobalStreamLabels: true,
OTLPSpec: lokiv1.OTLPSpec{
StreamLabels: &lokiv1.OTLPStreamLabelSpec{
ResourceAttributes: []lokiv1.OTLPAttributeReference{
{
Name: "tenant.stream.label",
},
},
},
},
},
},
},
},
},
wantConfig: config.OTLPAttributeConfig{
Tenants: map[string]*config.OTLPTenantAttributeConfig{
"test-tenant": {
IgnoreGlobalStreamLabels: true,
ResourceAttributes: []config.OTLPAttribute{
{
Action: config.OTLPAttributeActionStreamLabel,
Names: []string{"tenant.stream.label"},
},
},
},
},
},
},
{
desc: "tenant stream label regex",
spec: lokiv1.LokiStackSpec{
Limits: &lokiv1.LimitsSpec{
Tenants: map[string]lokiv1.PerTenantLimitsTemplateSpec{
"test-tenant": {
OTLP: &lokiv1.TenantOTLPSpec{
OTLPSpec: lokiv1.OTLPSpec{
StreamLabels: &lokiv1.OTLPStreamLabelSpec{
ResourceAttributes: []lokiv1.OTLPAttributeReference{
{
Name: "tenant\\.stream\\.label\\.regex\\..+",
Regex: true,
},
},
},
},
},
},
},
},
},
wantConfig: config.OTLPAttributeConfig{
Tenants: map[string]*config.OTLPTenantAttributeConfig{
"test-tenant": {
ResourceAttributes: []config.OTLPAttribute{
{
Action: config.OTLPAttributeActionStreamLabel,
Regex: "tenant\\.stream\\.label\\.regex\\..+",
},
},
},
},
},
},
{
desc: "tenant metadata",
spec: lokiv1.LokiStackSpec{
Limits: &lokiv1.LimitsSpec{
Tenants: map[string]lokiv1.PerTenantLimitsTemplateSpec{
"test-tenant": {
OTLP: &lokiv1.TenantOTLPSpec{
OTLPSpec: lokiv1.OTLPSpec{
StructuredMetadata: &lokiv1.OTLPMetadataSpec{
ResourceAttributes: []lokiv1.OTLPAttributeReference{
{
Name: "tenant.metadata",
},
},
},
},
},
},
},
},
},
wantConfig: config.OTLPAttributeConfig{
Tenants: map[string]*config.OTLPTenantAttributeConfig{
"test-tenant": {
ResourceAttributes: []config.OTLPAttribute{
{
Action: config.OTLPAttributeActionMetadata,
Names: []string{"tenant.metadata"},
},
},
},
},
},
},
{
desc: "tenant combined",
spec: lokiv1.LokiStackSpec{
Limits: &lokiv1.LimitsSpec{
Tenants: map[string]lokiv1.PerTenantLimitsTemplateSpec{
"test-tenant": {
OTLP: &lokiv1.TenantOTLPSpec{
OTLPSpec: lokiv1.OTLPSpec{
StreamLabels: &lokiv1.OTLPStreamLabelSpec{
ResourceAttributes: []lokiv1.OTLPAttributeReference{
{
Name: "tenant.stream.label",
},
{
Name: "tenant\\.stream\\.label\\.regex\\..+",
Regex: true,
},
},
},
StructuredMetadata: &lokiv1.OTLPMetadataSpec{
ResourceAttributes: []lokiv1.OTLPAttributeReference{
{
Name: "tenant.resource.metadata",
},
{
Name: "tenant\\.resource.metadata\\.other\\..+",
Regex: true,
},
},
ScopeAttributes: []lokiv1.OTLPAttributeReference{
{
Name: "tenant.scope.metadata",
},
{
Name: "tenant\\.scope.metadata\\.other\\..+",
Regex: true,
},
},
LogAttributes: []lokiv1.OTLPAttributeReference{
{
Name: "tenant.log.metadata",
},
{
Name: "tenant\\.log.metadata\\.other\\..+",
Regex: true,
},
},
},
},
},
},
},
},
},
wantConfig: config.OTLPAttributeConfig{},
},
{
desc: "openshift-logging defaults",
spec: lokiv1.LokiStackSpec{
Expand Down

0 comments on commit 3811195

Please sign in to comment.