-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
* Fix Otel API change * Update test files with new date/year (cherry picked from commit 1430cfd) # Conflicts: # x-pack/filebeat/fbreceiver/receiver_test.go # x-pack/filebeat/module/cisco/asa/test/non-canonical.log-expected.json
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package fbreceiver | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/pdata/plog" | ||
"go.opentelemetry.io/collector/receiver" | ||
"go.uber.org/zap" | ||
"go.uber.org/zap/zapcore" | ||
) | ||
|
||
func TestNewReceiver(t *testing.T) { | ||
config := Config{ | ||
Check failure on line 23 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (windows)
Check failure on line 23 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (linux)
|
||
Beatconfig: map[string]interface{}{ | ||
"filebeat": map[string]interface{}{ | ||
"inputs": []map[string]interface{}{ | ||
{ | ||
"type": "benchmark", | ||
"enabled": true, | ||
"message": "test", | ||
"count": 1, | ||
}, | ||
}, | ||
}, | ||
"output": map[string]interface{}{ | ||
"otelconsumer": map[string]interface{}{}, | ||
}, | ||
"logging": map[string]interface{}{ | ||
"level": "debug", | ||
"selectors": []string{ | ||
"*", | ||
}, | ||
}, | ||
"path.home": t.TempDir(), | ||
}, | ||
} | ||
|
||
var zapLogs bytes.Buffer | ||
core := zapcore.NewCore( | ||
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), | ||
zapcore.AddSync(&zapLogs), | ||
zapcore.DebugLevel) | ||
|
||
receiverSettings := receiver.Settings{} | ||
receiverSettings.Logger = zap.New(core) | ||
|
||
var countLogs int | ||
logConsumer, err := consumer.NewLogs(func(ctx context.Context, ld plog.Logs) error { | ||
countLogs = countLogs + ld.LogRecordCount() | ||
return nil | ||
}) | ||
assert.NoError(t, err, "Error creating log consumer") | ||
|
||
r, err := createReceiver(context.Background(), receiverSettings, &config, logConsumer) | ||
Check failure on line 64 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (windows)
Check failure on line 64 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (linux)
|
||
assert.NoErrorf(t, err, "Error creating receiver. Logs:\n %s", zapLogs.String()) | ||
err = r.Start(context.Background(), nil) | ||
assert.NoError(t, err, "Error starting filebeatreceiver") | ||
|
||
ch := make(chan bool, 1) | ||
timer := time.NewTimer(120 * time.Second) | ||
defer timer.Stop() | ||
ticker := time.NewTicker(1 * time.Second) | ||
defer ticker.Stop() | ||
|
||
for tick := ticker.C; ; { | ||
select { | ||
case <-timer.C: | ||
t.Fatalf("consumed logs didn't increase\nCount: %d\nLogs: %s\n", countLogs, zapLogs.String()) | ||
case <-tick: | ||
tick = nil | ||
go func() { ch <- countLogs > 0 }() | ||
case v := <-ch: | ||
if v { | ||
goto found | ||
} | ||
tick = ticker.C | ||
} | ||
} | ||
found: | ||
err = r.Shutdown(context.Background()) | ||
assert.NoError(t, err, "Error shutting down filebeatreceiver") | ||
} | ||
|
||
func BenchmarkFactory(b *testing.B) { | ||
tmpDir := b.TempDir() | ||
|
||
cfg := &Config{ | ||
Check failure on line 97 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (windows)
Check failure on line 97 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (linux)
|
||
Beatconfig: map[string]interface{}{ | ||
"filebeat": map[string]interface{}{ | ||
"inputs": []map[string]interface{}{ | ||
{ | ||
"type": "benchmark", | ||
"enabled": true, | ||
"message": "test", | ||
"count": 10, | ||
}, | ||
}, | ||
}, | ||
"output": map[string]interface{}{ | ||
"otelconsumer": map[string]interface{}{}, | ||
}, | ||
"logging": map[string]interface{}{ | ||
"level": "debug", | ||
"selectors": []string{ | ||
"*", | ||
}, | ||
}, | ||
"path.home": tmpDir, | ||
}, | ||
} | ||
|
||
var zapLogs bytes.Buffer | ||
core := zapcore.NewCore( | ||
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), | ||
zapcore.AddSync(&zapLogs), | ||
zapcore.DebugLevel) | ||
|
||
receiverSettings := receiver.Settings{} | ||
receiverSettings.Logger = zap.New(core) | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, err := NewFactory().CreateLogs(context.Background(), receiverSettings, cfg, nil) | ||
Check failure on line 133 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (windows)
Check failure on line 133 in x-pack/filebeat/fbreceiver/receiver_test.go GitHub Actions / lint (linux)
|
||
require.NoError(b, err) | ||
} | ||
} |