Skip to content

Commit bff339f

Browse files
author
Israel Blancas
authored
Merge branch 'main' into bug/3281
2 parents 8d63442 + 94249dc commit bff339f

19 files changed

+853
-431
lines changed

.chloggen/improve-probe-parsing.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: collector
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Improves healthcheck parsing capabilities, allowing for future extensions to configure a healthcheck other than the v1 healthcheck extension.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3184]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

apis/v1beta1/config.go

+45-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"github.com/open-telemetry/opentelemetry-operator/internal/components"
3333
"github.com/open-telemetry/opentelemetry-operator/internal/components/exporters"
34+
"github.com/open-telemetry/opentelemetry-operator/internal/components/extensions"
3435
"github.com/open-telemetry/opentelemetry-operator/internal/components/processors"
3536
"github.com/open-telemetry/opentelemetry-operator/internal/components/receivers"
3637
)
@@ -41,10 +42,11 @@ const (
4142
KindReceiver ComponentKind = iota
4243
KindExporter
4344
KindProcessor
45+
KindExtension
4446
)
4547

4648
func (c ComponentKind) String() string {
47-
return [...]string{"receiver", "exporter", "processor"}[c]
49+
return [...]string{"receiver", "exporter", "processor", "extension"}[c]
4850
}
4951

5052
// AnyConfig represent parts of the config.
@@ -114,6 +116,7 @@ func (c *Config) GetEnabledComponents() map[ComponentKind]map[string]interface{}
114116
KindReceiver: {},
115117
KindProcessor: {},
116118
KindExporter: {},
119+
KindExtension: {},
117120
}
118121
for _, pipeline := range c.Service.Pipelines {
119122
if pipeline == nil {
@@ -129,6 +132,9 @@ func (c *Config) GetEnabledComponents() map[ComponentKind]map[string]interface{}
129132
toReturn[KindProcessor][componentId] = struct{}{}
130133
}
131134
}
135+
for _, componentId := range c.Service.Extensions {
136+
toReturn[KindExtension][componentId] = struct{}{}
137+
}
132138
return toReturn
133139
}
134140

@@ -168,6 +174,8 @@ func (c *Config) getRbacRulesForComponentKinds(logger logr.Logger, componentKind
168174
} else {
169175
cfg = *c.Processors
170176
}
177+
case KindExtension:
178+
continue
171179
}
172180
for componentName := range enabledComponents[componentKind] {
173181
// TODO: Clean up the naming here and make it simpler to use a retriever.
@@ -197,7 +205,9 @@ func (c *Config) getPortsForComponentKinds(logger logr.Logger, componentKinds ..
197205
retriever = exporters.ParserFor
198206
cfg = c.Exporters
199207
case KindProcessor:
200-
break
208+
continue
209+
case KindExtension:
210+
continue
201211
}
202212
for componentName := range enabledComponents[componentKind] {
203213
// TODO: Clean up the naming here and make it simpler to use a retriever.
@@ -233,6 +243,38 @@ func (c *Config) GetAllRbacRules(logger logr.Logger) ([]rbacv1.PolicyRule, error
233243
return c.getRbacRulesForComponentKinds(logger, KindReceiver, KindExporter, KindProcessor)
234244
}
235245

246+
// GetLivenessProbe gets the first enabled liveness probe. There should only ever be one extension enabled
247+
// that provides the hinting for the liveness probe.
248+
func (c *Config) GetLivenessProbe(logger logr.Logger) (*corev1.Probe, error) {
249+
enabledComponents := c.GetEnabledComponents()
250+
for componentName := range enabledComponents[KindExtension] {
251+
// TODO: Clean up the naming here and make it simpler to use a retriever.
252+
parser := extensions.ParserFor(componentName)
253+
if probe, err := parser.GetLivenessProbe(logger, c.Extensions.Object[componentName]); err != nil {
254+
return nil, err
255+
} else if probe != nil {
256+
return probe, nil
257+
}
258+
}
259+
return nil, nil
260+
}
261+
262+
// GetReadinessProbe gets the first enabled readiness probe. There should only ever be one extension enabled
263+
// that provides the hinting for the readiness probe.
264+
func (c *Config) GetReadinessProbe(logger logr.Logger) (*corev1.Probe, error) {
265+
enabledComponents := c.GetEnabledComponents()
266+
for componentName := range enabledComponents[KindExtension] {
267+
// TODO: Clean up the naming here and make it simpler to use a retriever.
268+
parser := extensions.ParserFor(componentName)
269+
if probe, err := parser.GetReadinessProbe(logger, c.Extensions.Object[componentName]); err != nil {
270+
return nil, err
271+
} else if probe != nil {
272+
return probe, nil
273+
}
274+
}
275+
return nil, nil
276+
}
277+
236278
// Yaml encodes the current object and returns it as a string.
237279
func (c *Config) Yaml() (string, error) {
238280
var buf bytes.Buffer
@@ -295,7 +337,7 @@ func (c *Config) nullObjects() []string {
295337
}
296338

297339
type Service struct {
298-
Extensions *[]string `json:"extensions,omitempty" yaml:"extensions,omitempty"`
340+
Extensions []string `json:"extensions,omitempty" yaml:"extensions,omitempty"`
299341
// +kubebuilder:pruning:PreserveUnknownFields
300342
Telemetry *AnyConfig `json:"telemetry,omitempty" yaml:"telemetry,omitempty"`
301343
// +kubebuilder:pruning:PreserveUnknownFields

apis/v1beta1/config_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func TestConfigYaml(t *testing.T) {
363363
},
364364
},
365365
Service: Service{
366-
Extensions: &[]string{"addon"},
366+
Extensions: []string{"addon"},
367367
Telemetry: &AnyConfig{
368368
Object: map[string]interface{}{
369369
"insights": "yeah!",
@@ -524,6 +524,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
524524
"bar": struct{}{},
525525
"count": struct{}{},
526526
},
527+
KindExtension: {},
527528
},
528529
},
529530
{
@@ -541,6 +542,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
541542
KindExporter: {
542543
"prometheus": struct{}{},
543544
},
545+
KindExtension: {},
544546
},
545547
},
546548
{
@@ -559,6 +561,11 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
559561
"otlp": struct{}{},
560562
"prometheus": struct{}{},
561563
},
564+
KindExtension: {
565+
"health_check": struct{}{},
566+
"pprof": struct{}{},
567+
"zpages": struct{}{},
568+
},
562569
},
563570
},
564571
{
@@ -572,6 +579,9 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
572579
KindExporter: {
573580
"otlp/auth": struct{}{},
574581
},
582+
KindExtension: {
583+
"oauth2client": struct{}{},
584+
},
575585
},
576586
},
577587
{
@@ -585,6 +595,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
585595
KindExporter: {
586596
"debug": struct{}{},
587597
},
598+
KindExtension: {},
588599
},
589600
},
590601
{
@@ -594,6 +605,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
594605
KindReceiver: {},
595606
KindProcessor: {},
596607
KindExporter: {},
608+
KindExtension: {},
597609
},
598610
},
599611
}

