Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ otherwise no tag is added. {issue}42208[42208] {pull}42403[42403]
- Fix timeout handling by Crowdstrike streaming input. {pull}44720[44720]
- Ensure DEPROVISIONED Okta entities are published by Okta entityanalytics provider. {issue}12658[12658] {pull}44719[44719]
- Fix handling of cursors by the streaming input for Crowdstrike. {issue}44364[44364] {pull}44548[44548]
- Added missing "text/csv" content-type filter support in azureblobsortorage input. {issue}44596[44596] {pull}44824[44824]
- Fix unexpected EOF detection and improve memory usage. {pull}44813[44813]

*Heartbeat*
Expand Down
24 changes: 23 additions & 1 deletion x-pack/filebeat/input/azureblobstorage/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
beatsNdJSONContainer = "beatsndjsoncontainer"
beatsGzJSONContainer = "beatsgzjsoncontainer"
beatsJSONWithArrayContainer = "beatsjsonwitharraycontainer"
beatsCSVContainer = "beatscsvcontainer"
)

func Test_StorageClient(t *testing.T) {
Expand Down Expand Up @@ -471,6 +472,28 @@
mock.Beatscontainer_2_blob_data3_json: true,
},
},
{
name: "ReadCSV",
baseConfig: map[string]interface{}{
"account_name": "beatsblobnew",
"auth.shared_credentials.account_key": "7pfLm1betGiRyyABEM/RFrLYlafLZHbLtGhB52LkWVeBxE7la9mIvk6YYAbQKYE/f0GdhiaOZeV8+AStsAdr/Q==",
"max_workers": 1,
"poll": true,
"poll_interval": "10s",
"decoding.codec.csv.enabled": true,
"decoding.codec.csv.comma": " ",
"containers": []map[string]interface{}{
{
"name": beatsCSVContainer,
},
},
},
mockHandler: mock.AzureStorageFileServer,
expected: map[string]bool{
mock.BeatsFilesContainer_csv[0]: true,
mock.BeatsFilesContainer_csv[1]: true,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -540,8 +563,7 @@
var err error
val, err = got.Fields.GetValue("message")
assert.NoError(t, err)

assert.True(t, tt.expected[strings.ReplaceAll(val.(string), "\r\n", "\n")])

Check failure on line 566 in x-pack/filebeat/input/azureblobstorage/input_test.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Error return value is not checked (errcheck)
assert.Equal(t, tt.expectedError, err)
receivedCount += 1
if receivedCount == len(tt.expected) {
Expand Down
34 changes: 34 additions & 0 deletions x-pack/filebeat/input/azureblobstorage/mock/data_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
beatsNdJSONContainer = "beatsndjsoncontainer"
beatsGzJSONContainer = "beatsgzjsoncontainer"
beatsJSONWithArrayContainer = "beatsjsonwitharraycontainer"
beatsCSVContainer = "beatscsvcontainer"
)

var fileContainers = map[string]bool{
Expand All @@ -18,6 +19,7 @@ var fileContainers = map[string]bool{
beatsNdJSONContainer: true,
beatsGzJSONContainer: true,
beatsJSONWithArrayContainer: true,
beatsCSVContainer: true,
}

var availableFileBlobs = map[string]map[string]bool{
Expand All @@ -38,6 +40,9 @@ var availableFileBlobs = map[string]map[string]bool{
"array-at-root.json": true,
"nested-arrays.json": true,
},
beatsCSVContainer: {
"txn1.csv": true,
},
}

var fetchFilesContainer = map[string]string{
Expand Down Expand Up @@ -197,6 +202,30 @@ var fetchFilesContainer = map[string]string{
</Blobs>
<NextMarker />
</EnumerationResults>`,
beatsCSVContainer: `<?xml version="1.0" encoding="utf-8"?>
<EnumerationResults ServiceEndpoint="https://127.0.0.1/" ContainerName="beatscsvcontainer">
<Blobs>
<Blob>
<Name>txn1.csv</Name>
<Properties>
<Last-Modified>Wed, 14 Sep 2022 12:12:28 GMT</Last-Modified>
<Etag>0x8DA964A64516C82</Etag>
<Content-Length>643</Content-Length>
<Content-Type>text/csv</Content-Type>
<Content-Encoding />
<Content-Language />
<Content-MD5>UjQX73kQRTHx+UyXZDvVkg==</Content-MD5>
<Cache-Control />
<Content-Disposition />
<BlobType>BlockBlob</BlobType>
<LeaseStatus>unlocked</LeaseStatus>
<LeaseState>available</LeaseState>
</Properties>
<Metadata />
</Blob>
</Blobs>
<NextMarker />
</EnumerationResults>`,
}

var BeatsFilesContainer_multiline_json = []string{
Expand Down Expand Up @@ -231,3 +260,8 @@ var BeatsFilesContainer_multiline_json_gz = []string{
"{\n \"@timestamp\": \"2021-05-25T17:25:42.806Z\",\n \"log.level\": \"error\",\n \"message\": \"error making http request\"\n}",
"{\n \"@timestamp\": \"2021-05-25T17:25:51.391Z\",\n \"log.level\": \"info\",\n \"message\": \"available disk space 44.3gb\"\n}",
}

var BeatsFilesContainer_csv = []string{
"{\"id\":\"1\",\"name\":\"Alice\",\"email\":\"[email protected]\",\"status\":\"active\"}",
"{\"id\":\"2\",\"name\":\"Bob\",\"email\":\"[email protected]\",\"status\":\"inactive\"}",
}
2 changes: 2 additions & 0 deletions x-pack/filebeat/input/azureblobstorage/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func AzureStorageFileServer() http.Handler {
w.Header().Set(contentType, jsonType)
case "log.ndjson":
w.Header().Set(contentType, "application/x-ndjson")
case "txn1.csv":
w.Header().Set(contentType, "text/csv")
}
w.Write(data)
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id name email status
1 Alice [email protected] active
2 Bob [email protected] inactive
2 changes: 2 additions & 0 deletions x-pack/filebeat/input/azureblobstorage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
octetType = "application/octet-stream"
ndJsonType = "application/x-ndjson"
gzType = "application/x-gzip"
csvType = "text/csv"
encodingGzip = "gzip"
)

Expand All @@ -59,4 +60,5 @@ var allowedContentTypes = map[string]bool{
octetType: true,
ndJsonType: true,
gzType: true,
csvType: true,
}
Loading