fluent-bit icon indicating copy to clipboard operation
fluent-bit copied to clipboard

BigQuery output plugin discards last character in BQ endpoint

Open jevgenimarenkov opened this issue 6 years ago • 1 comments

Bug Report

Describe the bug BigQuery output plugin discards the last character of URL for if dataset_id and table_id are long enough

To Reproduce

  • Execute the next command
echo '{"lol":42}' | docker run -v $PWD/bq:/cred -i fluent/fluent-bit:1.6.2 /fluent-bit/bin/fluent-bit -v -i stdin -o bigquery -p dataset_id=test_1 -p table_id=long_table_id_that_is_longer_than_url -p google_service_credentials=/cred/cred.json -f 1

and the next exception is thrown

 <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/bigquery/v2/projects/quantico-system-credentials/datasets/test_1/tables/long_table_id_that_is_longer_than_url/insertAl</code> was not found on this server.  <ins>That’s all we know.</ins>

the exception clearly shows that BQ output plugin discards the letter "l" from the end of URL. It should be "insertAll" not "insertAl"

Expected behavior The correct endpoint URL is generated to access BigQuery without discarded last character

Your Environment

  • Version used: 1.6.2 (broken in all versions)
  • Configuration: (broken in all versions)
  • Environment name and version (e.g. Kubernetes? What version?): (broken in all versions)
  • Server type and version: (broken in all versions)
  • Operating System and version: (broken in all versions)
  • Filters and plugins: (broken in all versions)

jevgenimarenkov avatar Oct 27 '20 07:10 jevgenimarenkov

The source of the problem is that the size of uri is generated using the next command :

ctx->uri = flb_sds_create_size(sizeof(FLB_BIGQUERY_RESOURCE_TEMPLATE)-7 +
                                   flb_sds_len(ctx->project_id) +
                                   flb_sds_len(ctx->dataset_id) +
                                   flb_sds_len(ctx->table_id));

flb_sds_create_size(sizeof(FLB_BIGQUERY_RESOURCE_TEMPLATE)-7 is wrong as afterwards flb_sds_printf is called that relies on vsnprintf that discards the remaining characters if the resulting string would be longer than n-1 characters.

flb_sds_create_size(sizeof(FLB_BIGQUERY_RESOURCE_TEMPLATE)-7 should be replaced with flb_sds_create_size(sizeof(FLB_BIGQUERY_RESOURCE_TEMPLATE)-6 if really would like to preserve every byte

jevgenimarenkov avatar Oct 27 '20 07:10 jevgenimarenkov