Skip to content

Commit 1b52387

Browse files
authored
feat(operator)!: Provide default OTLP attribute configuration (#14410)
1 parent 673ede1 commit 1b52387

24 files changed

+3294
-2424
lines changed

‎operator/api/loki/v1/lokistack_types.go

Lines changed: 72 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,34 @@ type OpenshiftTenantSpec struct {
289289
// +kubebuilder:validation:Optional
290290
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Admin Groups"
291291
AdminGroups []string `json:"adminGroups"`
292+
293+
// OTLP contains settings for ingesting data using OTLP in the OpenShift tenancy mode.
294+
//
295+
// +optional
296+
// +kubebuilder:validation:Optional
297+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="OpenTelemetry Protocol"
298+
OTLP *OpenshiftOTLPConfig `json:"otlp,omitempty"`
299+
}
300+
301+
// OpenshiftOTLPConfig defines configuration specific to users using OTLP together with an OpenShift tenancy mode.
302+
type OpenshiftOTLPConfig struct {
303+
// DisableRecommendedAttributes can be used to reduce the number of attributes used for stream labels and structured
304+
// metadata.
305+
//
306+
// Enabling this setting removes the "recommended attributes" from the generated Loki configuration. This will cause
307+
// meta information to not be available as stream labels or structured metadata, potentially making queries more
308+
// expensive and less performant.
309+
//
310+
// Note that there is a set of "required attributes", needed for OpenShift Logging to work properly. Those will be
311+
// added to the configuration, even if this field is set to true.
312+
//
313+
// This option is supposed to be combined with a custom label configuration customizing the labels for the specific
314+
// usecase.
315+
//
316+
// +optional
317+
// +kubebuilder:validation:Optional
318+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Disable recommended OTLP attributes"
319+
DisableRecommendedAttributes bool `json:"disableRecommendedAttributes,omitempty"`
292320
}
293321

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

794-
// OTLPAttributeAction defines the action to executed when indexing
795-
// OTLP resource attributes. Resource attributes can be either added
796-
// to the index, the chunk structured metadata or entirely dropped.
797-
type OTLPAttributeAction string
798-
799-
const (
800-
// OTLPAttributeActionIndexLabel stores a resource attribute as a label, which is part of the index identifying streams.
801-
OTLPAttributeActionIndexLabel OTLPAttributeAction = "indexLabel"
802-
// OTLPAttributeActionStructuredMetadata stores an attribute as structured metadata with each log entry.
803-
OTLPAttributeActionStructuredMetadata OTLPAttributeAction = "structuredMetadata"
804-
// OTLPAttributeActionDrop removes the matching attributes from the log entry.
805-
OTLPAttributeActionDrop OTLPAttributeAction = "drop"
806-
)
807-
808-
// OTLPAttributesSpec contains the configuration for a set of attributes
809-
// to store them as index labels or structured metadata or drop them altogether.
810-
type OTLPAttributesSpec struct {
811-
// Action defines the indexing action for the selected attributes. They
812-
// can be either added to structured metadata or drop altogether.
813-
//
814-
// +required
815-
// +kubebuilder:validation:Required
816-
// +kubebuilder:validation:Enum=structured_metadata;drop
817-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Action"
818-
Action OTLPAttributeAction `json:"action"`
819-
820-
// Attributes allows choosing the attributes by listing their names.
822+
// OTLPSpec defines which resource, scope and log attributes should be used as stream labels or
823+
// stored as structured metadata.
824+
type OTLPSpec struct {
825+
// StreamLabels configures which resource attributes are converted to Loki stream labels.
821826
//
822827
// +optional
823828
// +kubebuilder:validation:Optional
824-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Attribute Names"
825-
Attributes []string `json:"attributes,omitempty"`
829+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Stream Labels"
830+
StreamLabels *OTLPStreamLabelSpec `json:"streamLabels,omitempty"`
826831

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

835-
// OTLPResourceAttributesConfigSpec contains the configuration for a set of resource attributes
836-
// to store them as index labels or structured metadata or drop them altogether.
837-
type OTLPResourceAttributesConfigSpec struct {
838-
// Action defines the indexing action for the selected resoure attributes. They
839-
// can be either indexed as labels, added to structured metadata or drop altogether.
840-
//
841-
// +required
842-
// +kubebuilder:validation:Required
843-
// +kubebuilder:validation:Enum=index_label;structured_metadata;drop
844-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Action"
845-
Action OTLPAttributeAction `json:"action"`
846-
847-
// Attributes is the list of attributes to configure indexing or drop them
848-
// altogether.
849-
//
850-
// +optional
851-
// +kubebuilder:validation:Optional
852-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Attribute Names"
853-
Attributes []string `json:"attributes,omitempty"`
854-
855-
// Regex allows choosing the attributes by matching a regular expression.
840+
type OTLPStreamLabelSpec struct {
841+
// ResourceAttributes lists the names of the resource attributes that should be converted into Loki stream labels.
856842
//
857843
// +optional
858844
// +kubebuilder:validation:Optional
859-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Regular Expression"
860-
Regex string `json:"regex,omitempty"`
845+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Resource Attributes"
846+
ResourceAttributes []OTLPAttributeReference `json:"resourceAttributes,omitempty"`
861847
}
862848

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

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

885-
// GlobalOTLPSpec defines which resource, scope and log attributes to
886-
// be stored as index or structured metadata or drop altogether for all
887-
// tenants.
888-
type GlobalOTLPSpec struct {
889-
// IndexedResourceAttributes contains the global configuration for resource attributes
890-
// to store them as index labels.
864+
// LogAttributes lists the names of log attributes that should be included in structured metadata.
891865
//
892866
// +optional
893867
// +kubebuilder:validation:Optional
894-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Indexed Resource Attributes"
895-
IndexedResourceAttributes []string `json:"indexedResourceAttributes,omitempty"`
896-
897-
OTLPSpec `json:",omitempty"`
868+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Log Attributes"
869+
LogAttributes []OTLPAttributeReference `json:"logAttributes,omitempty"`
898870
}
899871

900-
// OTLPSpec defines which resource, scope and log attributes to
901-
// be stored as index or structured metadata or drop altogether
902-
type OTLPSpec struct {
903-
// ResourceAttributes contains the configuration for resource attributes
904-
// to store them as index labels or structured metadata or drop them altogether.
872+
type OTLPAttributeReference struct {
873+
// Name contains either a verbatim name of an attribute or a regular expression matching many attributes.
905874
//
906-
// +optional
907-
// +kubebuilder:validation:Optional
908-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Resource Attributes"
909-
ResourceAttributes *OTLPResourceAttributesSpec `json:"resourceAttributes,omitempty"`
910-
911-
// ScopeAttributes contains the configuration for scope attributes
912-
// to store them as structured metadata or drop them altogether.
913-
//
914-
// +optional
915-
// +kubebuilder:validation:Optional
916-
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Scope Attributes"
917-
ScopeAttributes []OTLPAttributesSpec `json:"scopeAttributes,omitempty"`
875+
// +required
876+
// +kubebuilder:validation:Required
877+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Name"
878+
Name string `json:"name"`
918879

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

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

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

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

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

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

14641428
return strings.Join(res, ",")
14651429
}
1466-
1467-
func (a OTLPAttributeAction) Value() string {
1468-
switch a {
1469-
case OTLPAttributeActionIndexLabel:
1470-
return "index_label"
1471-
case OTLPAttributeActionStructuredMetadata:
1472-
return "structured_metadata"
1473-
case OTLPAttributeActionDrop:
1474-
return "drop"
1475-
default:
1476-
return string(a)
1477-
}
1478-
}

‎operator/api/loki/v1/v1.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ var (
8484
// ErrIPv6InstanceAddrTypeNotAllowed when the default InstanceAddrType is used with enableIPv6.
8585
ErrIPv6InstanceAddrTypeNotAllowed = errors.New(`instanceAddrType "default" cannot be used with enableIPv6 at the same time`)
8686

87-
// ErrOTLPResourceAttributesEmptyNotAllowed when the OTLP ResourceAttributes are empty even though ignoreDefaults is enabled.
88-
ErrOTLPResourceAttributesEmptyNotAllowed = errors.New(`resourceAttributes cannot be empty when ignoreDefaults is true`)
89-
// ErrOTLPResourceAttributesIndexLabelActionMissing when OTLP ResourceAttributes does not contain at least one index label when ignoreDefaults is enabled.
90-
ErrOTLPResourceAttributesIndexLabelActionMissing = errors.New(`resourceAttributes does not contain at least one attributed mapped to "index_label"`)
91-
// ErrOTLPAttributesSpecInvalid when the OTLPAttributesSpec attibutes and regex fields are both empty.
92-
ErrOTLPAttributesSpecInvalid = errors.New(`attributes and regex cannot be empty at the same time`)
87+
// ErrOTLPGlobalNoStreamLabel when the global OTLP configuration does not define at least one stream label.
88+
ErrOTLPGlobalNoStreamLabel = errors.New("global OTLP configuration needs to define at least one stream label")
89+
// ErrOTLPTenantMissing when a tenant is missing from the OTLP configuration although it has been defined in the tenancy.
90+
ErrOTLPTenantMissing = errors.New("if no global OTLP configuration is present which defines at least one stream label, every tenant must have an OTLP configuration")
91+
// ErrOTLPTenantNoStreamLabel when a tenant is defined but has no stream labels and there also no global stream labels.
92+
ErrOTLPTenantNoStreamLabel = errors.New("if no global OTLP configuration is present which defines at least one stream label, every tenant must define at least one stream label")
9393

9494
// ErrRuleMustMatchNamespace indicates that an expression used in an alerting or recording rule is missing
9595
// matchers for a namespace.

0 commit comments

Comments
 (0)