Skip to content

Commit

Permalink
Merge pull request #240 from golisai/worklooad-uuid
Browse files Browse the repository at this point in the history
Introducing  workload.uid metric attribute for kubernetes workloads
  • Loading branch information
yonch authored Nov 27, 2023
2 parents 9c29e68 + d0494c5 commit f1aceba
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 6 deletions.
13 changes: 13 additions & 0 deletions docs/metrics/dimensions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ dest.workload.name:
brief: See workload.name
description: See workload.name

workload.uid:
brief: Kubernetes workload or application UUID.
description: If the associated metric comes from a monitored Kubernetes cluster running the k8-collector, the metric may note the UUID of the source and destination workload that the traffic being measured moved between. This UUID represents the unique identifier of the associated Deployment or DaemonSet.
example: 0485c36b-283e-496e-af47-1a69545cd887

source.workload.uid:
brief: See workload.uid
description: See workload.uid

dest.workload.uid:
brief: See workload.uid
description: See workload.uid

image_version:
brief: Kubernetes pod version label of the workload.
description: If the associated metric comes from a monitored Kubernetes cluster running the k8-collector, the metric may note the source and destination versions that the traffic being measured moved between. The version label is optionally set by the administrator configuring Kubernetes. Sometimes referred to as the 'service version.' May be found in the docker (pod) image or Kubernetes metadata.
Expand Down
4 changes: 4 additions & 0 deletions reducer/aggregation/agg_root_span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ void AggRootSpan::update_node(
using role_t = ::ebpf_net::aggregation::spans::role::s_t;
auto role = as_short_string<role_t>(msg->role, stat_counters.trunc_role);

using uid_t = ::ebpf_net::aggregation::spans::role::uid_t;
auto role_uid = as_short_string<uid_t>(msg->role_uid, stat_counters.trunc_role_uid);

using version_t = ::ebpf_net::aggregation::spans::role::version_t;
auto version = as_short_string<version_t>(msg->version, stat_counters.trunc_version);

Expand Down Expand Up @@ -84,6 +87,7 @@ void AggRootSpan::update_node(
if (!role_ref.valid()) {
return;
}
role_ref.modify().uid(role_uid);

auto az_ref = index.az.by_key({az, role_ref.loc()});
if (!az_ref.valid()) {
Expand Down
1 change: 1 addition & 0 deletions reducer/aggregation/labels.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct NodeLabels {
std::string ip;
std::string az;
std::string role;
std::string role_uid;
std::string version;
std::string env;
std::string ns;
Expand Down
2 changes: 2 additions & 0 deletions reducer/aggregation/labels.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#define FOREACH_NODE_LABEL(FUNC) \
FUNC("workload.name", role) \
FUNC("workload.uid", role_uid) \
FUNC("availability_zone", az) \
FUNC("id", id) \
FUNC("ip", ip) \
Expand Down Expand Up @@ -39,6 +40,7 @@ inline NodeLabels::NodeLabels(::ebpf_net::aggregation::weak_refs::az az_ref) : N
inline NodeLabels::NodeLabels(::ebpf_net::aggregation::weak_refs::role role_ref)
{
role = role_ref.s().to_string();
role_uid = role_ref.uid().to_string();
version = role_ref.version().to_string();
env = role_ref.env().to_string();
ns = role_ref.ns().to_string();
Expand Down
3 changes: 2 additions & 1 deletion reducer/aggregation/stat_counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
FN(pod_name, 6) \
FN(process, 7) \
FN(role, 8) \
FN(version, 9)
FN(version, 9) \
FN(role_uid, 10)

namespace reducer::aggregation {

Expand Down
9 changes: 5 additions & 4 deletions reducer/ingest/agent_span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ void AgentSpan::bpf_lost_samples(
void AgentSpan::set_pod_new(
std::string_view uid,
std::string_view owner_name,
std::string_view owner_uid,
std::string_view pod_name,
std::string_view ns,
std::string_view version,
Expand Down Expand Up @@ -640,7 +641,7 @@ void AgentSpan::set_pod_new(
version);

// populate the pod span with pod metadata
k8s_pod.set_pod_detail(jb_blob(owner_name), jb_blob{pod_name}, jb_blob(ns), jb_blob(version));
k8s_pod.set_pod_detail(jb_blob(owner_name), jb_blob{pod_name}, jb_blob(ns), jb_blob(version), jb_blob(owner_uid));

// Add pod to k8s_pod_set if it isn't already there.

Expand All @@ -661,18 +662,18 @@ void AgentSpan::set_pod_new(

void AgentSpan::pod_new_legacy(::ebpf_net::ingest::weak_refs::agent span_ref, u64 timestamp, jsrv_ingest__pod_new_legacy *msg)
{
set_pod_new(msg->uid, msg->owner_name, {}, msg->ns, {}, msg->ip);
set_pod_new(msg->uid, msg->owner_name, msg->owner_uid, {}, msg->ns, {}, msg->ip);
}

void AgentSpan::pod_new_legacy2(::ebpf_net::ingest::weak_refs::agent span_ref, u64 timestamp, jsrv_ingest__pod_new_legacy2 *msg)
{
set_pod_new(msg->uid, msg->owner_name, {}, msg->ns, msg->version, msg->ip);
set_pod_new(msg->uid, msg->owner_name, msg->owner_uid, {}, msg->ns, msg->version, msg->ip);
}

void AgentSpan::pod_new_with_name(
::ebpf_net::ingest::weak_refs::agent span_ref, u64 timestamp, jsrv_ingest__pod_new_with_name *msg)
{
set_pod_new(msg->uid, msg->owner_name, msg->pod_name, msg->ns, msg->version, msg->ip);
set_pod_new(msg->uid, msg->owner_name, msg->owner_uid, msg->pod_name, msg->ns, msg->version, msg->ip);
}

void AgentSpan::pod_container(::ebpf_net::ingest::weak_refs::agent span_ref, u64 timestamp, jsrv_ingest__pod_container *msg)
Expand Down
1 change: 1 addition & 0 deletions reducer/ingest/agent_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class AgentSpan : public ::ebpf_net::ingest::AgentSpanBase {
void set_pod_new(
std::string_view uid,
std::string_view owner_name,
std::string_view owner_uid,
std::string_view pod_name,
std::string_view ns,
std::string_view version,
Expand Down
6 changes: 5 additions & 1 deletion reducer/matching/flow_span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ void FlowSpan::update_node(::ebpf_net::matching::weak_refs::agg_root agg_root, F
jb_blob(n.address),
jb_blob(n.comm),
jb_blob(n.container_name),
jb_blob(n.pod_name));
jb_blob(n.pod_name),
jb_blob(n.role_uid));
}

void FlowSpan::create_agg_root(::ebpf_net::matching::weak_refs::flow flow, NodeData const &node_a, NodeData const &node_b)
Expand Down Expand Up @@ -316,6 +317,7 @@ FlowSpan::NodeData FlowSpan::resolve_node(::ebpf_net::matching::weak_refs::flow
auto [id, az, is_autonomous_system] = get_id_az(side);

std::string role;
std::string role_uid;
std::string version;
std::string env;
std::string ns;
Expand Down Expand Up @@ -364,6 +366,7 @@ FlowSpan::NodeData FlowSpan::resolve_node(::ebpf_net::matching::weak_refs::flow
// enrich
node_type = NodeResolutionType::K8S_CONTAINER;
role = pod.owner_name();
role_uid = pod.owner_uid();
version = pod.version();
ns = pod.ns();

Expand Down Expand Up @@ -477,6 +480,7 @@ FlowSpan::NodeData FlowSpan::resolve_node(::ebpf_net::matching::weak_refs::flow
.id = id,
.az = az,
.role = role,
.role_uid = role_uid,
.version = version,
.env = env,
.ns = ns,
Expand Down
1 change: 1 addition & 0 deletions reducer/matching/flow_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class FlowSpan : public ::ebpf_net::matching::FlowSpanBase {
std::string id;
std::string az;
std::string role;
std::string role_uid;
std::string version;
std::string env;
std::string ns;
Expand Down
1 change: 1 addition & 0 deletions reducer/matching/k8s_pod_span.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void K8sPodSpan::set_pod_detail(
{
span_ref.modify()
.owner_name({short_string_behavior::truncate, msg->owner_name})
.owner_uid({short_string_behavior::truncate, msg->owner_uid})
.pod_name({short_string_behavior::truncate, msg->pod_name})
.ns({short_string_behavior::truncate, msg->ns})
.version({short_string_behavior::truncate, msg->version});
Expand Down
7 changes: 7 additions & 0 deletions render/ebpf_net.render
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,9 @@ app ingest {
// can be obtained from docker label `io.kubernetes.pod.name`??
string<64> owner_name // name of the Deployment, DaemonSet, ReplicaSet or StatefulSet owning the pod

// owner uid
string<64> owner_uid

// can be obtained from docker label `io.kubernetes.pod.namespace`
string<64> ns

Expand Down Expand Up @@ -1343,6 +1346,7 @@ app matching {
u64 uid_hash

string<64> owner_name // name of the Deployment, DaemonSet, ReplicaSet or StatefulSet owning the pod
string<64> owner_uid
string<64> pod_name
string<64> ns
string<64> version
Expand All @@ -1357,6 +1361,7 @@ app matching {
2: string pod_name
3: string ns
4: string version
5: string owner_uid
}
} /* span k8s_pod */

Expand Down Expand Up @@ -1425,6 +1430,7 @@ app aggregation {
pool_size 70000
index (s, version, env, ns, node_type, process, container)
string<80> s
string<80> uid
string<64> version
string<32> env
string<64> ns
Expand Down Expand Up @@ -1498,6 +1504,7 @@ app aggregation {
11: string process
12: string container
13: string pod_name
14: string role_uid
}
14: msg update_tcp_metrics {
1: u8 direction
Expand Down

0 comments on commit f1aceba

Please sign in to comment.