Skip to content

Commit 4421cc0

Browse files
author
Israel Blancas
authored
Merge branch 'main' into node-import
2 parents 3b65d65 + 313ee2a commit 4421cc0

Some content is hidden

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

55 files changed

+1588
-121
lines changed
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: Inject environment K8S_NODE_NAME environment variable for the Kubelet Stats Receiver.
9+
10+
# One or more tracking issues related to the change
11+
issues: [2779]
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,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: 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: add config for installing musl based auto-instrumentation for Python
9+
10+
# One or more tracking issues related to the change
11+
issues: [2264]
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,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: 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: Support `http/json` and `http/protobuf` via OTEL_EXPORTER_OTLP_PROTOCOL environment variable in addition to default `grpc` for exporting traces
9+
10+
# One or more tracking issues related to the change
11+
issues: [3412]
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:

.chloggen/scrape-config-probe.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: target allocator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: enables support for pulling scrape config and probe CRDs in the target allocator
9+
10+
# One or more tracking issues related to the change
11+
issues: [1842]
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:

.github/workflows/e2e.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- e2e-pdb
3232
- e2e-prometheuscr
3333
- e2e-targetallocator
34+
- e2e-targetallocator-cr
3435
- e2e-upgrade
3536
- e2e-multi-instrumentation
3637
- e2e-metadata-filters
@@ -51,6 +52,8 @@ jobs:
5152
kube-version: "1.29"
5253
- group: e2e-targetallocator
5354
setup: "enable-targetallocator-cr prepare-e2e"
55+
- group: e2e-targetallocator-cr
56+
setup: "enable-targetallocator-cr prepare-e2e"
5457
steps:
5558
- name: Check out code into the Go module directory
5659
uses: actions/checkout@v4

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ e2e-prometheuscr: chainsaw
327327
e2e-targetallocator: chainsaw
328328
$(CHAINSAW) test --test-dir ./tests/e2e-targetallocator
329329

