Skip to content

Commit 455ea29

Browse files
authored
Merge branch 'main' into stanley.liu/otel-e2e-pipelines
2 parents 04656d3 + 70ded07 commit 455ea29

File tree

10 files changed

+176
-35
lines changed

10 files changed

+176
-35
lines changed

cmd/otel-agent/config/agent_config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package config
88

99
import (
1010
"context"
11+
"errors"
1112
"fmt"
1213
"strings"
1314

@@ -59,8 +60,14 @@ var logLevelReverseMap = func(src map[string]logLevel) map[logLevel]string {
5960
return reverse
6061
}(logLevelMap)
6162

63+
// ErrNoDDExporter indicates there is no Datadog exporter in the configs
64+
var ErrNoDDExporter = fmt.Errorf("no datadog exporter found")
65+
6266
// NewConfigComponent creates a new config component from the given URIs
6367
func NewConfigComponent(ctx context.Context, ddCfg string, uris []string) (config.Component, error) {
68+
if len(uris) == 0 {
69+
return nil, errors.New("no URIs provided for configs")
70+
}
6471
// Load the configuration from the fileName
6572
rs := confmap.ResolverSettings{
6673
URIs: uris,
@@ -220,7 +227,7 @@ func getDDExporterConfig(cfg *confmap.Conf) (*datadogexporter.Config, error) {
220227
}
221228
}
222229
if len(configs) == 0 {
223-
return nil, fmt.Errorf("no datadog exporter found")
230+
return nil, ErrNoDDExporter
224231
}
225232
// Check if we have multiple datadog exporters
226233
// We only support one exporter for now

cmd/otel-agent/config/agent_config_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func (suite *ConfigTestSuite) SetupTest() {
2929
pkgconfigsetup.SetDatadog(datadog)
3030
}
3131

32+
func TestNoURIsProvided(t *testing.T) {
33+
_, err := NewConfigComponent(context.Background(), "", []string{})
34+
assert.Error(t, err, "no URIs provided for configs")
35+
}
36+
3237
func (suite *ConfigTestSuite) TestAgentConfig() {
3338
t := suite.T()
3439
fileName := "testdata/config.yaml"

cmd/otel-agent/subcommands/run/command.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,24 @@ func (o *orchestratorinterfaceimpl) Reset() {
9292
}
9393

9494
func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams, opts ...fx.Option) error {
95-
err := fxutil.Run(
95+
acfg, err := agentConfig.NewConfigComponent(context.Background(), params.CoreConfPath, params.ConfPaths)
96+
if err != nil && err != agentConfig.ErrNoDDExporter {
97+
return err
98+
}
99+
if err == agentConfig.ErrNoDDExporter {
100+
return fxutil.Run(
101+
fx.Provide(func() []string {
102+
return append(params.ConfPaths, params.Sets...)
103+
}),
104+
collectorcontribFx.Module(),
105+
collectorfx.ModuleNoAgent(),
106+
fx.Options(opts...),
107+
fx.Invoke(func(_ collectordef.Component) {
108+
}),
109+
)
110+
}
111+
112+
return fxutil.Run(
96113
ForwarderBundle(),
97114
logtracefx.Module(),
98115
inventoryagentimpl.Module(),
@@ -108,12 +125,8 @@ func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams,
108125
return cp
109126
}),
110127
fx.Provide(func() (coreconfig.Component, error) {
111-
c, err := agentConfig.NewConfigComponent(context.Background(), params.CoreConfPath, params.ConfPaths)
112-
if err != nil {
113-
return nil, err
114-
}
115-
pkgconfigenv.DetectFeatures(c)
116-
return c, nil
128+
pkgconfigenv.DetectFeatures(acfg)
129+
return acfg, nil
117130
}),
118131
workloadmetafx.Module(workloadmeta.Params{
119132
AgentType: workloadmeta.NodeAgent,
@@ -197,10 +210,6 @@ func runOTelAgentCommand(ctx context.Context, params *subcommands.GlobalParams,
197210
}),
198211
traceagentfx.Module(),
199212
)
200-
if err != nil {
201-
return err
202-
}
203-
return nil
204213
}
205214

206215
// ForwarderBundle returns the fx.Option for the forwarder bundle.

cmd/otel-agent/subcommands/run/command_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,22 @@ import (
1515
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
1616
)
1717

18-
func TestFxRun(t *testing.T) {
18+
func TestFxRun_WithDatadogExporter(t *testing.T) {
1919
fxutil.TestRun(t, func() error {
2020
ctx := context.Background()
21-
cliParams := &subcommands.GlobalParams{}
22-
return runOTelAgentCommand(ctx, cliParams)
21+
params := &subcommands.GlobalParams{
22+
ConfPaths: []string{"test_config.yaml"},
23+
}
24+
return runOTelAgentCommand(ctx, params)
25+
})
26+
}
27+
28+
func TestFxRun_NoDatadogExporter(t *testing.T) {
29+
fxutil.TestRun(t, func() error {
30+
ctx := context.Background()
31+
params := &subcommands.GlobalParams{
32+
ConfPaths: []string{"test_config_no_dd.yaml"},
33+
}
34+
return runOTelAgentCommand(ctx, params)
2335
})
2436
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
http:
5+
endpoint: "localhost:4318"
6+
grpc:
7+
endpoint: "localhost:4317"
8+
9+
exporters:
10+
datadog:
11+
api:
12+
key: "abc"
13+
14+
service:
15+
pipelines:
16+
traces:
17+
receivers: [otlp]
18+
exporters: [datadog]
19+
telemetry:
20+
metrics:
21+
address: 127.0.0.1:8888
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
receivers:
2+
otlp:
3+
protocols:
4+
http:
5+
endpoint: "localhost:4318"
6+
grpc:
7+
endpoint: "localhost:4317"
8+
9+
exporters:
10+
debug:
11+
12+
service:
13+
pipelines:
14+
traces:
15+
receivers: [otlp]
16+
exporters: [debug]
17+
telemetry:
18+
metrics:
19+
address: 127.0.0.1:8888

comp/otelcol/collector/fx/fx.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,13 @@ func Module() fxutil.Module {
2525
fxutil.ProvideOptional[collector.Component](),
2626
)
2727
}
28+
29+
// ModuleNoAgent for OTel Agent with no Agent functionalities
30+
func ModuleNoAgent() fxutil.Module {
31+
return fxutil.Component(
32+
fxutil.ProvideComponentConstructor(
33+
collectorimpl.NewComponentNoAgent,
34+
),
35+
fxutil.ProvideOptional[collector.Component](),
36+
)
37+
}

comp/otelcol/collector/impl/collector.go

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package collectorimpl
1010

1111
import (
1212
"context"
13+
"log"
1314
"os"
1415
"path/filepath"
1516

@@ -28,7 +29,7 @@ import (
2829
"go.uber.org/zap/zapcore"
2930

3031
"github.com/DataDog/datadog-agent/comp/core/config"
31-
log "github.com/DataDog/datadog-agent/comp/core/log/def"
32+
corelog "github.com/DataDog/datadog-agent/comp/core/log/def"
3233
"github.com/DataDog/datadog-agent/comp/core/tagger"
3334
"github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors/util"
3435
compdef "github.com/DataDog/datadog-agent/comp/def"
@@ -48,7 +49,7 @@ import (
4849
)
4950

5051
type collectorImpl struct {
51-
log log.Component
52+
log corelog.Component
5253
set otelcol.CollectorSettings
5354
col *otelcol.Collector
5455
}
@@ -59,18 +60,29 @@ type Requires struct {
5960
// and shutdown hooks.
6061
Lc compdef.Lifecycle
6162

62-
// Log specifies the logging component.
63-
Log log.Component
64-
Provider confmap.Converter
63+
CollectorContrib collectorcontrib.Component
64+
URIs []string
65+
66+
// Below are dependencies required by Datadog exporter and other Agent functionalities
67+
Log corelog.Component
68+
Converter confmap.Converter
6569
Config config.Component
66-
CollectorContrib collectorcontrib.Component
6770
Serializer serializer.MetricSerializer
6871
TraceAgent traceagent.Component
6972
LogsAgent optional.Option[logsagentpipeline.Component]
7073
SourceProvider serializerexporter.SourceProviderFunc
7174
Tagger tagger.Component
7275
StatsdClientWrapper *metricsclient.StatsdClientWrapper
73-
URIs []string
76+
}
77+
78+
// RequiresNoAgent declares the input types to the constructor with no dependencies on Agent components
79+
type RequiresNoAgent struct {
80+
// Lc specifies the compdef lifecycle settings, used for appending startup
81+
// and shutdown hooks.
82+
Lc compdef.Lifecycle
83+
84+
CollectorContrib collectorcontrib.Component
85+
URIs []string
7486
}
7587

7688
// Provides declares the output types from the constructor
@@ -88,18 +100,18 @@ func (c *converterFactory) Create(_ confmap.ConverterSettings) confmap.Converter
88100
return c.converter
89101
}
90102

91-
func newConfigProviderSettings(reqs Requires, enhanced bool) otelcol.ConfigProviderSettings {
103+
func newConfigProviderSettings(uris []string, converter confmap.Converter, enhanced bool) otelcol.ConfigProviderSettings {
92104
converterFactories := []confmap.ConverterFactory{
93105
expandconverter.NewFactory(),
94106
}
95107

96108
if enhanced {
97-
converterFactories = append(converterFactories, &converterFactory{converter: reqs.Provider})
109+
converterFactories = append(converterFactories, &converterFactory{converter: converter})
98110
}
99111

100112
return otelcol.ConfigProviderSettings{
101113
ResolverSettings: confmap.ResolverSettings{
102-
URIs: reqs.URIs,
114+
URIs: uris,
103115
ProviderFactories: []confmap.ProviderFactory{
104116
fileprovider.NewFactory(),
105117
envprovider.NewFactory(),
@@ -124,10 +136,16 @@ func addFactories(reqs Requires, factories otelcol.Factories) {
124136
}
125137
factories.Processors[infraattributesprocessor.Type] = infraattributesprocessor.NewFactory(reqs.Tagger, generateID)
126138
factories.Connectors[component.MustNewType("datadog")] = datadogconnector.NewFactory()
127-
factories.Extensions[ddextension.Type] = ddextension.NewFactory(&factories, newConfigProviderSettings(reqs, false))
139+
factories.Extensions[ddextension.Type] = ddextension.NewFactory(&factories, newConfigProviderSettings(reqs.URIs, reqs.Converter, false))
128140
}
129141

130-
// NewComponent returns a new instance of the collector component.
142+
var buildInfo = component.BuildInfo{
143+
Version: "v0.104.0",
144+
Command: filepath.Base(os.Args[0]),
145+
Description: "Datadog Agent OpenTelemetry Collector",
146+
}
147+
148+
// NewComponent returns a new instance of the collector component with full Agent functionalities.
131149
func NewComponent(reqs Requires) (Provides, error) {
132150
factories, err := reqs.CollectorContrib.OTelComponentFactories()
133151
if err != nil {
@@ -143,16 +161,12 @@ func NewComponent(reqs Requires) (Provides, error) {
143161
}),
144162
}
145163
set := otelcol.CollectorSettings{
146-
BuildInfo: component.BuildInfo{
147-
Version: "v0.104.0",
148-
Command: filepath.Base(os.Args[0]),
149-
Description: "Datadog Agent OpenTelemetry Collector",
150-
},
164+
BuildInfo: buildInfo,
151165
LoggingOptions: options,
152166
Factories: func() (otelcol.Factories, error) {
153167
return factories, nil
154168
},
155-
ConfigProviderSettings: newConfigProviderSettings(reqs, converterEnabled),
169+
ConfigProviderSettings: newConfigProviderSettings(reqs.URIs, reqs.Converter, converterEnabled),
156170
}
157171
col, err := otelcol.NewCollector(set)
158172
if err != nil {
@@ -173,6 +187,39 @@ func NewComponent(reqs Requires) (Provides, error) {
173187
}, nil
174188
}
175189

190+
// NewComponentNoAgent returns a new instance of the collector component with no Agent functionalities.
191+
// It is used when there is no Datadog exporter in the OTel Agent config.
192+
func NewComponentNoAgent(reqs RequiresNoAgent) (Provides, error) {
193+
factories, err := reqs.CollectorContrib.OTelComponentFactories()
194+
if err != nil {
195+
return Provides{}, err
196+
}
197+
198+
set := otelcol.CollectorSettings{
199+
BuildInfo: buildInfo,
200+
Factories: func() (otelcol.Factories, error) {
201+
return factories, nil
202+
},
203+
ConfigProviderSettings: newConfigProviderSettings(reqs.URIs, nil, false),
204+
}
205+
col, err := otelcol.NewCollector(set)
206+
if err != nil {
207+
return Provides{}, err
208+
}
209+
c := &collectorImpl{
210+
set: set,
211+
col: col,
212+
}
213+
214+
reqs.Lc.Append(compdef.Hook{
215+
OnStart: c.start,
216+
OnStop: c.stop,
217+
})
218+
return Provides{
219+
Comp: c,
220+
}, nil
221+
}
222+
176223
func (c *collectorImpl) start(ctx context.Context) error {
177224
// Dry run the collector pipeline to ensure it is configured correctly
178225
err := c.col.DryRun(ctx)
@@ -181,7 +228,11 @@ func (c *collectorImpl) start(ctx context.Context) error {
181228
}
182229
go func() {
183230
if err := c.col.Run(context.Background()); err != nil {
184-
c.log.Errorf("Error running the collector pipeline: %v", err)
231+
if c.log != nil {
232+
c.log.Errorf("Error running the collector pipeline: %v", err)
233+
} else {
234+
log.Printf("Error running the collector pipeline: %v", err)
235+
}
185236
}
186237
}()
187238
return nil

tools/windows/DatadogAgentInstaller/AgentCustomActions/InstallStateCustomActions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ private void SetDDDriverRollback()
7575
var upgradeDetected = _session["WIX_UPGRADE_DETECTED"];
7676
if (!string.IsNullOrEmpty(upgradeDetected)) // This is an upgrade, conditionally set rollback flags.
7777
{
78+
_session.Log($"WIX_UPGRADE_DETECTED: {_session["WIX_UPGRADE_DETECTED"]}");
7879
var versionString = _nativeMethods.GetVersionString(upgradeDetected);
80+
_session.Log($"versionString: {versionString}");
7981
// Using Version class
8082
// https://learn.microsoft.com/en-us/dotnet/api/system.version?view=net-8.0
8183
var currentVersion = new Version(versionString);

tools/windows/DatadogAgentInstaller/CustomActions/Native/NativeMethods.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,12 @@ public string GetVersionString(string product)
930930
var len = 512;
931931
var builder = new System.Text.StringBuilder(len);
932932

933-
MsiGetProductInfo(product, "VersionString", builder, ref len);
933+
var err = (ReturnCodes)MsiGetProductInfo(product, "VersionString", builder, ref len);
934+
if (err != ReturnCodes.NO_ERROR)
935+
{
936+
throw new Exception($"Failed to get version string for product {product}",
937+
new Win32Exception((int)err));
938+
}
934939

935940
return builder.ToString();
936941
}

0 commit comments

Comments
 (0)