Skip to content

Commit d02f435

Browse files
feat(operator): Add support for Loki OTLP limits config (#13446)
Co-authored-by: Robert Jacob <rojacob@redhat.com>
1 parent 1b3ba53 commit d02f435

19 files changed

+3374
-3
lines changed

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

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,140 @@ type IngestionLimitSpec struct {
791791
PerStreamRateLimitBurst int32 `json:"perStreamRateLimitBurst,omitempty"`
792792
}
793793

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.
821+
//
822+
// +optional
823+
// +kubebuilder:validation:Optional
824+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Attribute Names"
825+
Attributes []string `json:"attributes,omitempty"`
826+
827+
// Regex allows choosing the attributes by matching a regular expression.
828+
//
829+
// +optional
830+
// +kubebuilder:validation:Optional
831+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Regular Expression"
832+
Regex string `json:"regex,omitempty"`
833+
}
834+
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,omitempty"`
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.
856+
//
857+
// +optional
858+
// +kubebuilder:validation:Optional
859+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Regular Expression"
860+
Regex string `json:"regex,omitempty"`
861+
}
862+
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.
870+
//
871+
// +optional
872+
// +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"`
875+
876+
// Attributes contains the configuration for resource attributes
877+
// to store them as index labels or structured metadata or drop them altogether.
878+
//
879+
// +optional
880+
// +kubebuilder:validation:Optional
881+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Attributes"
882+
Attributes []OTLPResourceAttributesConfigSpec `json:"attributes,omitempty"`
883+
}
884+
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 or structured metadata or drop them altogether.
891+
//
892+
// +optional
893+
// +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"`
898+
}
899+
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.
905+
//
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 index labels or 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"`
918+
919+
// LogAttributes contains the configuration for log attributes
920+
// to store them as index labels or structured metadata or drop them altogether.
921+
//
922+
// +optional
923+
// +kubebuilder:validation:Optional
924+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Log Attributes"
925+
LogAttributes []OTLPAttributesSpec `json:"logAttributes,omitempty"`
926+
}
927+
794928
// RetentionStreamSpec defines a log stream with separate retention time.
795929
type RetentionStreamSpec struct {
796930
// Days contains the number of days logs are kept.
@@ -844,6 +978,14 @@ type LimitsTemplateSpec struct {
844978
// +kubebuilder:validation:Optional
845979
QueryLimits *QueryLimitSpec `json:"queries,omitempty"`
846980

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.
984+
//
985+
// +optional
986+
// +kubebuilder:validation:Optional
987+
OTLP *GlobalOTLPSpec `json:"otlp,omitempty"`
988+
847989
// Retention defines how long logs are kept in storage.
848990
//
849991
// +optional
@@ -865,6 +1007,14 @@ type PerTenantLimitsTemplateSpec struct {
8651007
// +kubebuilder:validation:Optional
8661008
QueryLimits *PerTenantQueryLimitSpec `json:"queries,omitempty"`
8671009

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.
1013+
//
1014+
// +optional
1015+
// +kubebuilder:validation:Optional
1016+
OTLP *OTLPSpec `json:"otlp,omitempty"`
1017+
8681018
// Retention defines how long logs are kept in storage.
8691019
//
8701020
// +optional
@@ -1313,3 +1463,16 @@ func (t BlockedQueryTypes) String() string {
13131463

13141464
return strings.Join(res, ",")
13151465
}
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/apis/loki/v1/v1.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ 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`)
93+
8794
// ErrRuleMustMatchNamespace indicates that an expression used in an alerting or recording rule is missing
8895
// matchers for a namespace.
8996
ErrRuleMustMatchNamespace = errors.New("rule needs to have a matcher for the namespace")

‎operator/apis/loki/v1/zz_generated.deepcopy.go

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)