Skip to content

Commit

Permalink
out_stackdriver: add k8s_cluster resource type
Browse files Browse the repository at this point in the history
this can be used in combination with the in_kubernetes_events
to write k8s_cluster type events to stackdriver(such as replicaset events)

Signed-off-by: ryanohnemus <[email protected]>
  • Loading branch information
ryanohnemus committed Jan 22, 2024
1 parent 71746b3 commit 34bc58e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions plugins/out_stackdriver/stackdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,45 @@ static flb_sds_t stackdriver_format(struct flb_stackdriver *ctx,

flb_mp_map_header_end(&mh);
}
else if (strcmp(ctx->resource, K8S_CLUSTER) == 0) {
/* k8s_cluster resource has fields project_id, location, cluster_name
*
* There is no local_resource_id for k8s_cluster as we get all info
* from plugin config
*/

flb_mp_map_header_init(&mh, &mp_pck);

if (ctx->project_id) {
flb_mp_map_header_append(&mh);
msgpack_pack_str(&mp_pck, 10);
msgpack_pack_str_body(&mp_pck, "project_id", 10);
msgpack_pack_str(&mp_pck, flb_sds_len(ctx->project_id));
msgpack_pack_str_body(&mp_pck,
ctx->project_id, flb_sds_len(ctx->project_id));
}

if (ctx->cluster_location) {
flb_mp_map_header_append(&mh);
msgpack_pack_str(&mp_pck, 8);
msgpack_pack_str_body(&mp_pck, "location", 8);
msgpack_pack_str(&mp_pck, flb_sds_len(ctx->cluster_location));
msgpack_pack_str_body(&mp_pck,
ctx->cluster_location,
flb_sds_len(ctx->cluster_location));
}

if (ctx->cluster_name) {
flb_mp_map_header_append(&mh);
msgpack_pack_str(&mp_pck, 12);
msgpack_pack_str_body(&mp_pck, "cluster_name", 12);
msgpack_pack_str(&mp_pck, flb_sds_len(ctx->cluster_name));
msgpack_pack_str_body(&mp_pck,
ctx->cluster_name, flb_sds_len(ctx->cluster_name));
}

flb_mp_map_header_end(&mh);
}
else {
flb_plg_error(ctx->ins, "unsupported resource type '%s'",
ctx->resource);
Expand Down
1 change: 1 addition & 0 deletions plugins/out_stackdriver/stackdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
*/
#define STACKDRIVER_NET_ERROR 502

#define K8S_CLUSTER "k8s_cluster"
#define K8S_CONTAINER "k8s_container"
#define K8S_NODE "k8s_node"
#define K8S_POD "k8s_pod"
Expand Down
2 changes: 1 addition & 1 deletion plugins/out_stackdriver/stackdriver_resource_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
static const struct resource_type resource_types[] = {
{
.id = RESOURCE_TYPE_K8S,
.resources = {"k8s_container", "k8s_node", "k8s_pod"},
.resources = {"k8s_container", "k8s_node", "k8s_pod", "k8s_cluster"},
.required_labels = {"cluster_name", "location"}
},
{
Expand Down

0 comments on commit 34bc58e

Please sign in to comment.