Skip to content
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

plugins: New Azure Kusto Output Plugin #5645

Merged
merged 18 commits into from
Aug 16, 2022

Conversation

papigers
Copy link
Contributor

@papigers papigers commented Jun 27, 2022

Adds an output plugin for Azure Data Explorer (aka Kusto). #5591


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Attached Valgrind output that shows no leaks or memory corruption was found

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

Documentation

  • Documentation required for this feature

Will create documentation PR in the upcoming days

Backporting

  • [N/A] Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

@papigers
Copy link
Contributor Author

Sample configuration (https://pastebin.com/B6wT4aPP)

[SERVICE]
  Daemon          off
  Flush 5

[INPUT]
  Name dummy
  Tag    dummy.log
  Dummy {"top": {".dotted": "value"}}

[OUTPUT]
  Match *
  Name azure_kusto
  Tenant_Id <azure_ad_directory/tenant_id>
  Client_Id <azure_ad_app_id>
  Client_Secret <secret>
  Ingestion_Endpoint https://ingest-clustername.northeurope.kusto.windows.net
  Database_Name MyDatabase
  Table_Name MyTable
  Include_Tag_Key On
  Tag_Key tag
  Include_Time_Key On
  Time_Key time

Debug output (https://pastebin.com/SWm8tFnL)

fluent-bit -c ./fluent-bit.conf
Fluent Bit v1.9.6
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/06/27 02:37:18] [ info] [fluent bit] version=1.9.6, commit=, pid=26487
[2022/06/27 02:37:18] [ info] [storage] version=1.2.0, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/06/27 02:37:18] [ info] [cmetrics] version=0.3.4
[2022/06/27 02:37:18] [ info] [output:azure_kusto:azure_kusto.0] endpoint='https://ingest-kvcv10n0jt157umdjvadsq.northeurope.dev.kusto.windows.net', database='MyDatabase', table='MyTable'
[2022/06/27 02:37:18] [ info] [oauth2] HTTP Status=200
[2022/06/27 02:37:18] [ info] [oauth2] access token from 'login.microsoftonline.com:443' retrieved
[2022/06/27 02:37:18] [ info] [output:azure_kusto:azure_kusto.0] loading kusto ingestion resourcs
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] Kusto ingestion command request http_do=0, HTTP Status: 200
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: TempStorage 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SecuredReadyForAggregationQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SecuredReadyForAggregationQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SecuredReadyForAggregationQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SecuredReadyForAggregationQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SuccessfulIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SuccessfulIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SuccessfulIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: SuccessfulIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: FailedIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: FailedIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: FailedIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: FailedIngestionsQueue 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] found resource of type: IngestionsStatusTable 
[2022/06/27 02:37:18] [debug] [output:azure_kusto:azure_kusto.0] parsed 1 blob resources and 4 queue resources
[2022/06/27 02:37:19] [debug] [output:azure_kusto:azure_kusto.0] Kusto ingestion command request http_do=0, HTTP Status: 200
[2022/06/27 02:37:19] [debug] [output:azure_kusto:azure_kusto.0] parsed kusto identity token: '<redacted_jwt_token>'
[2022/06/27 02:37:19] [ info] [sp] stream processor started
[2022/06/27 02:37:23] [debug] [output:azure_kusto:azure_kusto.0] resources are already loaded and are not stale
[2022/06/27 02:37:23] [debug] [output:azure_kusto:azure_kusto.0] uploading payload to blob uri: /kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286643631.multijson?<redacted_blob_sas_token>
[2022/06/27 02:37:23] [debug] [output:azure_kusto:azure_kusto.0] kusto blob upload request http_do=0, HTTP Status: 201
[2022/06/27 02:37:23] [debug] [output:azure_kusto:azure_kusto.0] created blob https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286643631.multijson?<redacted_blob_sas_token>
[2022/06/27 02:37:24] [debug] [output:azure_kusto:azure_kusto.0] created ingestion message:
{"Id": "34aca4f2-86a6-606b-2fa3-e1bd7e8ffb11", "BlobPath": "https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286643631.multijson?<redacted_blob_sas_token>", "RawDataSize": 393, "DatabaseName": "MyDatabase", "TableName": "MyTable","AdditionalProperties": { "format": "multijson", "authorizationContext": "<redacted_jwt_token>", "jsonMappingReference": "" }}
[2022/06/27 02:37:24] [debug] [output:azure_kusto:azure_kusto.0] kusto queue request http_do=0, HTTP Status: 201
[2022/06/27 02:37:28] [debug] [output:azure_kusto:azure_kusto.0] resources are already loaded and are not stale
[2022/06/27 02:37:28] [debug] [output:azure_kusto:azure_kusto.0] uploading payload to blob uri: /kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286648631.multijson?<redacted_blob_sas_token>
[2022/06/27 02:37:28] [debug] [output:azure_kusto:azure_kusto.0] kusto blob upload request http_do=0, HTTP Status: 201
[2022/06/27 02:37:28] [debug] [output:azure_kusto:azure_kusto.0] created blob https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286648631.multijson?<redacted_blob_sas_token>
[2022/06/27 02:37:28] [debug] [output:azure_kusto:azure_kusto.0] created ingestion message:
{"Id": "03a0eac0-a4cb-0d07-1287-83110c091796", "BlobPath": "https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286648631.multijson?<redacted_blob_sas_token>", "RawDataSize": 491, "DatabaseName": "MyDatabase", "TableName": "MyTable","AdditionalProperties": { "format": "multijson", "authorizationContext": "<redacted_jwt_token>, "jsonMappingReference": "" }}
[2022/06/27 02:37:28] [debug] [output:azure_kusto:azure_kusto.0] kusto queue request http_do=0, HTTP Status: 201
[2022/06/27 02:37:33] [debug] [output:azure_kusto:azure_kusto.0] resources are already loaded and are not stale
[2022/06/27 02:37:33] [debug] [output:azure_kusto:azure_kusto.0] uploading payload to blob uri: /kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286653632.multijson<redacted_blob_sas_token>
[2022/06/27 02:37:33] [debug] [output:azure_kusto:azure_kusto.0] kusto blob upload request http_do=0, HTTP Status: 201
[2022/06/27 02:37:33] [debug] [output:azure_kusto:azure_kusto.0] created blob https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286653632.multijson<redacted_blob_sas_token>
[2022/06/27 02:37:33] [debug] [output:azure_kusto:azure_kusto.0] created ingestion message:
{"Id": "39d53c40-5a4f-8046-fdfd-3a94be4d62eb", "BlobPath": "https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286653632.multijson<redacted_blob_sas_token>", "RawDataSize": 491, "DatabaseName": "MyDatabase", "TableName": "MyTable","AdditionalProperties": { "format": "multijson", "authorizationContext": "<redacted_jwt_token>", "jsonMappingReference": "" }}
[2022/06/27 02:37:33] [debug] [output:azure_kusto:azure_kusto.0] kusto queue request http_do=0, HTTP Status: 201
[2022/06/27 02:37:38] [debug] [output:azure_kusto:azure_kusto.0] resources are already loaded and are not stale
[2022/06/27 02:37:38] [debug] [output:azure_kusto:azure_kusto.0] uploading payload to blob uri: /kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286658632.multijson<redacted_blob_sas_token>
[2022/06/27 02:37:38] [debug] [output:azure_kusto:azure_kusto.0] kusto blob upload request http_do=0, HTTP Status: 201
[2022/06/27 02:37:38] [debug] [output:azure_kusto:azure_kusto.0] created blob https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286658632.multijson<redacted_blob_sas_token>
[2022/06/27 02:37:38] [debug] [output:azure_kusto:azure_kusto.0] created ingestion message:
{"Id": "5d7f87bb-96d4-fed3-8d7f-2c96ce287ced", "BlobPath": "https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286658632.multijson<redacted_blob_sas_token>", "RawDataSize": 491, "DatabaseName": "MyDatabase", "TableName": "MyTable","AdditionalProperties": { "format": "multijson", "authorizationContext": "<redacted_jwt_token>", "jsonMappingReference": "" }}
[2022/06/27 02:37:38] [debug] [output:azure_kusto:azure_kusto.0] kusto queue request http_do=0, HTTP Status: 201
^C[2022/06/27 02:37:41] [engine] caught signal (SIGINT)
[2022/06/27 02:37:41] [ warn] [engine] service will shutdown in max 5 seconds
[2022/06/27 02:37:41] [debug] [output:azure_kusto:azure_kusto.0] resources are already loaded and are not stale
[2022/06/27 02:37:41] [debug] [output:azure_kusto:azure_kusto.0] uploading payload to blob uri: /kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286661962.multijson<redacted_blob_sas_token>
[2022/06/27 02:37:42] [debug] [output:azure_kusto:azure_kusto.0] kusto blob upload request http_do=0, HTTP Status: 201
[2022/06/27 02:37:42] [debug] [output:azure_kusto:azure_kusto.0] created blob https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286661962.multijson<redacted_blob_sas_token>
[2022/06/27 02:37:42] [debug] [output:azure_kusto:azure_kusto.0] created ingestion message:
{"Id": "74adedd3-d33e-a461-c838-4825bfa7d07d", "BlobPath": "https://n58virtualdms.blob.core.windows.net/kvcv10n0jt157umdjvadsq-20220626-ingestdata-e5c334ee145d4b4-0/flb__MyDatabase__MyTable__ZHVtbXkubG9nPyY9XjM__1656286661962.multijson<redacted_blob_sas_token>", "RawDataSize": 393, "DatabaseName": "MyDatabase", "TableName": "MyTable","AdditionalProperties": { "format": "multijson", "authorizationContext": "<redacted_jwt_token>", "jsonMappingReference": "" }}
[2022/06/27 02:37:42] [debug] [output:azure_kusto:azure_kusto.0] kusto queue request http_do=0, HTTP Status: 201
[2022/06/27 02:37:42] [ info] [engine] service has stopped (0 pending tasks)

Valgrind output (https://pastebin.com/gtWJbRzv)

valgrind --tool=memcheck --leak-check=full fluent-bit -c ./fluent-bit.conf
==17725== Memcheck, a memory error detector
==17725== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==17725== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==17725== Command: fluent-bit -c ./fluent-bit.conf
==17725== 
Fluent Bit v1.9.6
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/06/27 03:31:26] [ info] [fluent bit] version=1.9.6, commit=, pid=17725
[2022/06/27 03:31:26] [ info] [storage] version=1.2.0, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/06/27 03:31:26] [ info] [cmetrics] version=0.3.4
[2022/06/27 03:31:26] [ info] [output:azure_kusto:azure_kusto.0] endpoint='https://ingest-kvcv10n0jt157umdjvadsq.northeurope.dev.kusto.windows.net', database='MyDatabase', table='MyTable'
[2022/06/27 03:31:28] [ info] [oauth2] HTTP Status=200
[2022/06/27 03:31:28] [ info] [oauth2] access token from 'login.microsoftonline.com:443' retrieved
[2022/06/27 03:31:28] [ info] [output:azure_kusto:azure_kusto.0] loading kusto ingestion resourcs
[2022/06/27 03:31:29] [ info] [sp] stream processor started
==17725== Warning: client switching stacks?  SP change: 0x5c9b808 --> 0x68fe5d0
==17725==          to suppress, use: --max-stackframe=12987848 or greater
==17725== Warning: client switching stacks?  SP change: 0x68fe528 --> 0x5c9b808
==17725==          to suppress, use: --max-stackframe=12987680 or greater
==17725== Warning: client switching stacks?  SP change: 0x5c9ba38 --> 0x68fe528
==17725==          to suppress, use: --max-stackframe=12987120 or greater
==17725==          further instances of this message will not be shown.
==17725== Thread 2 flb-pipeline:
==17725== Invalid read of size 1
==17725==    at 0x484ED24: strlen (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==17725==  Address 0x6b2a604 is 0 bytes after a block of size 36 alloc'd
==17725==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==17725== 
^C[2022/06/27 03:31:41] [engine] caught signal (SIGINT)
[2022/06/27 03:31:41] [ warn] [engine] service will shutdown in max 5 seconds
[2022/06/27 03:31:41] [ info] [task] dummy/dummy.0 has 1 pending task(s):
[2022/06/27 03:31:41] [ info] [task]   task_id=0 still running on route(s): azure_kusto/azure_kusto.0 
[2022/06/27 03:31:42] [ info] [engine] service has stopped (0 pending tasks)
==17725== 
==17725== HEAP SUMMARY:
==17725==     in use at exit: 762,568 bytes in 5,806 blocks
==17725==   total heap usage: 59,677 allocs, 53,871 frees, 9,488,410 bytes allocated
==17725== 
==17725== Thread 1:
==17725== 610 bytes in 3 blocks are definitely lost in loss record 733 of 819
==17725==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==17725== 
==17725== LEAK SUMMARY:
==17725==    definitely lost: 610 bytes in 3 blocks
==17725==    indirectly lost: 0 bytes in 0 blocks
==17725==      possibly lost: 0 bytes in 0 blocks
==17725==    still reachable: 761,958 bytes in 5,803 blocks
==17725==         suppressed: 0 bytes in 0 blocks
==17725== Reachable blocks (those to which a pointer was found) are not shown.
==17725== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==17725== 
==17725== For lists of detected and suppressed errors, rerun with: -s
==17725== ERROR SUMMARY: 7 errors from 2 contexts (suppressed: 0 from 0)

@patrick-stephens
Copy link
Contributor

@papigers can you raise a docs PR and link it here for the new plugin too? I can't comment on the actual changes here but I've approved the workflows to run - the docs PR is needed so we can include in a release after merging this.

@agup006 looks like a good addition for 2.0 maybe?

@patrick-stephens patrick-stephens changed the title Azure Kusto Output Plugin plugins: New Azure Kusto Output Plugin Jun 27, 2022
@patrick-stephens
Copy link
Contributor

@papigers it's great to have the new plugin but probably need some help on integration testing as well over at fluent/fluent-bit-ci. Can you link a PR from there with the integration tests as well? Ideally we can test in isolation and not requiring more infrastructure set up but feel free to ping me or @niedbalski to discuss.

@papigers
Copy link
Contributor Author

@patrick-stephens

can you raise a docs PR and link it here for the new plugin too? I can't comment on the actual changes here but I've approved the workflows to run - the docs PR is needed so we can include in a release after merging this.

Hopefully will find a time for it today/tomorrow.

it's great to have the new plugin but probably need some help on integration testing as well over at fluent/fluent-bit-ci. Can you link a PR from there with the integration tests as well? Ideally we can test in isolation and not requiring more infrastructure set up but feel free to ping me or @niedbalski to discuss.

Unfortunately, kusto doesn't have an emulator to run against locally, but we could probably utilize their free tier offering. We would also need to create an azure account (no subscription/payment needed AFAIK), and then create an oauth application in that directory, and use its credentials in the plugin's configuration.

@patrick-stephens
Copy link
Contributor

Unfortunately, kusto doesn't have an emulator to run against locally, but we could probably utilize their free tier offering. We would also need to create an azure account (no subscription/payment needed AFAIK), and then create an oauth application in that directory, and use its credentials in the plugin's configuration.

Would it be possible to pull together a test then, assuming we have access, so we can provide it? We can sort out the access separately then and just have your test case hook into it.

@papigers
Copy link
Contributor Author

Sure thing, I'll update as soon as I have something ready.

@patrick-stephens
Copy link
Contributor

Thanks @papigers , feel free to open a PR on the fluent ci repo.

An example one with a linked integration test: #5557

@papigers
Copy link
Contributor Author

papigers commented Jul 6, 2022

Hey @patrick-stephens, sorry for the delay, I've created this CI PR: fluent/fluent-bit-ci#66

Please tell me what you think.
I'm still planning to work on the documentation as well, hopefully I'll find the time over the weekend.

@patrick-stephens
Copy link
Contributor

Super awesome is what I think @papigers , really appreciate it! Once we land the CI PR we can run it with this change.

We may have to look at how we handle running it for PRs without your plugin though. Don't want failures for previous PRs.

@agup006
Copy link
Member

agup006 commented Jul 6, 2022

@papigers this is awesome, want to present this at our community meeting this Thursday? https://docs.google.com/document/d/1vJvsn8E0SanLO1R0X3RC1qTw0XQK_7q75sZ8IbWAu-g/edit#

@papigers
Copy link
Contributor Author

papigers commented Jul 6, 2022

@agup006 wow, thanks a lot for the offer.
This Thursday I won't be available for that, but maybe the meeting after that?
If that works for you I'd also appreciate a breif/demo of how it usually goes so I would come prepared :)

@patrick-stephens
Copy link
Contributor

@agup006 wow, thanks a lot for the offer. This Thursday I won't be available for that, but maybe the meeting after that? If that works for you I'd also appreciate a breif/demo of how it usually goes so I would come prepared :)

I think that's fine for the one after if we can schedule you in - the dates should be on the meet up page and I'll add you to the agenda.
As to how it goes, it's pretty casual and there are a few recorded ones in the linked agenda doc if you want to watch a previous one. We should really get them up on Youtube or similar @agup006 .

Copy link
Collaborator

@leonardo-albertovich leonardo-albertovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain the logic behind the flb_upstream_node_destroy correction?

/* Clear any previous oauth2 payload content */
flb_oauth2_payload_clear(ctx->o);

ret = flb_oauth2_payload_append(ctx->o, "grant_type", 10, "client_credentials", 18);
Copy link
Collaborator

@leonardo-albertovich leonardo-albertovich Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please normalize these calls so all of them pass -1 or the precomputed length as the length of the constant strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normalized all constant string but kept variables with -1, should I pass sdslens there?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's ok since flb_oauth2_payload_append can do it at no additional cost.

token = get_azure_kusto_token(ctx);
if (!token) {
flb_plg_error(ctx->ins, "cannot retrieve oauth2 token");
goto execute_error;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point neither c nor body have been initialized so this jump causes a check that could return a false positive and call the destructors for the http client or sds depending on the contents of the stack before this function is called.

In general I think if not strictly necessary goto should not be used but if that's not an option then please initialize those variables to NULL at the beginning of the function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, removed all gotos except those in azure_kusto_load_ingestion_resources, I think goto is helpful with handling mutex unlock on errors

flb_output_upstream_set(ctx->u, ins);

/* Get or renew the OAuth2 token */
token = get_azure_kusto_token(ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that this callback is invoked when the input plugin is initialized (before the event loop is active) then any http requests made by the code that obtains token will be synchronous (as well as the ones made by azure_kusto_load_ingestion_resources).

Do you think this could be delayed until first use? That would shift the delay and minimize the impact, considering that the code does handle token expiration I think this should not be a problem right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's not necessary, I just mimicked the behavior of other plugins (example) that checked "dependencies" are valid before continuing. But considering that failures here will only emit warnings, I don't see harm in removing them.

@papigers
Copy link
Contributor Author

papigers commented Jul 8, 2022

Could you please explain the logic behind the flb_upstream_node_destroy correction?

@leonardo-albertovich Discovered by running valgrind.

==53772== Invalid read of size 8
==53772==    at 0x1BEF2A: flb_tls_session_destroy (flb_tls.c:439)
==53772==    by 0x1A6E1A: destroy_conn (flb_upstream.c:487)
==53772==    by 0x1A7287: flb_upstream_destroy (flb_upstream.c:605)
==53772==    by 0x2D6CE5: flb_upstream_node_destroy (flb_upstream_node.c:193)
==53772==    by 0x2D5892: flb_upstream_ha_destroy (flb_upstream_ha.c:72)
==53772==    by 0x22F83B: flb_azure_kusto_resources_clear (azure_kusto_conf.c:125)
==53772==    by 0x230B7F: flb_azure_kusto_resources_destroy (azure_kusto_conf.c:516)
==53772==    by 0x231263: flb_azure_kusto_conf_destroy (azure_kusto_conf.c:628)
==53772==    by 0x22F0EA: cb_azure_kusto_exit (azure_kusto.c:452)
==53772==    by 0x18CF59: flb_output_exit (flb_output.c:315)
==53772==    by 0x1A0661: flb_engine_shutdown (flb_engine.c:917)
==53772==    by 0x1A02B2: flb_engine_start (flb_engine.c:823)

In flb_upstream_destroy, the tls struct is referenced, so if it's destroyed before calling upstream_destory we get this warning.
This is caused by the upstream_node and the upstream using the same tls struct

Edit: just noticed my commit message suggests the tls is being freed twice, which is not true, I'll update the message as soon as I push fixes for the rest of your review comments

msgpack_sbuffer_destroy(&mp_sbuf);
return -1;
}
msgpack_pack_array(&mp_pck, records);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you are writing the array header with the total number of records here wouldn't skipping elements create a problem when flb_msgpack_raw_to_json_sds unpacks the newly created msgpack buffer? I had that happen in a different setting, I'm not sure of what the right way to address it would be other than inserting placeholder entries at the end or saving the buffer index to go back to edit it after the loop which is not very nice.

I'm not aware of a proper mechanism to address this issue but thought it'd be nice to mention it so others can chime in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting till we decide what's the best approach here. I'll just note that I saw similar "skips" in other output plugins too, so we might want to create a task for it and also fix it there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'll bring it up internally to see if there's anything we can do to fix that at the root.

Signed-off-by: Gershon Papiashvili <[email protected]>
Signed-off-by: Gershon Papiashvili <[email protected]>
Signed-off-by: Gershon Papiashvili <[email protected]>
Signed-off-by: Gershon Papiashvili <[email protected]>
Signed-off-by: Gershon Papiashvili <[email protected]>
@papigers papigers force-pushed the 5591_azure_kusto_output_plugin branch from 313db94 to 9ed4f0c Compare August 10, 2022 14:24
@papigers
Copy link
Contributor Author

papigers commented Aug 10, 2022

@leonardo-albertovich conflict was because the flb_hash interface was renamed to flb_hash_table, so I also added another commit to rename references to that in the plugin code.

@leonardo-albertovich
Copy link
Collaborator

Great, I'll review the PR again either today or tomorrow so we can wrap it up, thanks for the time and effort you're putting on this!

@papigers
Copy link
Contributor Author

@leonardo-albertovich thanks, looks like I also need a review from @fujimotos or @niedbalski ?

@leonardo-albertovich
Copy link
Collaborator

Yeah, I don't really know what's going on with that, maybe @patrick-stephens can help us, I had the same issue yesterday with a PR of my own.

@patrick-stephens
Copy link
Contributor

Nothing has been changed by us as far as I'm aware... I suspect a Github update somewhere.

@patrick-stephens
Copy link
Contributor

Ah, I bet it's down to having changes across files you are not a code owner for @leonardo-albertovich so those have to be approved.

@niedbalski niedbalski merged commit f906de4 into fluent:master Aug 16, 2022
@nokute78
Copy link
Collaborator

We can't build on current master since we removed mbedtls by #5874

If I removed below include , I can build .
Is the line needed ?

Error:

[ 47%] Building C object plugins/out_azure_kusto/CMakeFiles/flb-plugin-out_azure_kusto.dir/azure_kusto_ingest.c.o
/home/taka/git/fluent-bit/plugins/out_azure_kusto/azure_kusto_ingest.c:28:10: fatal error: mbedtls/base64.h: No such file or directory
   28 | #include <mbedtls/base64.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [plugins/out_azure_kusto/CMakeFiles/flb-plugin-out_azure_kusto.dir/build.make:89: plugins/out_azure_kusto/CMakeFiles/flb-plugin-out_azure_kusto.dir/azure_kusto_ingest.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:5495: plugins/out_azure_kusto/CMakeFiles/flb-plugin-out_azure_kusto.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

@leonardo-albertovich
Copy link
Collaborator

leonardo-albertovich commented Aug 17, 2022

I fixed that issue a few hours ago, it was just a lagging include statement, he had already updated the code to use the flb_ version of the base64 encoder / decoder functions (which are a copy of an older version of the mbedtls functions (before they introduced a performance regression))

@nokute78
Copy link
Collaborator

@leonardo-albertovich Thank you.

@papigers
Copy link
Contributor Author

@leonardo-albertovich thanks, sorry for missing that.

mgeriesa pushed a commit to mgeriesa/fluent-bit that referenced this pull request Oct 25, 2022
* out_azure_kusto: create azure kusto output plugin

Signed-off-by: Gershon Papiashvili <[email protected]>

* flb_upstream_node: fix tls free before upstream destroy

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: fix build

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: normalize flb_oauth2_payload_append constant lengths

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: check token sds create succeed

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: remove blocking checks on plugin init

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: debug on msgpack parsing issues

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: avoid goto when possible

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: fix uuid malloc

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: better msgpack inits and cleanups

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: move casting to after declarations

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: use flb_base64_encode

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: remove goto in flb_upstream_node_create_url

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: change defaults

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: use snprintf

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: avoid reprtitive free

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: fix ingestion message snprintf

Signed-off-by: Gershon Papiashvili <[email protected]>

* out_azure_kusto: use new name for hash table interface

Signed-off-by: Gershon Papiashvili <[email protected]>

Signed-off-by: Gershon Papiashvili <[email protected]>
Signed-off-by: Manal Geries <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants