Skip to content

Commit 6049ced

Browse files
author
Israel Blancas
committed
Merge branch 'bug/3281' of github.com:iblancasa/opentelemetry-operator into bug/3281
2 parents 32264b6 + 11a2258 commit 6049ced

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1640
-487
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: 'breaking'
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: auto-instrumentation
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Enable multi instrumentation by default.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3090]
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: |
17+
Starting with this release, the OpenTelemetry Operator now enables multi-instrumentation by default.
18+
This enhancement allows instrumentation of multiple containers in a pod with language-specific configurations.|
19+
Key Changes:
20+
- Single Instrumentation (Default Behavior): If no container names are specified using the
21+
`instrumentation.opentelemetry.io/container-names` annotation, instrumentation will be applied to the first container in
22+
the pod spec by default. This only applies when single instrumentation injection is configured.
23+
- Multi-Container Pods: In scenarios where different containers in a pod use distinct technologies, users must specify the
24+
container(s) for instrumentation using language-specific annotations. Without this specification, the default behavior may
25+
not work as expected for multi-container environments.
26+
Compatibility:
27+
- Users already utilizing the `instrumentation.opentelemetry.io/container-names` annotation do not need to take any action.
28+
Their existing setup will continue to function as before.
29+
- Important: Users who attempt to configure both `instrumentation.opentelemetry.io/container-names` and language-specific annotations
30+
(for multi-instrumentation) simultaneously will encounter an error, as this configuration is not supported.

.chloggen/container-names.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: bug_fix
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: auto-instrumentation
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Fix ApacheHttpd, Nginx and SDK injectors to honour their container-names annotations.
9+
10+
# One or more tracking issues related to the change
11+
issues: [3313]
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: This is a breaking change if anyone is accidentally using the enablement flag with container names for these 3 injectors.

.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:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
change_type: enhancement
2+
3+
component: auto-instrumentation
4+
5+
note: Add support for k8s labels such as app.kubernetes.io/name for resource attributes
6+
7+
issues: [3112]
8+
9+
subtext: |
10+
You can opt-in as follows:
11+
```yaml
12+
apiVersion: opentelemetry.io/v1alpha1
13+
kind: Instrumentation
14+
metadata:
15+
name: my-instrumentation
16+
spec:
17+
defaults:
18+
useLabelsForResourceAttributes: true
19+
```
20+
The following labels are supported:
21+
- `app.kubernetes.io/name` becomes `service.name`
22+
- `app.kubernetes.io/version` becomes `service.version`
23+
- `app.kubernetes.io/part-of` becomes `service.namespace`
24+
- `app.kubernetes.io/instance` becomes `service.instance.id`

.github/workflows/e2e.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- group: e2e-instrumentation
3939
setup: "add-instrumentation-params prepare-e2e"
4040
- group: e2e-multi-instrumentation
41-
setup: "add-multi-instrumentation-params prepare-e2e"
41+
setup: "add-instrumentation-params prepare-e2e"
4242
- group: e2e-metadata-filters
4343
setup: "add-operator-arg OPERATOR_ARG='--annotations-filter=.*filter.out --annotations-filter=config.*.gke.io.* --labels-filter=.*filter.out' prepare-e2e"
4444
- group: e2e-automatic-rbac

README.md

+56-2
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,9 @@ spec:
717717
EOF
718718
```
719719

720-
### Setting instrumentation resource attributes via namespace annotations
720+
## Configure resource attributes
721+
722+
### Configure resource attributes with annotations
721723

722724
This example shows a pod configuration with OpenTelemetry annotations using the `resource.opentelemetry.io/` prefix. These annotations can be used to add resource attributes to data produced by OpenTelemetry instrumentation.
723725

@@ -734,7 +736,59 @@ spec:
734736
containers:
735737
- name: main-container
736738
image: your-image:tag
737-
```
739+
```
740+
741+
### Configure resource attributes with labels
742+
743+
You can also use common labels to set resource attributes.
744+
745+
The following labels are supported:
746+
- `app.kubernetes.io/name` becomes `service.name`
747+
- `app.kubernetes.io/version` becomes `service.version`
748+
- `app.kubernetes.io/part-of` becomes `service.namespace`
749+
- `app.kubernetes.io/instance` becomes `service.instance.id`
750+
751+
```yaml
752+
apiVersion: v1
753+
kind: Pod
754+
metadata:
755+
name: example-pod
756+
labels:
757+
app.kubernetes.io/name: "my-service"
758+
app.kubernetes.io/version: "1.0.0"
759+
app.kubernetes.io/part-of: "shop"
760+
app.kubernetes.io/instance: "my-service-123"
761+
spec:
762+
containers:
763+
- name: main-container
764+
image: your-image:tag
765+
```
766+
767+
This requires an explicit opt-in as follows:
768+
769+
```yaml
770+
apiVersion: opentelemetry.io/v1alpha1
771+
kind: Instrumentation
772+
metadata:
773+
name: my-instrumentation
774+
spec:
775+
defaults:
776+
useLabelsForResourceAttributes: true
777+
```
778+
779+
### Priority for setting resource attributes
780+
781+
The priority for setting resource attributes is as follows (first found wins):
782+
783+
1. Resource attributes set via `OTEL_RESOURCE_ATTRIBUTES` and `OTEL_SERVICE_NAME` environment variables
784+
2. Resource attributes set via annotations (with the `resource.opentelemetry.io/` prefix)
785+
3. Resource attributes set via labels (e.g. `app.kubernetes.io/name`)
786+
if the `Instrumentation` CR has defaults.useLabelsForResourceAttributes=true (see above)
787+
4. Resource attributes calculated from the pod's metadata (e.g. `k8s.pod.name`)
788+
5. Resource attributes set via the `Instrumentation` CR (in the `spec.resource.resourceAttributes` section)
789+
790+
This priority is applied for each resource attribute separately, so it is possible to set some attributes via
791+
annotations and others via labels.
738792

739793
## Compatibility matrix
740794

apis/v1alpha1/instrumentation_types.go

+13
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ type InstrumentationSpec struct {
4040
// +optional
4141
Sampler `json:"sampler,omitempty"`
4242

43+
// Defaults defines default values for the instrumentation.
44+
Defaults Defaults `json:"defaults,omitempty"`
45+
4346
// Env defines common env vars. There are four layers for env vars' definitions and
4447
// the precedence order is: `original container env vars` > `language specific env vars` > `common env vars` > `instrument spec configs' vars`.
4548
// If the former var had been defined, then the other vars would be ignored.
@@ -114,6 +117,16 @@ type Sampler struct {
114117
Argument string `json:"argument,omitempty"`
115118
}
116119

120+
// Defaults defines default values for the instrumentation.
121+
type Defaults struct {
122+
// UseLabelsForResourceAttributes defines whether to use common labels for resource attributes:
123+
// - `app.kubernetes.io/name` becomes `service.name`
124+
// - `app.kubernetes.io/version` becomes `service.version`
125+
// - `app.kubernetes.io/part-of` becomes `service.namespace`
126+
// - `app.kubernetes.io/instance` becomes `service.instance.id`
127+
UseLabelsForResourceAttributes bool `json:"useLabelsForResourceAttributes,omitempty"`
128+
}
129+
117130
// Java defines Java SDK and instrumentation configuration.
118131
type Java struct {
119132
// Image is a container image with javaagent auto-instrumentation JAR.

apis/v1alpha1/zz_generated.deepcopy.go

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

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
}

0 commit comments

Comments
 (0)