Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(operator)!: Provide default OTLP attribute configuration #14410

Merged
merged 43 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3c253af
wip! feat(operator): Provide default OTLP attribute configuration for…
xperimental Oct 1, 2024
67c88b2
Extend API for regular expressions
xperimental Oct 7, 2024
bb420c9
Make conversion code compatible with regex
xperimental Oct 7, 2024
9da80cd
Fix typo
xperimental Oct 7, 2024
b2e70aa
Update default attributes based on data model
xperimental Oct 7, 2024
9919c58
Split OTLP config to separate file
xperimental Oct 7, 2024
8258bbd
Add tests for OTLP config conversion
xperimental Oct 7, 2024
7094618
Update API docs
xperimental Oct 7, 2024
5d13142
Merge branch 'main' into otlp-defaults
xperimental Oct 10, 2024
b2209f2
Update test after Go update
xperimental Oct 10, 2024
09daa17
Small refactor of default config
xperimental Oct 10, 2024
3a43315
Convert per-tenant attributes in configuration
xperimental Oct 10, 2024
1157d1a
Refactor conversion code
xperimental Oct 11, 2024
8ef3697
Split default attributes into required and recommended
xperimental Oct 11, 2024
35ff750
Merge branch 'main' into otlp-defaults
xperimental Oct 14, 2024
b5986b6
Test for default mixed with custom attributes
xperimental Oct 14, 2024
8ab9a3f
Simple attribute de-duplication
xperimental Oct 14, 2024
03a2236
Sort and deduplicate attributes
xperimental Oct 14, 2024
1071aa8
Provide defaults pre-sorted
xperimental Oct 14, 2024
207d3bd
Add kubernetes_host stream label
xperimental Oct 14, 2024
47c7b93
Simple changes from review
xperimental Oct 18, 2024
5d6955f
Merge branch 'main' into otlp-defaults
xperimental Oct 18, 2024
40840bf
Update bundle and docs
xperimental Oct 18, 2024
1f5d5b9
Remove duplicate change introduced by merge
xperimental Oct 18, 2024
1e3dac8
Remove option to ignore global configuration
xperimental Oct 18, 2024
630f04d
Small refactor of defaults function
xperimental Oct 18, 2024
0dccac4
Update todo lines
xperimental Oct 18, 2024
88bf863
Update API docs
xperimental Oct 18, 2024
1a63d89
Add note about required attributes
xperimental Oct 21, 2024
21f502f
Move Kubernetes parent attributes to stream labels
xperimental Oct 21, 2024
ebfc753
Move OpenShift OTLP configuration to own package
xperimental Oct 21, 2024
6c933be
Avoid usage of default stream labels
xperimental Oct 21, 2024
750a77d
Refactor tenant attribute config code
xperimental Oct 21, 2024
6ac670f
Fix sort for single attribute config
xperimental Oct 21, 2024
312eea0
Copy global attributes to tenant configuration
xperimental Oct 21, 2024
76f8c57
Add test for tenant config combined with defaults
xperimental Oct 21, 2024
2dac6a8
Fix default resource attributes being overwritten
xperimental Oct 21, 2024
ce75bfb
Use raw strings for regular expressions
xperimental Oct 21, 2024
8f24c62
Merge branch 'main' into otlp-defaults
xperimental Oct 21, 2024
65fe47c
Merge branch 'main' into otlp-defaults
xperimental Oct 22, 2024
f635ba6
Fix new code after merge
xperimental Oct 22, 2024
94ba2e8
Add validation for custom OTLP configuration
xperimental Oct 22, 2024
7253cf8
Move some attributes to structured metadata
xperimental Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 72 additions & 121 deletions operator/api/loki/v1/lokistack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,34 @@ type OpenshiftTenantSpec struct {
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Admin Groups"
AdminGroups []string `json:"adminGroups"`

// OTLP contains settings for ingesting data using OTLP in the OpenShift tenancy mode.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="OpenTelemetry Protocol"
OTLP *OpenshiftOTLPConfig `json:"otlp,omitempty"`
}

// OpenshiftOTLPConfig defines configuration specific to users using OTLP together with an OpenShift tenancy mode.
type OpenshiftOTLPConfig struct {
// DisableRecommendedAttributes can be used to reduce the number of attributes used for stream labels and structured
// metadata.
//
// Enabling this setting removes the "recommended attributes" from the generated Loki configuration. This will cause
// meta information to not be available as stream labels or structured metadata, potentially making queries more
// expensive and less performant.
//
// Note that there is a set of "required attributes", needed for OpenShift Logging to work properly. Those will be
// added to the configuration, even if this field is set to true.
//
// This option is supposed to be combined with a custom label configuration customizing the labels for the specific
// usecase.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Disable recommended OTLP attributes"
DisableRecommendedAttributes bool `json:"disableRecommendedAttributes,omitempty"`
}

