Skip to content

Commit d241f7f

Browse files
committed
Merge branch 'main' of github.com:open-telemetry/opentelemetry-operator into 2603-part-two
2 parents 0038aa3 + ad0f1f9 commit d241f7f

20 files changed

+102
-106
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: 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: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: change java instrumentation feature gate operator.autoinstrumentation.java into command line flag --enable-java-instrumentation
9+
10+
# One or more tracking issues related to the change
11+
issues: [2673, 2582]
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: 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: 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: Remove `operator.collector.rewritetargetallocator` feature flag
9+
10+
# One or more tracking issues related to the change
11+
issues: [2796]
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/v1alpha1/collector_webhook.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/open-telemetry/opentelemetry-operator/internal/config"
3333
ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
3434
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
35-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3635
)
3736

3837
var (
@@ -365,7 +364,7 @@ func (c CollectorWebhook) validateTargetAllocatorConfig(ctx context.Context, r *
365364
if err != nil {
366365
return nil, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
367366
}
368-
err = ta.ValidatePromConfig(promCfg, r.Spec.TargetAllocator.Enabled, featuregate.EnableTargetAllocatorRewrite.IsEnabled())
367+
err = ta.ValidatePromConfig(promCfg, r.Spec.TargetAllocator.Enabled)
369368
if err != nil {
370369
return nil, fmt.Errorf("the OpenTelemetry Spec Prometheus configuration is incorrect, %w", err)
371370
}

apis/v1beta1/allocation_strategy.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package v1beta1
1616

1717
type (
1818
// TargetAllocatorAllocationStrategy represent a strategy Target Allocator uses to distribute targets to each collector
19-
// +kubebuilder:validation:Enum=least-weighted;consistent-hashing
19+
// +kubebuilder:validation:Enum=least-weighted;consistent-hashing;per-node
2020
TargetAllocatorAllocationStrategy string
2121
// TargetAllocatorFilterStrategy represent a filtering strategy for targets before they are assigned to collectors
2222
// +kubebuilder:validation:Enum="";relabel-config
@@ -30,6 +30,9 @@ const (
3030
// TargetAllocatorAllocationStrategyConsistentHashing targets will be consistently added to collectors, which allows a high-availability setup.
3131
TargetAllocatorAllocationStrategyConsistentHashing TargetAllocatorAllocationStrategy = "consistent-hashing"
3232

33+
// TargetAllocatorAllocationStrategyPerNode targets will be assigned to the collector on the node they reside on (use only with daemon set).
34+
TargetAllocatorAllocationStrategyPerNode TargetAllocatorAllocationStrategy = "per-node"
35+
3336
// TargetAllocatorFilterStrategyRelabelConfig targets will be consistently drops targets based on the relabel_config.
3437
TargetAllocatorFilterStrategyRelabelConfig TargetAllocatorFilterStrategy = "relabel-config"
3538
)

bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -7146,6 +7146,7 @@ spec:
71467146
enum:
71477147
- least-weighted
71487148
- consistent-hashing
7149+
- per-node
71497150
type: string
71507151
enabled:
71517152
type: boolean

config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -7132,6 +7132,7 @@ spec:
71327132
enum:
71337133
- least-weighted
71347134
- consistent-hashing
7135+
- per-node
71357136
type: string
71367137
enabled:
71377138
type: boolean

config/crd/bases/opentelemetry.io_targetallocators.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ spec:
10721072
enum:
10731073
- least-weighted
10741074
- consistent-hashing
1075+
- per-node
10751076
type: string
10761077
args:
10771078
additionalProperties:

docs/api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40460,7 +40460,7 @@ The current options are least-weighted, consistent-hashing and per-node. The def
4046040460
consistent-hashing.
4046140461
WARNING: The per-node strategy currently ignores targets without a Node, like control plane components.<br/>
4046240462
<br/>
40463-
<i>Enum</i>: least-weighted, consistent-hashing<br/>
40463+
<i>Enum</i>: least-weighted, consistent-hashing, per-node<br/>
4046440464
<i>Default</i>: consistent-hashing<br/>
4046540465
</td>
4046640466
<td>false</td>

internal/config/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Config struct {
4949
enableDotNetInstrumentation bool
5050
enableNginxInstrumentation bool
5151
enablePythonInstrumentation bool
52+
enableJavaInstrumentation bool
5253
autoInstrumentationDotNetImage string
5354
autoInstrumentationGoImage string
5455
autoInstrumentationApacheHttpdImage string
@@ -74,6 +75,7 @@ func New(opts ...Option) Config {
7475
operatorOpAMPBridgeConfigMapEntry: defaultOperatorOpAMPBridgeConfigMapEntry,
7576
logger: logf.Log.WithName("config"),
7677
version: version.Get(),
78+
enableJavaInstrumentation: true,
7779
}
7880
for _, opt := range opts {
7981
opt(&o)
@@ -89,6 +91,7 @@ func New(opts ...Option) Config {
8991
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
9092
enableNginxInstrumentation: o.enableNginxInstrumentation,
9193
enablePythonInstrumentation: o.enablePythonInstrumentation,
94+
enableJavaInstrumentation: o.enableJavaInstrumentation,
9295
targetAllocatorImage: o.targetAllocatorImage,
9396
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
9497
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
@@ -151,6 +154,11 @@ func (c *Config) EnableNginxAutoInstrumentation() bool {
151154
return c.enableNginxInstrumentation
152155
}
153156

157+
// EnableJavaAutoInstrumentation is true when the operator supports nginx auto instrumentation.
158+
func (c *Config) EnableJavaAutoInstrumentation() bool {
159+
return c.enableJavaInstrumentation
160+
}
161+
154162
// EnablePythonAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
155163
func (c *Config) EnablePythonAutoInstrumentation() bool {
156164
return c.enablePythonInstrumentation

internal/config/options.go

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type options struct {
4848
enableDotNetInstrumentation bool
4949
enableNginxInstrumentation bool
5050
enablePythonInstrumentation bool
51+
enableJavaInstrumentation bool
5152
targetAllocatorConfigMapEntry string
5253
operatorOpAMPBridgeConfigMapEntry string
5354
targetAllocatorImage string
@@ -108,6 +109,11 @@ func WithEnableNginxInstrumentation(s bool) Option {
108109
o.enableNginxInstrumentation = s
109110
}
110111
}
112+
func WithEnableJavaInstrumentation(s bool) Option {
113+
return func(o *options) {
114+
o.enableJavaInstrumentation = s
115+
}
116+
}
111117
func WithEnablePythonInstrumentation(s bool) Option {
112118
return func(o *options) {
113119
o.enablePythonInstrumentation = s

internal/manifests/collector/config_replace.go

+8-28
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters"
2626
ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
2727
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
28-
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
2928
)
3029

3130
type targetAllocator struct {
@@ -62,43 +61,24 @@ func ReplaceConfig(instance v1beta1.OpenTelemetryCollector) (string, error) {
6261
return "", getCfgPromErr
6362
}
6463

65-
validateCfgPromErr := ta.ValidatePromConfig(promCfgMap, instance.Spec.TargetAllocator.Enabled, featuregate.EnableTargetAllocatorRewrite.IsEnabled())
64+
validateCfgPromErr := ta.ValidatePromConfig(promCfgMap, instance.Spec.TargetAllocator.Enabled)
6665
if validateCfgPromErr != nil {
6766
return "", validateCfgPromErr
6867
}
6968

70-
if featuregate.EnableTargetAllocatorRewrite.IsEnabled() {
71-
// To avoid issues caused by Prometheus validation logic, which fails regex validation when it encounters
72-
// $$ in the prom config, we update the YAML file directly without marshaling and unmarshalling.
73-
updPromCfgMap, getCfgPromErr := ta.AddTAConfigToPromConfig(promCfgMap, naming.TAService(instance.Name))
74-
if getCfgPromErr != nil {
75-
return "", getCfgPromErr
76-
}
77-
78-
// type coercion checks are handled in the AddTAConfigToPromConfig method above
79-
config["receivers"].(map[interface{}]interface{})["prometheus"] = updPromCfgMap
80-
81-
out, updCfgMarshalErr := yaml.Marshal(config)
82-
if updCfgMarshalErr != nil {
83-
return "", updCfgMarshalErr
84-
}
85-
return string(out), nil
86-
}
87-
8869
// To avoid issues caused by Prometheus validation logic, which fails regex validation when it encounters
8970
// $$ in the prom config, we update the YAML file directly without marshaling and unmarshalling.
90-
updPromCfgMap, err := ta.AddHTTPSDConfigToPromConfig(promCfgMap, naming.TAService(instance.Name))
91-
if err != nil {
92-
return "", err
71+
updPromCfgMap, getCfgPromErr := ta.AddTAConfigToPromConfig(promCfgMap, naming.TAService(instance.Name))
72+
if getCfgPromErr != nil {
73+
return "", getCfgPromErr
9374
}
9475

95-
// To avoid issues caused by Prometheus validation logic, which fails regex validation when it encounters
96-
// type coercion checks are handled in the ConfigToPromConfig method above
76+
// type coercion checks are handled in the AddTAConfigToPromConfig method above
9777
config["receivers"].(map[interface{}]interface{})["prometheus"] = updPromCfgMap
9878

99-
out, err := yaml.Marshal(config)
100-
if err != nil {
101-
return "", err
79+
out, updCfgMarshalErr := yaml.Marshal(config)
80+
if updCfgMarshalErr != nil {
81+
return "", updCfgMarshalErr
10282
}
10383

10484
return string(out), nil

internal/manifests/targetallocator/adapters/config_to_prom_config.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package adapters
1616

1717
import (
18-
"errors"
1918
"fmt"
2019
"net/url"
2120
"regexp"
@@ -297,20 +296,12 @@ func AddTAConfigToPromConfig(prometheus map[interface{}]interface{}, taServiceNa
297296
}
298297

299298
// ValidatePromConfig checks if the prometheus receiver config is valid given other collector-level settings.
300-
func ValidatePromConfig(config map[interface{}]interface{}, targetAllocatorEnabled bool, targetAllocatorRewriteEnabled bool) error {
299+
func ValidatePromConfig(config map[interface{}]interface{}, targetAllocatorEnabled bool) error {
300+
// TODO: Rethink this validation, now that target allocator rewrite is enabled permanently.
301+
301302
_, promConfigExists := config["config"]
302303

303304
if targetAllocatorEnabled {
304-
if targetAllocatorRewriteEnabled { // if rewrite is enabled, we will add a target_allocator section during rewrite
305-
return nil
306-
}
307-
_, targetAllocatorExists := config["target_allocator"]
308-
309-
// otherwise, either the target_allocator or config section needs to be here
310-
if !(promConfigExists || targetAllocatorExists) {
311-
return errors.New("either target allocator or prometheus config needs to be present")
312-
}
313-
314305
return nil
315306
}
316307
// if target allocator isn't enabled, we need a config section

internal/manifests/targetallocator/adapters/config_to_prom_config_test.go

+19-33
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package adapters_test
1616

1717
import (
18-
"errors"
1918
"fmt"
2019
"net/url"
2120
"reflect"
@@ -302,66 +301,53 @@ func TestAddTAConfigToPromConfig(t *testing.T) {
302301

303302
func TestValidatePromConfig(t *testing.T) {
304303
testCases := []struct {
305-
description string
306-
config map[interface{}]interface{}
307-
targetAllocatorEnabled bool
308-
targetAllocatorRewriteEnabled bool
309-
expectedError error
304+
description string
305+
config map[interface{}]interface{}
306+
targetAllocatorEnabled bool
307+
expectedError error
310308
}{
311309
{
312-
description: "target_allocator and rewrite enabled",
313-
config: map[interface{}]interface{}{},
314-
targetAllocatorEnabled: true,
315-
targetAllocatorRewriteEnabled: true,
316-
expectedError: nil,
310+
description: "target_allocator enabled",
311+
config: map[interface{}]interface{}{},
312+
targetAllocatorEnabled: true,
313+
expectedError: nil,
317314
},
318315
{
319316
description: "target_allocator enabled, target_allocator section present",
320317
config: map[interface{}]interface{}{
321318
"target_allocator": map[interface{}]interface{}{},
322319
},
323-
targetAllocatorEnabled: true,
324-
targetAllocatorRewriteEnabled: false,
325-
expectedError: nil,
320+
targetAllocatorEnabled: true,
321+
expectedError: nil,
326322
},
327323
{
328324
description: "target_allocator enabled, config section present",
329325
config: map[interface{}]interface{}{
330326
"config": map[interface{}]interface{}{},
331327
},
332-
targetAllocatorEnabled: true,
333-
targetAllocatorRewriteEnabled: false,
334-
expectedError: nil,
335-
},
336-
{
337-
description: "target_allocator enabled, neither section present",
338-
config: map[interface{}]interface{}{},
339-
targetAllocatorEnabled: true,
340-
targetAllocatorRewriteEnabled: false,
341-
expectedError: errors.New("either target allocator or prometheus config needs to be present"),
328+
targetAllocatorEnabled: true,
329+
expectedError: nil,
342330
},
343331
{
344332
description: "target_allocator disabled, config section present",
345333
config: map[interface{}]interface{}{
346334
"config": map[interface{}]interface{}{},
347335
},
348-
targetAllocatorEnabled: false,
349-
targetAllocatorRewriteEnabled: false,
350-
expectedError: nil,
336+
targetAllocatorEnabled: false,
337+
expectedError: nil,
351338
},
352339
{
353-
description: "target_allocator disabled, config section not present",
354-
config: map[interface{}]interface{}{},
355-
targetAllocatorEnabled: false,
356-
targetAllocatorRewriteEnabled: false,
357-
expectedError: fmt.Errorf("no %s available as part of the configuration", "prometheusConfig"),
340+
description: "target_allocator disabled, config section not present",
341+
config: map[interface{}]interface{}{},
342+
targetAllocatorEnabled: false,
343+
expectedError: fmt.Errorf("no %s available as part of the configuration", "prometheusConfig"),
358344
},
359345
}
360346

361347
for _, testCase := range testCases {
362348
testCase := testCase
363349
t.Run(testCase.description, func(t *testing.T) {
364-
err := ta.ValidatePromConfig(testCase.config, testCase.targetAllocatorEnabled, testCase.targetAllocatorRewriteEnabled)
350+
err := ta.ValidatePromConfig(testCase.config, testCase.targetAllocatorEnabled)
365351
assert.Equal(t, testCase.expectedError, err)
366352
})
367353
}

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func main() {
114114
enableDotNetInstrumentation bool
115115
enablePythonInstrumentation bool
116116
enableNginxInstrumentation bool
117+
enableJavaInstrumentation bool
117118
collectorImage string
118119
targetAllocatorImage string
119120
operatorOpAMPBridgeImage string
@@ -142,6 +143,7 @@ func main() {
142143
pflag.BoolVar(&enableDotNetInstrumentation, constants.FlagDotNet, true, "Controls whether the operator supports dotnet auto-instrumentation")
143144
pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation")
144145
pflag.BoolVar(&enableNginxInstrumentation, constants.FlagNginx, false, "Controls whether the operator supports nginx auto-instrumentation")
146+
pflag.BoolVar(&enableJavaInstrumentation, constants.FlagJava, true, "Controls whether the operator supports java auto-instrumentation")
145147
stringFlagOrEnv(&collectorImage, "collector-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector:%s", v.OpenTelemetryCollector), "The default OpenTelemetry collector image. This image is used when no image is specified in the CustomResource.")
146148
stringFlagOrEnv(&targetAllocatorImage, "target-allocator-image", "RELATED_IMAGE_TARGET_ALLOCATOR", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:%s", v.TargetAllocator), "The default OpenTelemetry target allocator image. This image is used when no image is specified in the CustomResource.")
147149
stringFlagOrEnv(&operatorOpAMPBridgeImage, "operator-opamp-bridge-image", "RELATED_IMAGE_OPERATOR_OPAMP_BRIDGE", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:%s", v.OperatorOpAMPBridge), "The default OpenTelemetry Operator OpAMP Bridge image. This image is used when no image is specified in the CustomResource.")
@@ -186,6 +188,7 @@ func main() {
186188
"enable-dotnet-instrumentation", enableDotNetInstrumentation,
187189
"enable-python-instrumentation", enablePythonInstrumentation,
188190
"enable-nginx-instrumentation", enableNginxInstrumentation,
191+
"enable-java-instrumentation", enableJavaInstrumentation,
189192
)
190193

191194
restConfig := ctrl.GetConfigOrDie()
@@ -207,6 +210,7 @@ func main() {
207210
config.WithEnableDotNetInstrumentation(enableDotNetInstrumentation),
208211
config.WithEnableNginxInstrumentation(enableNginxInstrumentation),
209212
config.WithEnablePythonInstrumentation(enablePythonInstrumentation),
213+
config.WithEnableJavaInstrumentation(enableJavaInstrumentation),
210214
config.WithTargetAllocatorImage(targetAllocatorImage),
211215
config.WithOperatorOpAMPBridgeImage(operatorOpAMPBridgeImage),
212216
config.WithAutoInstrumentationJavaImage(autoInstrumentationJava),

pkg/constants/env.go

+1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ const (
4141
FlagDotNet = "enable-dotnet-instrumentation"
4242
FlagPython = "enable-python-instrumentation"
4343
FlagNginx = "enable-nginx-instrumentation"
44+
FlagJava = "enable-java-instrumentation"
4445
)

0 commit comments

Comments
 (0)