-
Notifications
You must be signed in to change notification settings - Fork 5k
[beatreceiver] Add e2e test for azure blob storage #51738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ad26d47
[beatreceiver] Add e2e test for azure blob storage
khushijain21 5763ede
Merge branch 'main' into azure-blob-storage
khushijain21 3255a8b
fix ci
khushijain21 a07af64
delete meta.json
khushijain21 f3f0199
fix cel test
khushijain21 3e2b84e
Merge remote-tracking branch 'upstream/main' into azure-blob-storage
khushijain21 5f1193b
fix ci
khushijain21 ef79a8e
fix cel input
khushijain21 4634435
Update x-pack/filebeat/tests/integration/otel_azure_blob_storage_test.go
khushijain21 fff7198
Merge branch 'main' into azure-blob-storage
khushijain21 186596d
Merge branch 'main' into azure-blob-storage
khushijain21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
205 changes: 205 additions & 0 deletions
205
x-pack/filebeat/tests/integration/otel_azure_blob_storage_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,205 @@ | ||
| // 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. | ||
|
|
||
| //go:build integration | ||
|
|
||
| package integration | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "fmt" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
| "text/template" | ||
| "time" | ||
|
|
||
| "github.com/gofrs/uuid/v5" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/elastic/beats/v7/libbeat/tests/integration" | ||
| "github.com/elastic/beats/v7/x-pack/filebeat/input/azureblobstorage/mock" | ||
| "github.com/elastic/beats/v7/x-pack/otel/oteltest" | ||
| "github.com/elastic/beats/v7/x-pack/otel/oteltestcol" | ||
| "github.com/elastic/elastic-agent-libs/testing/estools" | ||
| ) | ||
|
|
||
| const ( | ||
| azureBlobTestAccountName = "beatsblobnew" | ||
| azureBlobTestAccountKey = "7pfLm1betGiRyyABEM/RFrLYlafLZHbLtGhB52LkWVeBxE7la9mIvk6YYAbQKYE/f0GdhiaOZeV8+AStsAdr/Q==" | ||
| azureBlobTestContainer = "beatscontainer" | ||
| azureBlobTestBlob = "ata.json" | ||
| azureBlobTestMessage = "iPhone 9" | ||
| ) | ||
|
|
||
| func startAzureBlobMockStorageServer(t *testing.T) string { | ||
| t.Helper() | ||
|
|
||
| srv := httptest.NewServer(mock.AzureStorageServer()) | ||
| t.Cleanup(srv.Close) | ||
|
|
||
| return srv.URL + "/" | ||
| } | ||
|
|
||
| func TestAzureBlobStorageInputOTelE2E(t *testing.T) { | ||
| integration.EnsureESIsRunning(t) | ||
|
|
||
| storageURL := startAzureBlobMockStorageServer(t) | ||
| otelHome := t.TempDir() | ||
|
|
||
| host := integration.GetESURL(t, "http") | ||
| user := host.User.Username() | ||
| password, _ := host.User.Password() | ||
|
|
||
| otelNamespace := strings.ReplaceAll(uuid.Must(uuid.NewV4()).String(), "-", "") | ||
| fbNamespace := strings.ReplaceAll(uuid.Must(uuid.NewV4()).String(), "-", "") | ||
|
|
||
| otelIndex := "logs-integration-" + otelNamespace | ||
| fbIndex := "logs-integration-" + fbNamespace | ||
|
|
||
| type options struct { | ||
| Index string | ||
| ESURL string | ||
| Username string | ||
| Password string | ||
| StorageURL string | ||
| PathHome string | ||
| AccountName string | ||
| AccountKey string | ||
| } | ||
|
|
||
| filebeatConfig := `filebeat.inputs: | ||
| - type: azure-blob-storage | ||
| id: azure-blob-storage-input-e2e | ||
| account_name: {{ .AccountName }} | ||
| storage_url: {{ .StorageURL }} | ||
| auth: | ||
| shared_credentials: | ||
| account_key: {{ .AccountKey }} | ||
| poll: false | ||
| max_workers: 1 | ||
| containers: | ||
| - name: ` + azureBlobTestContainer + ` | ||
| file_selectors: | ||
| - regex: '^` + azureBlobTestBlob + `$' | ||
|
|
||
| output: | ||
| elasticsearch: | ||
| hosts: | ||
| - {{ .ESURL }} | ||
| username: {{ .Username }} | ||
| password: {{ .Password }} | ||
| index: {{ .Index }} | ||
|
|
||
| queue.mem.flush.timeout: 0s | ||
| setup.template.enabled: false | ||
| processors: | ||
| - add_host_metadata: ~ | ||
| - add_cloud_metadata: ~ | ||
| - add_docker_metadata: ~ | ||
| - add_kubernetes_metadata: ~ | ||
| ` | ||
|
|
||
| otelConfig := otelElasticsearchExporterYAML + `receivers: | ||
| filebeatreceiver: | ||
| filebeat: | ||
| inputs: | ||
| - type: azure-blob-storage | ||
| id: azure-blob-storage-input-e2e | ||
| account_name: {{ .AccountName }} | ||
| storage_url: {{ .StorageURL }} | ||
| auth: | ||
| shared_credentials: | ||
| account_key: {{ .AccountKey }} | ||
| poll: false | ||
| max_workers: 1 | ||
| containers: | ||
| - name: ` + azureBlobTestContainer + ` | ||
| file_selectors: | ||
| - regex: '^` + azureBlobTestBlob + `$' | ||
| processors: | ||
| - add_host_metadata: ~ | ||
| - add_cloud_metadata: ~ | ||
| - add_docker_metadata: ~ | ||
| - add_kubernetes_metadata: ~ | ||
| queue.mem.flush.timeout: 0s | ||
| setup.template.enabled: false | ||
| path.home: {{ .PathHome }} | ||
| ` + otelElasticsearchServiceYAML | ||
|
|
||
| optionsValue := options{ | ||
| ESURL: fmt.Sprintf("%s://%s", host.Scheme, host.Host), | ||
| Username: user, | ||
| Password: password, | ||
| StorageURL: storageURL, | ||
| PathHome: otelHome, | ||
| AccountName: azureBlobTestAccountName, | ||
| AccountKey: azureBlobTestAccountKey, | ||
| } | ||
|
|
||
| var configBuffer bytes.Buffer | ||
| optionsValue.Index = otelIndex | ||
| require.NoError(t, template.Must(template.New("config").Parse(otelConfig)).Execute(&configBuffer, optionsValue)) | ||
|
|
||
| oteltestcol.New(t, configBuffer.String()) | ||
|
|
||
| configBuffer.Reset() | ||
|
|
||
| optionsValue.Index = fbIndex | ||
| require.NoError(t, template.Must(template.New("config").Parse(filebeatConfig)).Execute(&configBuffer, optionsValue)) | ||
|
|
||
| filebeat := integration.NewBeat( | ||
| t, | ||
| "filebeat", | ||
| "../../filebeat.test", | ||
| ) | ||
| filebeat.WriteConfigFile(configBuffer.String()) | ||
| filebeat.Start() | ||
| defer filebeat.Stop() | ||
|
|
||
| filebeat.WaitLogsContains( | ||
| "filebeat start running", | ||
| 20*time.Second, | ||
| "filebeat did not run", | ||
| ) | ||
|
|
||
| es := integration.GetESClient(t, "http") | ||
|
|
||
| t.Cleanup(func() { | ||
| deleteDataStreamsFromES(t, es, []string{otelIndex, fbIndex}) | ||
| }) | ||
|
|
||
| rawQuery := otelE2ERawQueryForInputTypeAndMessage("azure-blob-storage", azureBlobTestMessage) | ||
|
|
||
| var filebeatDocs estools.Documents | ||
| var otelDocs estools.Documents | ||
| var err error | ||
|
|
||
| require.EventuallyWithTf(t, | ||
| func(ct *assert.CollectT) { | ||
| findCtx, findCancel := context.WithTimeout(t.Context(), 900*time.Millisecond) | ||
| defer findCancel() | ||
|
|
||
| otelDocs, err = estools.PerformQueryForRawQuery(findCtx, rawQuery, ".ds-"+otelIndex+"*", es) | ||
| assert.NoError(ct, err) | ||
| assert.GreaterOrEqual(ct, otelDocs.Hits.Total.Value, 1, "expected at least 1 otel document, got %d", otelDocs.Hits.Total.Value) | ||
|
|
||
| filebeatDocs, err = estools.PerformQueryForRawQuery(findCtx, rawQuery, ".ds-"+fbIndex+"*", es) | ||
| assert.NoError(ct, err) | ||
| assert.GreaterOrEqual(ct, filebeatDocs.Hits.Total.Value, 1, "expected at least 1 filebeat document, got %d", filebeatDocs.Hits.Total.Value) | ||
| }, | ||
| 3*time.Minute, 1*time.Second, "expected at least 1 document for both filebeat and otel modes") | ||
|
|
||
| filebeatDoc := filebeatDocs.Hits.Hits[0].Source | ||
| otelDoc := otelDocs.Hits.Hits[0].Source | ||
| ignoredFields := []string{ | ||
| "@timestamp", | ||
| "agent.ephemeral_id", | ||
| "agent.id", | ||
| } | ||
|
|
||
| oteltest.AssertMapsEqual(t, filebeatDoc, otelDoc, ignoredFields, "expected documents to be equal") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.