// LokiComponentSpec defines the requirements to configure scheduling
Expand Down Expand Up @@ -791,138 +819,70 @@ type IngestionLimitSpec struct {
PerStreamRateLimitBurst int32 `json:"perStreamRateLimitBurst,omitempty"`
}

// OTLPAttributeAction defines the action to executed when indexing
// OTLP resource attributes. Resource attributes can be either added
// to the index, the chunk structured metadata or entirely dropped.
type OTLPAttributeAction string

const (
// OTLPAttributeActionIndexLabel stores a resource attribute as a label, which is part of the index identifying streams.
OTLPAttributeActionIndexLabel OTLPAttributeAction = "indexLabel"
// OTLPAttributeActionStructuredMetadata stores an attribute as structured metadata with each log entry.
OTLPAttributeActionStructuredMetadata OTLPAttributeAction = "structuredMetadata"
// OTLPAttributeActionDrop removes the matching attributes from the log entry.
OTLPAttributeActionDrop OTLPAttributeAction = "drop"
)

// OTLPAttributesSpec contains the configuration for a set of attributes
// to store them as index labels or structured metadata or drop them altogether.
type OTLPAttributesSpec struct {
// Action defines the indexing action for the selected attributes. They
// can be either added to structured metadata or drop altogether.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=structured_metadata;drop
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Action"
Action OTLPAttributeAction `json:"action"`

// Attributes allows choosing the attributes by listing their names.
// OTLPSpec defines which resource, scope and log attributes should be used as stream labels or
// stored as structured metadata.
type OTLPSpec struct {
// StreamLabels configures which resource attributes are converted to Loki stream labels.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Attribute Names"
Attributes []string `json:"attributes,omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Stream Labels"
StreamLabels *OTLPStreamLabelSpec `json:"streamLabels,omitempty"`

// Regex allows choosing the attributes by matching a regular expression.
// StructuredMetadata configures which attributes are saved in structured metadata.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Regular Expression"
Regex string `json:"regex,omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Structured Metadata"
StructuredMetadata *OTLPMetadataSpec `json:"structuredMetadata,omitempty"`
}

// OTLPResourceAttributesConfigSpec contains the configuration for a set of resource attributes
// to store them as index labels or structured metadata or drop them altogether.
type OTLPResourceAttributesConfigSpec struct {
// Action defines the indexing action for the selected resoure attributes. They
// can be either indexed as labels, added to structured metadata or drop altogether.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=index_label;structured_metadata;drop
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Action"
Action OTLPAttributeAction `json:"action"`

// Attributes is the list of attributes to configure indexing or drop them
// altogether.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Attribute Names"
Attributes []string `json:"attributes,omitempty"`

// Regex allows choosing the attributes by matching a regular expression.
type OTLPStreamLabelSpec struct {
// ResourceAttributes lists the names of the resource attributes that should be converted into Loki stream labels.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Regular Expression"
Regex string `json:"regex,omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Resource Attributes"
ResourceAttributes []OTLPAttributeReference `json:"resourceAttributes,omitempty"`
}

// OTLPResourceAttributesSpec contains the configuration for resource attributes
// to store them as index labels or structured metadata or drop them altogether.
type OTLPResourceAttributesSpec struct {
// IgnoreDefaults controls whether to ignore the global configuration for resource attributes
// indexed as labels.
//
// If IgnoreDefaults is true, then this spec needs to contain at least one mapping to a index label.
type OTLPMetadataSpec struct {
// ResourceAttributes lists the names of resource attributes that should be included in structured metadata.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors="urn:alm:descriptor:com.tectonic.ui:booleanSwitch",displayName="Ignore Global Defaults"
IgnoreDefaults bool `json:"ignoreDefaults,omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Resource Attributes"
ResourceAttributes []OTLPAttributeReference `json:"resourceAttributes,omitempty"`

// Attributes contains the configuration for resource attributes
// to store them as index labels or structured metadata or drop them altogether.
// ScopeAttributes lists the names of scope attributes that should be included in structured metadata.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Attributes"
Attributes []OTLPResourceAttributesConfigSpec `json:"attributes,omitempty"`
}
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Scope Attributes"
ScopeAttributes []OTLPAttributeReference `json:"scopeAttributes,omitempty"`

// GlobalOTLPSpec defines which resource, scope and log attributes to
// be stored as index or structured metadata or drop altogether for all
// tenants.
type GlobalOTLPSpec struct {
// IndexedResourceAttributes contains the global configuration for resource attributes
// to store them as index labels.
// LogAttributes lists the names of log attributes that should be included in structured metadata.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Indexed Resource Attributes"
IndexedResourceAttributes []string `json:"indexedResourceAttributes,omitempty"`

OTLPSpec `json:",omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Log Attributes"
LogAttributes []OTLPAttributeReference `json:"logAttributes,omitempty"`
}

// OTLPSpec defines which resource, scope and log attributes to
// be stored as index or structured metadata or drop altogether
type OTLPSpec struct {
// ResourceAttributes contains the configuration for resource attributes
// to store them as index labels or structured metadata or drop them altogether.
type OTLPAttributeReference struct {
// Name contains either a verbatim name of an attribute or a regular expression matching many attributes.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Resource Attributes"
ResourceAttributes *OTLPResourceAttributesSpec `json:"resourceAttributes,omitempty"`

// ScopeAttributes contains the configuration for scope attributes
// to store them as structured metadata or drop them altogether.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Scope Attributes"
ScopeAttributes []OTLPAttributesSpec `json:"scopeAttributes,omitempty"`
// +required
// +kubebuilder:validation:Required
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Name"
Name string `json:"name"`

// LogAttributes contains the configuration for log attributes
// to store them as structured metadata or drop them altogether.
// If Regex is true, then Name is treated as a regular expression instead of as a verbatim attribute name.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Log Attributes"
LogAttributes []OTLPAttributesSpec `json:"logAttributes,omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Treat name as regular expression"
Regex bool `json:"regex,omitempty"`
}

// RetentionStreamSpec defines a log stream with separate retention time.
Expand Down Expand Up @@ -978,13 +938,14 @@ type LimitsTemplateSpec struct {
// +kubebuilder:validation:Optional
QueryLimits *QueryLimitSpec `json:"queries,omitempty"`

// OTLP to configure which resource, scope and log attributes
// to store as labels or structured metadata or drop them altogether
// for all tenants.
// OTLP to configure which resource, scope and log attributes are stored as stream labels or structured metadata.
//
// Tenancy modes can provide a default OTLP configuration, when no custom OTLP configuration is set or even
// enforce the use of some required attributes.
//
// +optional
// +kubebuilder:validation:Optional
OTLP *GlobalOTLPSpec `json:"otlp,omitempty"`
OTLP *OTLPSpec `json:"otlp,omitempty"`

// Retention defines how long logs are kept in storage.
//
Expand All @@ -993,7 +954,7 @@ type LimitsTemplateSpec struct {
Retention *RetentionLimitSpec `json:"retention,omitempty"`
}

// LimitsTemplateSpec defines the limits applied at ingestion or query path.
// PerTenantLimitsTemplateSpec defines the limits applied at ingestion or query path.
type PerTenantLimitsTemplateSpec struct {
// IngestionLimits defines the limits applied on ingested log streams.
//
Expand All @@ -1007,9 +968,12 @@ type PerTenantLimitsTemplateSpec struct {
// +kubebuilder:validation:Optional
QueryLimits *PerTenantQueryLimitSpec `json:"queries,omitempty"`

// OTLP to configure which resource, scope and log attributes
// to store as labels or structured metadata or drop them altogether
// for a single tenants.
// OTLP to configure which resource, scope and log attributes are stored as stream labels or structured metadata.
//
// Tenancy modes can provide a default OTLP configuration, when no custom OTLP configuration is set or even
// enforce the use of some required attributes.
//
// The per-tenant configuration for OTLP attributes will be merged with the global configuration.
//
// +optional
// +kubebuilder:validation:Optional
Expand Down Expand Up @@ -1463,16 +1427,3 @@ func (t BlockedQueryTypes) String() string {

return strings.Join(res, ",")
}

func (a OTLPAttributeAction) Value() string {
switch a {
case OTLPAttributeActionIndexLabel:
return "index_label"
case OTLPAttributeActionStructuredMetadata:
return "structured_metadata"
case OTLPAttributeActionDrop:
return "drop"
default:
return string(a)
}
}
Loading
Loading