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
36 changes: 26 additions & 10 deletions plugins/out_stackdriver/gce_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

static int fetch_metadata(struct flb_stackdriver *ctx,
struct flb_upstream *upstream, char *uri,
char *payload)
flb_sds_t *payload)
{
int ret;
int ret_code;
Expand All @@ -44,21 +44,30 @@ static int fetch_metadata(struct flb_stackdriver *ctx,
/* If runtime test mode is enabled, add test data */
if (ctx->ins->test_mode == FLB_TRUE) {
if (strcmp(uri, FLB_STD_METADATA_PROJECT_ID_URI) == 0) {
if (!flb_sds_cat(payload, "fluent-bit-test", 15)) {
flb_sds_t tmp;
tmp = flb_sds_cat(*payload, "fluent-bit-test", 15);
if (!tmp) {
return -1;
}
*payload = tmp;
return 0;
}
else if (strcmp(uri, FLB_STD_METADATA_ZONE_URI) == 0) {
if (!flb_sds_cat(payload, "projects/0123456789/zones/fluent", 32)) {
flb_sds_t tmp;
tmp = flb_sds_cat(*payload, "projects/0123456789/zones/fluent", 32);
if (!tmp) {
return -1;
}
*payload = tmp;
return 0;
}
else if (strcmp(uri, FLB_STD_METADATA_INSTANCE_ID_URI) == 0) {
if (!flb_sds_cat(payload, "333222111", 9)) {
flb_sds_t tmp;
tmp = flb_sds_cat(*payload, "333222111", 9);
if (!tmp) {
return -1;
}
*payload = tmp;
return 0;
}
return -1;
Expand Down Expand Up @@ -93,8 +102,15 @@ static int fetch_metadata(struct flb_stackdriver *ctx,
/* The request was issued successfully, validate the 'error' field */
flb_plg_debug(ctx->ins, "HTTP Status=%i", c->resp.status);
if (c->resp.status == 200) {
ret_code = 0;
flb_sds_copy(payload, c->resp.payload, c->resp.payload_size);
flb_sds_t tmp;
tmp = flb_sds_copy(*payload, c->resp.payload, c->resp.payload_size);
if (!tmp) {
ret_code = -1;
}
else {
*payload = tmp;
ret_code = 0;
}
}
else {
if (c->resp.payload_size > 0) {
Expand Down Expand Up @@ -150,7 +166,7 @@ int gce_metadata_read_token(struct flb_stackdriver *ctx)
}
uri = tmp;

ret = fetch_metadata(ctx, ctx->metadata_u, uri, payload);
ret = fetch_metadata(ctx, ctx->metadata_u, uri, &payload);
if (ret != 0) {
flb_plg_error(ctx->ins, "can't fetch token from the metadata server");
flb_sds_destroy(payload);
Expand Down Expand Up @@ -180,7 +196,7 @@ int gce_metadata_read_zone(struct flb_stackdriver *ctx)
flb_sds_t zone = NULL;

ret = fetch_metadata(ctx, ctx->metadata_u, FLB_STD_METADATA_ZONE_URI,
payload);
&payload);
if (ret != 0) {
flb_plg_error(ctx->ins, "can't fetch zone from the metadata server");
flb_sds_destroy(payload);
Expand Down Expand Up @@ -226,7 +242,7 @@ int gce_metadata_read_project_id(struct flb_stackdriver *ctx)
flb_sds_t payload = flb_sds_create_size(4096);

ret = fetch_metadata(ctx, ctx->metadata_u,
FLB_STD_METADATA_PROJECT_ID_URI, payload);
FLB_STD_METADATA_PROJECT_ID_URI, &payload);
if (ret != 0) {
flb_plg_error(ctx->ins, "can't fetch project id from the metadata server");
flb_sds_destroy(payload);
Expand All @@ -243,7 +259,7 @@ int gce_metadata_read_instance_id(struct flb_stackdriver *ctx)
flb_sds_t payload = flb_sds_create_size(4096);

ret = fetch_metadata(ctx, ctx->metadata_u,
FLB_STD_METADATA_INSTANCE_ID_URI, payload);
FLB_STD_METADATA_INSTANCE_ID_URI, &payload);
if (ret != 0) {
flb_plg_error(ctx->ins, "can't fetch instance id from the metadata server");
flb_sds_destroy(payload);
Expand Down
5 changes: 5 additions & 0 deletions plugins/out_stackdriver/stackdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,9 @@ static int pack_resource_labels(struct flb_stackdriver *ctx,
} else {
flb_plg_warn(ctx->ins, "failed to find a corresponding entry for "
"resource label entry [%s=%s]", label_kv->key, label_kv->val);
if (rval) {
flb_ra_key_value_destroy(rval);
}
}
flb_ra_destroy(ra);
} else {
Expand Down Expand Up @@ -2510,6 +2513,8 @@ static flb_sds_t stackdriver_format(struct flb_stackdriver *ctx,
flb_sds_destroy(log_name);
}

destroy_http_request(&http_request);

flb_log_event_decoder_destroy(&log_decoder);
msgpack_sbuffer_destroy(&mp_sbuf);

Expand Down
3 changes: 3 additions & 0 deletions plugins/out_stackdriver/stackdriver_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ static int read_credentials_file(const char *cred_file, struct flb_stackdriver *
ctx->creds->type = flb_sds_create_len(val, val_len);
}
else if (key_cmp(key, key_len, "project_id") == 0) {
if (ctx->project_id) {
flb_sds_destroy(ctx->project_id);
}
ctx->project_id = flb_sds_create_len(val, val_len);
}
else if (key_cmp(key, key_len, "private_key_id") == 0) {
Expand Down
Loading