apis/v1beta1/zz_generated.deepcopy.go

+2-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/components/builder.go

+30-9
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ import (
2626
type ParserOption[ComponentConfigType any] func(*Settings[ComponentConfigType])
2727

2828
type Settings[ComponentConfigType any] struct {
29-
protocol corev1.Protocol
30-
appProtocol *string
31-
targetPort intstr.IntOrString
32-
nodePort int32
33-
name string
34-
port int32
35-
portParser PortParser[ComponentConfigType]
36-
rbacGen RBACRuleGenerator[ComponentConfigType]
29+
protocol corev1.Protocol
30+
appProtocol *string
31+
targetPort intstr.IntOrString
32+
nodePort int32
33+
name string
34+
port int32
35+
portParser PortParser[ComponentConfigType]
36+
rbacGen RBACRuleGenerator[ComponentConfigType]
37+
livenessGen ProbeGenerator[ComponentConfigType]
38+
readinessGen ProbeGenerator[ComponentConfigType]
3739
}
3840

3941
func NewEmptySettings[ComponentConfigType any]() *Settings[ComponentConfigType] {
@@ -104,13 +106,32 @@ func (b Builder[ComponentConfigType]) WithRbacGen(rbacGen RBACRuleGenerator[Comp
104106
})
105107
}
106108

109+
func (b Builder[ComponentConfigType]) WithLivenessGen(livenessGen ProbeGenerator[ComponentConfigType]) Builder[ComponentConfigType] {
110+
return append(b, func(o *Settings[ComponentConfigType]) {
111+
o.livenessGen = livenessGen
112+
})
113+
}
114+
115+
func (b Builder[ComponentConfigType]) WithReadinessGen(readinessGen ProbeGenerator[ComponentConfigType]) Builder[ComponentConfigType] {
116+
return append(b, func(o *Settings[ComponentConfigType]) {
117+
o.readinessGen = readinessGen
118+
})
119+
}
120+
107121
func (b Builder[ComponentConfigType]) Build() (*GenericParser[ComponentConfigType], error) {
108122
o := NewEmptySettings[ComponentConfigType]()
109123
o.Apply(b...)
110124
if len(o.name) == 0 {
111125
return nil, fmt.Errorf("invalid settings struct, no name specified")
112126
}
113-
return &GenericParser[ComponentConfigType]{name: o.name, portParser: o.portParser, rbacGen: o.rbacGen, settings: o}, nil
127+
return &GenericParser[ComponentConfigType]{
128+
name: o.name,
129+
portParser: o.portParser,
130+
rbacGen: o.rbacGen,
131+
livenessGen: o.livenessGen,
132+
readinessGen: o.readinessGen,
133+
settings: o,
134+
}, nil
114135
}
115136

116137
func (b Builder[ComponentConfigType]) MustBuild() *GenericParser[ComponentConfigType] {

0 commit comments

Comments
 (0)