Skip to content

Commit f95e6e4

Browse files
author
Israel Blancas
committed
Merge branch 'feature/3149' of github.com:iblancasa/opentelemetry-operator into feature/3149
2 parents c7dc6b6 + 8fa0f59 commit f95e6e4

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.
@@ -108,6 +110,7 @@ func (c *Config) GetEnabledComponents() map[ComponentKind]map[string]interface{}
108110
KindReceiver: {},
109111
KindProcessor: {},
110112
KindExporter: {},
113+
KindExtension: {},
111114
}
112115
for _, pipeline := range c.Service.Pipelines {
113116
if pipeline == nil {
@@ -123,6 +126,9 @@ func (c *Config) GetEnabledComponents() map[ComponentKind]map[string]interface{}
123126
toReturn[KindProcessor][componentId] = struct{}{}
124127
}
125128
}
129+
for _, componentId := range c.Service.Extensions {
130+
toReturn[KindExtension][componentId] = struct{}{}
131+
}
126132
return toReturn
127133
}
128134

@@ -162,6 +168,8 @@ func (c *Config) getRbacRulesForComponentKinds(logger logr.Logger, componentKind
162168
} else {
163169
cfg = *c.Processors
164170
}
171+
case KindExtension:
172+
continue
165173
}
166174
for componentName := range enabledComponents[componentKind] {
167175
// TODO: Clean up the naming here and make it simpler to use a retriever.
@@ -191,7 +199,9 @@ func (c *Config) getPortsForComponentKinds(logger logr.Logger, componentKinds ..
191199
retriever = exporters.ParserFor
192200
cfg = c.Exporters
193201
case KindProcessor:
194-
break
202+
continue
203+
case KindExtension:
204+
continue
195205
}
196206
for componentName := range enabledComponents[componentKind] {
197207
// TODO: Clean up the naming here and make it simpler to use a retriever.
@@ -227,6 +237,38 @@ func (c *Config) GetAllRbacRules(logger logr.Logger) ([]rbacv1.PolicyRule, error
227237
return c.getRbacRulesForComponentKinds(logger, KindReceiver, KindExporter, KindProcessor)
228238
}
229239

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

270312
type Service struct {
271-
Extensions *[]string `json:"extensions,omitempty" yaml:"extensions,omitempty"`
313+
Extensions []string `json:"extensions,omitempty" yaml:"extensions,omitempty"`
272314
// +kubebuilder:pruning:PreserveUnknownFields
273315
Telemetry *AnyConfig `json:"telemetry,omitempty" yaml:"telemetry,omitempty"`
274316
// +kubebuilder:pruning:PreserveUnknownFields

apis/v1beta1/config_test.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestConfigYaml(t *testing.T) {
143143
},
144144
},
145145
Service: Service{
146-
Extensions: &[]string{"addon"},
146+
Extensions: []string{"addon"},
147147
Telemetry: &AnyConfig{
148148
Object: map[string]interface{}{
149149
"insights": "yeah!",
@@ -304,6 +304,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
304304
"bar": struct{}{},
305305
"count": struct{}{},
306306
},
307+
KindExtension: {},
307308
},
308309
},
309310
{
@@ -321,6 +322,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
321322
KindExporter: {
322323
"prometheus": struct{}{},
323324
},
325+
KindExtension: {},
324326
},
325327
},
326328
{
@@ -339,6 +341,11 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
339341
"otlp": struct{}{},
340342
"prometheus": struct{}{},
341343
},
344+
KindExtension: {
345+
"health_check": struct{}{},
346+
"pprof": struct{}{},
347+
"zpages": struct{}{},
348+
},
342349
},
343350
},
344351
{
@@ -352,6 +359,9 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
352359
KindExporter: {
353360
"otlp/auth": struct{}{},
354361
},
362+
KindExtension: {
363+
"oauth2client": struct{}{},
364+
},
355365
},
356366
},
357367
{
@@ -365,6 +375,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
365375
KindExporter: {
366376
"debug": struct{}{},
367377
},
378+
KindExtension: {},
368379
},
369380
},
370381
{
@@ -374,6 +385,7 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
374385
KindReceiver: {},
375386
KindProcessor: {},
376387
KindExporter: {},
388+
KindExtension: {},
377389
},
378390
},
379391
}

0 commit comments

Comments
 (0)