@@ -17,9 +17,10 @@ import (
17
17
18
18
"github.com/stretchr/testify/assert"
19
19
20
- "github.com/elastic/elastic-agent/pkg/control/v
21
20
"gopkg.in/yaml.v2"
22
21
22
+ "github.com/elastic/elastic-agent/pkg/control/v2/cproto"
23
+
23
24
"github.com/gofrs/uuid/v5"
24
25
"github.com/stretchr/testify/require"
25
26
@@ -121,11 +122,14 @@ func TestAgentMonitoring(t *testing.T) {
121
122
Outputs map [string ]PolicyOutputs `yaml:"outputs"`
122
123
Fleet map [string ]any `yaml:"fleet"`
123
124
OutputPermissions map [string ]any `yaml:"output_permissions"`
124
- Agent map [string ]any `yaml:"agent"`
125
- Inputs []map [string ]any `yaml:"inputs"`
126
- Signed map [string ]any `yaml:"signed"`
127
- SecretReferences []map [string ]any `yaml:"secret_references"`
128
- Namespaces []map [string ]any `yaml:"namespaces"`
125
+ Agent struct {
126
+ Monitoring map [string ]any `yaml:"monitoring"`
127
+ Rest map [string ]any `yaml:",inline"`
128
+ } `yaml:"agent"`
129
+ Inputs []map [string ]any `yaml:"inputs"`
130
+ Signed map [string ]any `yaml:"signed"`
131
+ SecretReferences []map [string ]any `yaml:"secret_references"`
132
+ Namespaces []map [string ]any `yaml:"namespaces"`
129
133
}
130
134
131
135
policy := PolicyStruct {}
@@ -144,6 +148,12 @@ func TestAgentMonitoring(t *testing.T) {
144
148
t .Run ("verify elastic-agent monitoring functionality" , func (t * testing.T ) {
145
149
ctx , cancel := testcontext .WithDeadline (t , context .Background (), time .Now ().Add (5 * time .Minute ))
146
150
t .Cleanup (cancel )
151
+
152
+ // beats processes and beats receivers should use a different namespace to ensure each test looks only at the
153
+ // right data
154
+ actualNamespace := fmt .Sprintf ("%s-%s" , info .Namespace , "process" )
155
+ policy .Agent .Monitoring ["namespace" ] = actualNamespace
156
+
147
157
updatedPolicyBytes , err := yaml .Marshal (policy )
148
158
require .NoErrorf (t , err , "error marshalling policy, struct was %v" , policy )
149
159
t .Cleanup (func () {
@@ -182,7 +192,7 @@ func TestAgentMonitoring(t *testing.T) {
182
192
mustClauses := []map [string ]any {
183
193
{"match" : map [string ]any {"data_stream.type" : tc .dsType }},
184
194
{"match" : map [string ]any {"data_stream.dataset" : tc .dsDataset }},
185
- {"match" : map [string ]any {"data_stream.namespace" : tc . dsNamespace }},
195
+ {"match" : map [string ]any {"data_stream.namespace" : actualNamespace }},
186
196
}
187
197
188
198
// Only add the "message" match if tc.message is not empty
@@ -231,11 +241,13 @@ func TestAgentMonitoring(t *testing.T) {
231
241
ctx , cancel := testcontext .WithDeadline (t , context .Background (), time .Now ().Add (5 * time .Minute ))
232
242
t .Cleanup (cancel )
233
243
244
+ // beats processes and beats receivers should use a different namespace to ensure each test looks only at the
245
+ // right data
246
+ actualNamespace := fmt .Sprintf ("%s-%s" , info .Namespace , "otel" )
247
+ policy .Agent .Monitoring ["namespace" ] = actualNamespace
248
+
234
249
// switch monitoring to the otel runtime
235
- monitoring := policy .Agent ["monitoring" ]
236
- monitoringMap := monitoring .(map [any ]any )
237
- monitoringMap ["_runtime_experimental" ] = "otel"
238
- policy .Agent ["monitoring" ] = monitoringMap
250
+ policy .Agent .Monitoring ["_runtime_experimental" ] = "otel"
239
251
240
252
updatedPolicyBytes , err := yaml .Marshal (policy )
241
253
require .NoErrorf (t , err , "error marshalling policy, struct was %v" , policy )
@@ -255,11 +267,6 @@ func TestAgentMonitoring(t *testing.T) {
255
267
err = fixture .Configure (ctx , updatedPolicyBytes )
256
268
require .NoError (t , err , "error configuring fixture" )
257
269
258
- // Get the timestamp before starting. Required to separate logs from agent and otel.
259
- timestamp := time .Now ().UTC ().Format ("2006-01-02T15:04:05.000Z" )
260
-
261
- fmt .Println (time .Now ())
262
-
263
270
output , err := fixture .InstallWithoutEnroll (ctx , & installOpts )
264
271
require .NoErrorf (t , err , "error install withouth enroll: %s\n combinedoutput:\n %s" , err , string (output ))
265
272
@@ -273,11 +280,12 @@ func TestAgentMonitoring(t *testing.T) {
273
280
274
281
// we should have filebeatreceiver and metricbeatreceiver running
275
282
otelCollectorStatus := status .Collector
276
- assert .Equal (collect , cproto .CollectorComponentStatus_StatusOK , otelCollectorStatus .Status )
283
+ assert .Equal (collect , int ( cproto .CollectorComponentStatus_StatusOK ) , otelCollectorStatus .Status )
277
284
pipelineStatusMap := otelCollectorStatus .ComponentStatusMap
278
285
279
286
// we should have 3 pipelines running: filestream for logs, http metrics and beats metrics
280
287
assert .Equal (collect , 3 , len (pipelineStatusMap ))
288
+
281
289
fileStreamPipeline := "pipeline:logs/_agent-component/filestream-monitoring"
282
290
httpMetricsPipeline := "pipeline:logs/_agent-component/http/metrics-monitoring"
283
291
beatsMetricsPipeline := "pipeline:logs/_agent-component/beat/metrics-monitoring"
@@ -286,9 +294,9 @@ func TestAgentMonitoring(t *testing.T) {
286
294
assert .Contains (collect , pipelineStatusMap , beatsMetricsPipeline )
287
295
288
296
// and they should be healthy
289
- assert .Equal (collect , cproto .CollectorComponentStatus_StatusOK , pipelineStatusMap [fileStreamPipeline ].Status )
290
- assert .Equal (collect , cproto .CollectorComponentStatus_StatusOK , pipelineStatusMap [httpMetricsPipeline ].Status )
291
- assert .Equal (collect , cproto .CollectorComponentStatus_StatusOK , pipelineStatusMap [beatsMetricsPipeline ].Status )
297
+ assert .Equal (collect , int ( cproto .CollectorComponentStatus_StatusOK ) , pipelineStatusMap [fileStreamPipeline ].Status )
298
+ assert .Equal (collect , int ( cproto .CollectorComponentStatus_StatusOK ) , pipelineStatusMap [httpMetricsPipeline ].Status )
299
+ assert .Equal (collect , int ( cproto .CollectorComponentStatus_StatusOK ) , pipelineStatusMap [beatsMetricsPipeline ].Status )
292
300
293
301
return
294
302
}, 1 * time .Minute , 1 * time .Second )
@@ -301,11 +309,9 @@ func TestAgentMonitoring(t *testing.T) {
301
309
defer findCancel ()
302
310
mustClauses := []map [string ]any {
303
311
{"match" : map [string ]any {"message" : tc .message }},
304
- {"range" : map [string ]interface {}{
305
- "@timestamp" : map [string ]string {
306
- "gte" : timestamp , // Use captured timestamp
307
- },
308
- }},
312
+ {"match" : map [string ]any {"data_stream.type" : tc .dsType }},
313
+ {"match" : map [string ]any {"data_stream.dataset" : tc .dsDataset }},
314
+ {"match" : map [string ]any {"data_stream.namespace" : actualNamespace }},
309
315
}
310
316
311
317
rawQuery := map [string ]any {
0 commit comments