330+
# Target allocator CR end-to-tests
331+
.PHONY: e2e-targetallocator-cr
332+
e2e-targetallocator-cr: chainsaw
333+
$(CHAINSAW) test --test-dir ./tests/e2e-targetallocator-cr
334+
330335
.PHONY: add-certmanager-permissions
331336
add-certmanager-permissions:
332337
# Kustomize only allows patches in the folder where the kustomization is located

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,12 @@ instrumentation.opentelemetry.io/inject-nodejs: "true"
292292
```
293293

294294
Python:
295+
Python auto-instrumentation also honors an annotation that will permit it to run it on images with a different C library than glibc.
295296

296297
```bash
297298
instrumentation.opentelemetry.io/inject-python: "true"
299+
instrumentation.opentelemetry.io/otel-python-platform: "glibc" # for Linux glibc based images, this is the default value and can be omitted
300+
instrumentation.opentelemetry.io/otel-python-platform: "musl" # for Linux musl based images
298301
```
299302

300303
.NET:

apis/v1beta1/collector_webhook.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (c CollectorWebhook) ValidateCreate(ctx context.Context, obj runtime.Object
122122
c.metrics.create(ctx, otelcol)
123123
}
124124
if c.bv != nil {
125-
newWarnings := c.bv(*otelcol)
125+
newWarnings := c.bv(ctx, *otelcol)
126126
warnings = append(warnings, newWarnings...)
127127
}
128128
return warnings, nil
@@ -152,7 +152,7 @@ func (c CollectorWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj run
152152
}
153153

154154
if c.bv != nil {
155-
newWarnings := c.bv(*otelcol)
155+
newWarnings := c.bv(ctx, *otelcol)
156156
warnings = append(warnings, newWarnings...)
157157
}
158158
return warnings, nil
@@ -435,7 +435,7 @@ func checkAutoscalerSpec(autoscaler *AutoscalerSpec) error {
435435

436436
// BuildValidator enables running the manifest generators for the collector reconciler
437437
// +kubebuilder:object:generate=false
438-
type BuildValidator func(c OpenTelemetryCollector) admission.Warnings
438+
type BuildValidator func(ctx context.Context, c OpenTelemetryCollector) admission.Warnings
439439

440440
func NewCollectorWebhook(
441441
logger logr.Logger,

apis/v1beta1/collector_webhook_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestValidate(t *testing.T) {
8383
},
8484
}
8585

86-
bv := func(collector v1beta1.OpenTelemetryCollector) admission.Warnings {
86+
bv := func(_ context.Context, collector v1beta1.OpenTelemetryCollector) admission.Warnings {
8787
var warnings admission.Warnings
8888
cfg := config.New(
8989
config.WithCollectorImage("default-collector"),
@@ -518,7 +518,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
518518
},
519519
}
520520

521-
bv := func(collector v1beta1.OpenTelemetryCollector) admission.Warnings {
521+
bv := func(_ context.Context, collector v1beta1.OpenTelemetryCollector) admission.Warnings {
522522
var warnings admission.Warnings
523523
cfg := config.New(
524524
config.WithCollectorImage("default-collector"),
@@ -1365,7 +1365,7 @@ func TestOTELColValidatingWebhook(t *testing.T) {
13651365
},
13661366
}
13671367

1368-
bv := func(collector v1beta1.OpenTelemetryCollector) admission.Warnings {
1368+
bv := func(_ context.Context, collector v1beta1.OpenTelemetryCollector) admission.Warnings {
13691369
var warnings admission.Warnings
13701370
cfg := config.New(
13711371
config.WithCollectorImage("default-collector"),
@@ -1433,7 +1433,7 @@ func TestOTELColValidateUpdateWebhook(t *testing.T) {
14331433
},
14341434
}
14351435

1436-
bv := func(collector v1beta1.OpenTelemetryCollector) admission.Warnings {
1436+
bv := func(_ context.Context, collector v1beta1.OpenTelemetryCollector) admission.Warnings {
14371437
var warnings admission.Warnings
14381438
cfg := config.New(
14391439
config.WithCollectorImage("default-collector"),

apis/v1beta1/config.go

+40
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,42 @@ func (c *Config) getPortsForComponentKinds(logger logr.Logger, componentKinds ..
226226
return ports, nil
227227
}
228228

229+
// getEnvironmentVariablesForComponentKinds gets the environment variables for the given ComponentKind(s).
230+
func (c *Config) getEnvironmentVariablesForComponentKinds(logger logr.Logger, componentKinds ...ComponentKind) ([]corev1.EnvVar, error) {
231+
var envVars []corev1.EnvVar = []corev1.EnvVar{}
232+
enabledComponents := c.GetEnabledComponents()
233+
for _, componentKind := range componentKinds {
234+
var retriever components.ParserRetriever
235+
var cfg AnyConfig
236+
237+
switch componentKind {
238+
case KindReceiver:
239+
retriever = receivers.ReceiverFor
240+
cfg = c.Receivers
241+
case KindExporter:
242+
continue
243+
case KindProcessor:
244+
continue
245+
case KindExtension:
246+
continue
247+
}
248+
for componentName := range enabledComponents[componentKind] {
249+
parser := retriever(componentName)
250+
if parsedEnvVars, err := parser.GetEnvironmentVariables(logger, cfg.Object[componentName]); err != nil {
251+
return nil, err
252+
} else {
253+
envVars = append(envVars, parsedEnvVars...)
254+
}
255+
}
256+
}
257+
258+
sort.Slice(envVars, func(i, j int) bool {
259+
return envVars[i].Name < envVars[j].Name
260+
})
261+
262+
return envVars, nil
263+
}
264+
229265
// applyDefaultForComponentKinds applies defaults to the endpoints for the given ComponentKind(s).
230266
func (c *Config) applyDefaultForComponentKinds(logger logr.Logger, componentKinds ...ComponentKind) error {
231267
if err := c.Service.ApplyDefaults(); err != nil {
@@ -286,6 +322,10 @@ func (c *Config) GetAllPorts(logger logr.Logger) ([]corev1.ServicePort, error) {
286322
return c.getPortsForComponentKinds(logger, KindReceiver, KindExporter)
287323
}
288324

325+
func (c *Config) GetEnvironmentVariables(logger logr.Logger) ([]corev1.EnvVar, error) {
326+
return c.getEnvironmentVariablesForComponentKinds(logger, KindReceiver)
327+
}
328+
289329
func (c *Config) GetAllRbacRules(logger logr.Logger) ([]rbacv1.PolicyRule, error) {
290330
return c.getRbacRulesForComponentKinds(logger, KindReceiver, KindExporter, KindProcessor)
291331
}

apis/v1beta1/config_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,66 @@ func TestConfig_GetEnabledComponents(t *testing.T) {
423423
}
424424
}
425425

426+
func TestConfig_getEnvironmentVariablesForComponentKinds(t *testing.T) {
427+
tests := []struct {
428+
name string
429+
config *Config
430+
componentKinds []ComponentKind
431+
envVarsLen int
432+
}{
433+
{
434+
name: "no env vars",
435+
config: &Config{
436+
Receivers: AnyConfig{
437+
Object: map[string]interface{}{
438+
"myreceiver": map[string]interface{}{
439+
"env": "test",
440+
},
441+
},
442+
},
443+
Service: Service{
444+
Pipelines: map[string]*Pipeline{
445+
"test": {
446+
Receivers: []string{"myreceiver"},
447+
},
448+
},
449+
},
450+
},
451+
componentKinds: []ComponentKind{KindReceiver},
452+
envVarsLen: 0,
453+
},
454+
{
455+
name: "kubeletstats env vars",
456+
config: &Config{
457+
Receivers: AnyConfig{
458+
Object: map[string]interface{}{
459+
"kubeletstats": map[string]interface{}{},
460+
},
461+
},
462+
Service: Service{
463+
Pipelines: map[string]*Pipeline{
464+
"test": {
465+
Receivers: []string{"kubeletstats"},
466+
},
467+
},
468+
},
469+
},
470+
componentKinds: []ComponentKind{KindReceiver},
471+
envVarsLen: 1,
472+
},
473+
}
474+
475+
for _, tt := range tests {
476+
t.Run(tt.name, func(t *testing.T) {
477+
logger := logr.Discard()
478+
envVars, err := tt.config.GetEnvironmentVariables(logger)
479+
480+
assert.NoError(t, err)
481+
assert.Len(t, envVars, tt.envVarsLen)
482+
})
483+
}
484+
}
485+
426486
func TestConfig_GetReceiverPorts(t *testing.T) {
427487
tests := []struct {
428488
name string

autoinstrumentation/nodejs/src/autoinstrumentation.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
2-
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
2+
import { OTLPTraceExporter as OTLPProtoTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
3+
import { OTLPTraceExporter as OTLPHttpTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
4+
import { OTLPTraceExporter as OTLPGrpcTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
35
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-grpc';
46
import { PrometheusExporter } from '@opentelemetry/exporter-prometheus';
57
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
@@ -12,6 +14,22 @@ import { diag } from '@opentelemetry/api';
1214

1315
import { NodeSDK } from '@opentelemetry/sdk-node';
1416

17+
function getTraceExporter() {
18+
let protocol = process.env.OTEL_EXPORTER_OTLP_PROTOCOL;
19+
switch (protocol) {
20+
case undefined:
21+
case '':
22+
case 'grpc':
23+
return new OTLPGrpcTraceExporter();
24+
case 'http/json':
25+
return new OTLPHttpTraceExporter();
26+
case 'http/protobuf':
27+
return new OTLPProtoTraceExporter();
28+
default:
29+
throw Error(`Creating traces exporter based on "${protocol}" protocol (configured via environment variable OTEL_EXPORTER_OTLP_PROTOCOL) is not implemented!`);
30+
}
31+
}
32+
1533
function getMetricReader() {
1634
switch (process.env.OTEL_METRICS_EXPORTER) {
1735
case undefined:
@@ -35,7 +53,7 @@ function getMetricReader() {
3553
const sdk = new NodeSDK({
3654
autoDetectResources: true,
3755
instrumentations: [getNodeAutoInstrumentations()],
38-
traceExporter: new OTLPTraceExporter(),
56+
traceExporter: getTraceExporter(),
3957
metricReader: getMetricReader(),
4058
resourceDetectors:
4159
[

0 commit comments

Comments
 (0)