Skip to content

Commit a0c490e

Browse files
committed
initial commit for clusterobservability CRD
1 parent fa11ace commit a0c490e

27 files changed

+4607
-66
lines changed
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package v1alpha1
5+
6+
import (
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
)
9+
10+
// ObservabilitySignal represents the type of observability signal.
11+
// +kubebuilder:validation:Enum=logs;traces;metrics;profiles
12+
type ObservabilitySignal string
13+
14+
const (
15+
ObservabilitySignalLogs ObservabilitySignal = "logs"
16+
ObservabilitySignalTraces ObservabilitySignal = "traces"
17+
ObservabilitySignalMetrics ObservabilitySignal = "metrics"
18+
ObservabilitySignalProfiles ObservabilitySignal = "profiles"
19+
)
20+
21+
// OTLPHTTPExporter defines OTLP HTTP exporter configuration.
22+
// This structure mirrors the official OpenTelemetry Collector otlphttpexporter configuration.
23+
type OTLPHTTPExporter struct {
24+
// Endpoint is the target base URL to send data to (e.g., https://example.com:4318).
25+
// +optional
26+
Endpoint string `json:"endpoint,omitempty"`
27+
28+
// TracesEndpoint is the target URL to send trace data to (e.g., https://example.com:4318/v1/traces).
29+
// If this setting is present the endpoint setting is ignored for traces.
30+
// +optional
31+
TracesEndpoint string `json:"traces_endpoint,omitempty"`
32+
33+
// MetricsEndpoint is the target URL to send metric data to (e.g., https://example.com:4318/v1/metrics).
34+
// If this setting is present the endpoint setting is ignored for metrics.
35+
// +optional
36+
MetricsEndpoint string `json:"metrics_endpoint,omitempty"`
37+
38+
// LogsEndpoint is the target URL to send log data to (e.g., https://example.com:4318/v1/logs).
39+
// If this setting is present the endpoint setting is ignored for logs.
40+
// +optional
41+
LogsEndpoint string `json:"logs_endpoint,omitempty"`
42+
43+
// ProfilesEndpoint is the target URL to send profile data to (e.g., https://example.com:4318/v1/development/profiles).
44+
// If this setting is present the endpoint setting is ignored for profiles.
45+
// +optional
46+
ProfilesEndpoint string `json:"profiles_endpoint,omitempty"`
47+
48+
// TLS defines TLS configuration for the exporter.
49+
// +optional
50+
TLS *TLSConfig `json:"tls,omitempty"`
51+
52+
// Timeout is the HTTP request time limit (e.g., "30s", "1m"). Default is 30s.
53+
// +optional
54+
Timeout string `json:"timeout,omitempty"`
55+
56+
// ReadBufferSize for HTTP client. Default is 0.
57+
// +optional
58+
// +kubebuilder:validation:Minimum=0
59+
ReadBufferSize *int `json:"read_buffer_size,omitempty"`
60+
61+
// WriteBufferSize for HTTP client. Default is 512 * 1024.
62+
// +optional
63+
// +kubebuilder:validation:Minimum=0
64+
WriteBufferSize *int `json:"write_buffer_size,omitempty"`
65+
66+
// SendingQueue defines configuration for the sending queue.
67+
// +optional
68+
SendingQueue *SendingQueueConfig `json:"sending_queue,omitempty"`
69+
70+
// RetryOnFailure defines retry configuration for failed requests.
71+
// +optional
72+
RetryOnFailure *RetryConfig `json:"retry_on_failure,omitempty"`
73+
74+
// Encoding defines the encoding to use for the messages.
75+
// Valid options: proto, json. Default is proto.
76+
// +optional
77+
// +kubebuilder:validation:Enum=proto;json
78+
Encoding string `json:"encoding,omitempty"`
79+
80+
// Compression defines the compression algorithm to use.
81+
// By default gzip compression is enabled. Use "none" to disable.
82+
// +optional
83+
// +kubebuilder:validation:Enum=gzip;none;""
84+
Compression string `json:"compression,omitempty"`
85+
86+
// Headers defines additional headers to be sent with each request.
87+
// +optional
88+
Headers map[string]string `json:"headers,omitempty"`
89+
}
90+
91+
// TLSConfig defines TLS configuration for the OTLP HTTP exporter.
92+
// This mirrors the OpenTelemetry Collector configtls settings.
93+
type TLSConfig struct {
94+
// CAFile is the path to the CA certificate file for server verification.
95+
// +optional
96+
CAFile string `json:"ca_file,omitempty"`
97+
98+
// CertFile is the path to the client certificate file for mutual TLS.
99+
// +optional
100+
CertFile string `json:"cert_file,omitempty"`
101+
102+
// KeyFile is the path to the client private key file for mutual TLS.
103+
// +optional
104+
KeyFile string `json:"key_file,omitempty"`
105+
106+
// Insecure controls whether to use insecure transport. Default is false.
107+
// +optional
108+
Insecure bool `json:"insecure,omitempty"`
109+
110+
// ServerName for TLS handshake. If empty, uses the hostname from endpoint.
111+
// +optional
112+
ServerName string `json:"server_name,omitempty"`
113+
}
114+
115+
// SendingQueueConfig defines configuration for the sending queue.
116+
type SendingQueueConfig struct {
117+
// Enabled controls whether the queue is enabled. Default is true.
118+
// +optional
119+
Enabled *bool `json:"enabled,omitempty"`
120+
121+
// NumConsumers is the number of consumers that dequeue batches. Default is 10.
122+
// +optional
123+
// +kubebuilder:validation:Minimum=1
124+
NumConsumers *int `json:"num_consumers,omitempty"`
125+
126+
// QueueSize is the maximum number of batches allowed in queue at a given time. Default is 1000.
127+
// +optional
128+
// +kubebuilder:validation:Minimum=1
129+
QueueSize *int `json:"queue_size,omitempty"`
130+
}
131+
132+
// RetryConfig defines retry configuration for failed requests.
133+
type RetryConfig struct {
134+
// Enabled controls whether retry is enabled. Default is true.
135+
// +optional
136+
Enabled *bool `json:"enabled,omitempty"`
137+
138+
// InitialInterval is the initial retry interval (e.g., "5s"). Default is 5s.
139+
// +optional
140+
InitialInterval string `json:"initial_interval,omitempty"`
141+
142+
// RandomizationFactor is the randomization factor for retry intervals (e.g., "0.5"). Default is 0.5.
143+
// +optional
144+
RandomizationFactor string `json:"randomization_factor,omitempty"`
145+
146+
// Multiplier is the multiplier for retry intervals (e.g., "1.5"). Default is 1.5.
147+
// +optional
148+
Multiplier string `json:"multiplier,omitempty"`
149+
150+
// MaxInterval is the maximum retry interval (e.g., "30s"). Default is 30s.
151+
// +optional
152+
MaxInterval string `json:"max_interval,omitempty"`
153+
154+
// MaxElapsedTime is the maximum elapsed time for retries (e.g., "5m"). Default is 5m.
155+
// +optional
156+
MaxElapsedTime string `json:"max_elapsed_time,omitempty"`
157+
}
158+
159+
// ClusterObservabilitySpec defines the desired state of ClusterObservability.
160+
// This follows a simplified design using a single OTLP HTTP exporter for all signals.
161+
type ClusterObservabilitySpec struct {
162+
// Signals defines which observability signals to collect and export.
163+
// Must contain at least one signal type from: logs, traces, metrics, profiles
164+
// +required
165+
// +kubebuilder:validation:MinItems=1
166+
// +listType=set
167+
Signals []ObservabilitySignal `json:"signals"`
168+
169+
// Exporter defines the OTLP HTTP exporter configuration for all signals.
170+
// The collector will automatically append appropriate paths for each signal type.
171+
// +required
172+
Exporter OTLPHTTPExporter `json:"exporter"`
173+
}
174+
175+
// ClusterObservabilityConditionType represents the type of condition.
176+
type ClusterObservabilityConditionType string
177+
178+
const (
179+
// ClusterObservabilityConditionReady indicates whether the ClusterObservability is ready.
180+
ClusterObservabilityConditionReady ClusterObservabilityConditionType = "Ready"
181+
// ClusterObservabilityConditionConfigured indicates whether the ClusterObservability is configured.
182+
ClusterObservabilityConditionConfigured ClusterObservabilityConditionType = "Configured"
183+
// ClusterObservabilityConditionConflicted indicates that multiple ClusterObservability resources exist.
184+
ClusterObservabilityConditionConflicted ClusterObservabilityConditionType = "Conflicted"
185+
)
186+
187+
const (
188+
// ClusterObservabilityFinalizer is the finalizer used for ClusterObservability resources.
189+
ClusterObservabilityFinalizer = "clusterobservability.opentelemetry.io/finalizer"
190+
)
191+
192+
// ClusterObservabilityCondition represents a condition of a ClusterObservability.
193+
type ClusterObservabilityCondition struct {
194+
// Type of condition.
195+
// +required
196+
Type ClusterObservabilityConditionType `json:"type"`
197+
198+
// Status of the condition.
199+
// +required
200+
Status metav1.ConditionStatus `json:"status"`
201+
202+
// Last time the condition transitioned from one status to another.
203+
// +optional
204+
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
205+
206+
// The reason for the condition's last transition.
207+
// +optional
208+
Reason string `json:"reason,omitempty"`
209+
210+
// A human readable message indicating details about the transition.
211+
// +optional
212+
Message string `json:"message,omitempty"`
213+
214+
// ObservedGeneration represents the .metadata.generation that the condition was set based upon.
215+
// +optional
216+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
217+
}
218+
219+
// ClusterObservabilityStatus defines the observed state of ClusterObservability.
220+
type ClusterObservabilityStatus struct {
221+
// Conditions represent the latest available observations of the ClusterObservability state.
222+
// +optional
223+
// +listType=map
224+
// +listMapKey=type
225+
Conditions []ClusterObservabilityCondition `json:"conditions,omitempty"`
226+
227+
// ObservedGeneration is the most recent generation observed for this ClusterObservability.
228+
// It corresponds to the ClusterObservability's generation, which is updated on mutation
229+
// by the API Server.
230+
// +optional
231+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
232+
233+
// Phase represents the current phase of the ClusterObservability.
234+
// +optional
235+
Phase string `json:"phase,omitempty"`
236+
237+
// Message provides additional information about the current state.
238+
// +optional
239+
Message string `json:"message,omitempty"`
240+
241+
// ComponentsStatus provides status information about individual observability components.
242+
// +optional
243+
ComponentsStatus map[string]ComponentStatus `json:"componentsStatus,omitempty"`
244+
245+
// ConfigVersions tracks the version hashes of the configuration files used.
246+
// This enables detection of config changes when operator is upgraded.
247+
// +optional
248+
ConfigVersions map[string]string `json:"configVersions,omitempty"`
249+
}
250+
251+
// ComponentStatus represents the status of an individual component.
252+
type ComponentStatus struct {
253+
// Ready indicates whether the component is ready.
254+
// +optional
255+
Ready bool `json:"ready,omitempty"`
256+
257+
// Message provides additional information about the component status.
258+
// +optional
259+
Message string `json:"message,omitempty"`
260+
261+
// LastUpdated is the last time this status was updated.
262+
// +optional
263+
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
264+
}
265+
266+
// +kubebuilder:object:root=true
267+
// +kubebuilder:subresource:status
268+
// +kubebuilder:printcolumn:name="Signals",type="string",JSONPath=".spec.signals",description="Observability signals"
269+
// +kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".spec.exporter.endpoint",description="OTLP exporter endpoint"
270+
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Current phase"
271+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
272+
// +operator-sdk:csv:customresourcedefinitions:displayName="Cluster Observability"
273+
// +operator-sdk:csv:customresourcedefinitions:resources={{Pod,v1},{Deployment,apps/v1},{ConfigMap,v1},{Service,v1},{DaemonSet,apps/v1}}
274+
275+
// ClusterObservability is the Schema for the clusterobservabilities API.
276+
type ClusterObservability struct {
277+
metav1.TypeMeta `json:",inline"`
278+
metav1.ObjectMeta `json:"metadata,omitempty"`
279+
280+
Spec ClusterObservabilitySpec `json:"spec,omitempty"`
281+
Status ClusterObservabilityStatus `json:"status,omitempty"`
282+
}
283+
284+
// +kubebuilder:object:root=true
285+
286+
// ClusterObservabilityList contains a list of ClusterObservability.
287+
type ClusterObservabilityList struct {
288+
metav1.TypeMeta `json:",inline"`
289+
metav1.ListMeta `json:"metadata,omitempty"`
290+
Items []ClusterObservability `json:"items"`
291+
}
292+
293+
func init() {
294+
SchemeBuilder.Register(&ClusterObservability{}, &ClusterObservabilityList{})
295+
}

0 commit comments

Comments
 (0)