Skip to content

Commit

Permalink
[chore] Move TargetAllocator CRD to v1alpha1
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Apr 27, 2024
1 parent 45bb65d commit 8ab25dd
Show file tree
Hide file tree
Showing 64 changed files with 1,146 additions and 1,017 deletions.
31 changes: 30 additions & 1 deletion apis/v1beta1/common.go → apis/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta1
// +kubebuilder:object:generate=true
// +groupName=opentelemetry.io
package common

import (
autoscalingv2 "k8s.io/api/autoscaling/v2"
Expand Down Expand Up @@ -94,6 +96,33 @@ type PortsSpec struct {
v1.ServicePort `json:",inline"`
}

// ObservabilitySpec defines how telemetry data gets handled.
type ObservabilitySpec struct {
// Metrics defines the metrics configuration for operands.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Metrics Config"
Metrics MetricsConfigSpec `json:"metrics,omitempty"`
}

// MetricsConfigSpec defines a metrics config.
type MetricsConfigSpec struct {
// EnableMetrics specifies if ServiceMonitor or PodMonitor(for sidecar mode) should be created for the service managed by the OpenTelemetry Operator.
// The operator.observability.prometheus feature gate must be enabled to use this feature.
//
// +optional
// +kubebuilder:validation:Optional
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Create ServiceMonitors for OpenTelemetry Collector"
EnableMetrics bool `json:"enableMetrics,omitempty"`
// DisablePrometheusAnnotations controls the automatic addition of default Prometheus annotations
// ('prometheus.io/scrape', 'prometheus.io/port', and 'prometheus.io/path')
//
// +optional
// +kubebuilder:validation:Optional
DisablePrometheusAnnotations bool `json:"disablePrometheusAnnotations,omitempty"`
}

type OpenTelemetryCommonFields struct {
// ManagementState defines if the CR should be managed by the operator or not.
// Default is managed.
Expand Down
4 changes: 2 additions & 2 deletions apis/v1beta1/config.go → apis/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta1
package common

import (
"bytes"
Expand Down Expand Up @@ -102,7 +102,7 @@ func (c *Config) Yaml() (string, error) {
}

// Returns null objects in the config.
func (c *Config) nullObjects() []string {
func (c *Config) NullObjects() []string {
var nullKeys []string
if nulls := hasNullValue(c.Receivers.Object); len(nulls) > 0 {
nullKeys = append(nullKeys, addPrefix("receivers.", nulls)...)
Expand Down
6 changes: 3 additions & 3 deletions apis/v1beta1/config_test.go → apis/common/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package v1beta1
package common

import (
"encoding/json"
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestNullObjects(t *testing.T) {
err = json.Unmarshal(collectorJson, cfg)
require.NoError(t, err)

nullObjects := cfg.nullObjects()
nullObjects := cfg.NullObjects()
assert.Equal(t, []string{"connectors.spanmetrics:", "exporters.otlp.endpoint:", "extensions.health_check:", "processors.batch:", "receivers.otlp.protocols.grpc:", "receivers.otlp.protocols.http:"}, nullObjects)
}

Expand Down Expand Up @@ -107,7 +107,7 @@ func TestNullObjects_go_yaml(t *testing.T) {
err = go_yaml.Unmarshal(collectorYaml, cfg)
require.NoError(t, err)

nullObjects := cfg.nullObjects()
nullObjects := cfg.NullObjects()
assert.Equal(t, []string{"connectors.spanmetrics:", "exporters.otlp.endpoint:", "extensions.health_check:", "processors.batch:", "receivers.otlp.protocols.grpc:", "receivers.otlp.protocols.http:"}, nullObjects)
}

Expand Down
64 changes: 64 additions & 0 deletions apis/common/targetallocator_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package common

import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

type (
// TargetAllocatorAllocationStrategy represent a strategy Target Allocator uses to distribute targets to each collector
// +kubebuilder:validation:Enum=least-weighted;consistent-hashing;per-node
TargetAllocatorAllocationStrategy string
// TargetAllocatorFilterStrategy represent a filtering strategy for targets before they are assigned to collectors
// +kubebuilder:validation:Enum="";relabel-config
TargetAllocatorFilterStrategy string
)

const (
// TargetAllocatorAllocationStrategyLeastWeighted targets will be distributed to collector with fewer targets currently assigned.
TargetAllocatorAllocationStrategyLeastWeighted TargetAllocatorAllocationStrategy = "least-weighted"

// TargetAllocatorAllocationStrategyConsistentHashing targets will be consistently added to collectors, which allows a high-availability setup.
TargetAllocatorAllocationStrategyConsistentHashing TargetAllocatorAllocationStrategy = "consistent-hashing"

// TargetAllocatorAllocationStrategyPerNode targets will be assigned to the collector on the node they reside on (use only with daemon set).
TargetAllocatorAllocationStrategyPerNode TargetAllocatorAllocationStrategy = "per-node"

// TargetAllocatorFilterStrategyRelabelConfig targets will be consistently drops targets based on the relabel_config.
TargetAllocatorFilterStrategyRelabelConfig TargetAllocatorFilterStrategy = "relabel-config"
)

// TargetAllocatorPrometheusCR configures Prometheus CustomResource handling in the Target Allocator.
type TargetAllocatorPrometheusCR struct {
// Enabled indicates whether to use a PrometheusOperator custom resources as targets or not.
// +optional
Enabled bool `json:"enabled,omitempty"`
// Default interval between consecutive scrapes. Intervals set in ServiceMonitors and PodMonitors override it.
//Equivalent to the same setting on the Prometheus CR.
//
// Default: "30s"
// +kubebuilder:default:="30s"
// +kubebuilder:validation:Format:=duration
ScrapeInterval *metav1.Duration `json:"scrapeInterval,omitempty"`
// PodMonitors to be selected for target discovery.
// This is a map of {key,value} pairs. Each {key,value} in the map is going to exactly match a label in a
// PodMonitor's meta labels. The requirements are ANDed.
// +optional
PodMonitorSelector *metav1.LabelSelector `json:"podMonitorSelector,omitempty"`
// ServiceMonitors to be selected for target discovery.
// This is a map of {key,value} pairs. Each {key,value} in the map is going to exactly match a label in a
// ServiceMonitor's meta labels. The requirements are ANDed.
// +optional
ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"`
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 8ab25dd

Please sign in to comment.