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

Add cli flag to disable name resolution #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ config_create()
config->sensor.frequency = 1000;
config->sensor.cgroup_basepath = "/sys/fs/cgroup/perf_event";
config->sensor.name = NULL;
config->sensor.resolve_names = true;

/* storage default config */
config->storage.type = STORAGE_CSV;
Expand Down Expand Up @@ -121,8 +122,11 @@ config_setup_from_cli(int argc, char **argv, struct config *config)
zhashx_set_duplicator(config->events.containers, (zhashx_duplicator_fn *) events_group_dup);
zhashx_set_destructor(config->events.containers, (zhashx_destructor_fn *) events_group_destroy);

while ((c = getopt(argc, argv, "vf:p:n:s:c:e:or:U:D:C:")) != -1) {
while ((c = getopt(argc, argv, "ivf:p:n:s:c:e:or:U:D:C:")) != -1) {
switch (c) {
case 'i':
config->sensor.resolve_names = false;
break;
case 'v':
config->sensor.frequency++;
break;
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct config_sensor
unsigned int verbose;
unsigned int frequency;
const char *cgroup_basepath;
bool resolve_names;
const char *name;
};

Expand Down
8 changes: 4 additions & 4 deletions src/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ setup_storage_module(struct config *config)
}

static void
sync_cgroups_running_monitored(struct hwinfo *hwinfo, zhashx_t *container_events_groups, const char *cgroup_basepath, zhashx_t *container_monitoring_actors)
sync_cgroups_running_monitored(struct hwinfo *hwinfo, zhashx_t *container_events_groups, const char *cgroup_basepath, bool resolve_name, zhashx_t *container_monitoring_actors)
{
zhashx_t *running_targets = NULL; /* char *cgroup_path -> struct target *target */
zactor_t *perf_monitor = NULL;
Expand All @@ -90,7 +90,7 @@ sync_cgroups_running_monitored(struct hwinfo *hwinfo, zhashx_t *container_events
running_targets = zhashx_new();

/* get running (and identifiable) container(s) */
if (target_discover_running(cgroup_basepath, TARGET_TYPE_EVERYTHING ^ TARGET_TYPE_UNKNOWN, running_targets)) {
if (target_discover_running(cgroup_basepath, TARGET_TYPE_EVERYTHING ^ TARGET_TYPE_UNKNOWN, resolve_name, running_targets)) {
zsys_error("sensor: error when retrieving the running targets.");
goto out;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ main(int argc, char **argv)

/* start system monitoring actor only when needed */
if (zhashx_size(config->events.system)) {
system_target = target_create(TARGET_TYPE_ALL, NULL);
system_target = target_create(TARGET_TYPE_ALL, NULL, config->sensor.resolve_names);
system_monitor_config = perf_config_create(hwinfo, config->events.system, system_target);
system_perf_monitor = zactor_new(perf_monitoring_actor, system_monitor_config);
}
Expand All @@ -256,7 +256,7 @@ main(int argc, char **argv)
while (!zsys_interrupted) {
/* monitor containers only when needed */
if (zhashx_size(config->events.containers)) {
sync_cgroups_running_monitored(hwinfo, config->events.containers, config->sensor.cgroup_basepath, container_monitoring_actors);
sync_cgroups_running_monitored(hwinfo, config->events.containers, config->sensor.cgroup_basepath, config->sensor.resolve_names , container_monitoring_actors);
}

/* send clock tick to monitoring actors */
Expand Down
19 changes: 14 additions & 5 deletions src/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ target_validate_type(enum target_type type, const char *cgroup_path)
}

struct target *
target_create(enum target_type type, const char *cgroup_path)
target_create(enum target_type type, const char *cgroup_path, bool resolve_name)
{
struct target *target = malloc(sizeof(struct target));

Expand All @@ -114,6 +114,7 @@ target_create(enum target_type type, const char *cgroup_path)

target->cgroup_path = (cgroup_path) ? strdup(cgroup_path) : NULL;
target->type = type;
target->resolve_name = resolve_name;

return target;
}
Expand All @@ -123,11 +124,19 @@ target_resolve_real_name(struct target *target)
{
switch (target->type) {
case TARGET_TYPE_DOCKER:
return target_docker_resolve_name(target);
if (target->resolve_name ) {
return target_docker_resolve_name(target);
} else {
return strdup(strrchr(target->cgroup_path, '/') + 1);
}
break;

case TARGET_TYPE_KUBERNETES:
return target_kubernetes_resolve_name(target);
if (target->resolve_name ) {
return target_kubernetes_resolve_name(target);
} else {
return strdup(strrchr(target->cgroup_path, '/') + 1);
}
break;

case TARGET_TYPE_ALL:
Expand All @@ -154,7 +163,7 @@ target_destroy(struct target *target)
}

int
target_discover_running(const char *base_path, enum target_type type_mask, zhashx_t *targets)
target_discover_running(const char *base_path, enum target_type type_mask, bool resolve_name, zhashx_t *targets)
{
const char *path[] = { base_path, NULL };
FTS *file_system = NULL;
Expand All @@ -174,7 +183,7 @@ target_discover_running(const char *base_path, enum target_type type_mask, zhash
if (node->fts_info == FTS_D && node->fts_statp->st_nlink == 2) {
type = target_detect_type(node->fts_path);
if ((type & type_mask) && target_validate_type(type, node->fts_path)) {
target = target_create(type, node->fts_path);
target = target_create(type, node->fts_path, resolve_name);
if (target)
zhashx_insert(targets, node->fts_path, target);
}
Expand Down
5 changes: 3 additions & 2 deletions src/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct target
{
enum target_type type;
char *cgroup_path;
bool resolve_name;
};

/*
Expand All @@ -77,7 +78,7 @@ int target_validate_type(enum target_type type, const char *cgroup_path);
/*
* target_create allocate the resources and configure the target.
*/
struct target *target_create(enum target_type type, const char *cgroup_path);
struct target *target_create(enum target_type type, const char *cgroup_path, bool resolve_name);

/*
* target_resolve_real_name resolve and return the real name of the given target.
Expand All @@ -92,7 +93,7 @@ void target_destroy(struct target *target);
/*
* target_discover_running returns a list of running targets.
*/
int target_discover_running(const char *base_path, enum target_type type_mask, zhashx_t *targets);
int target_discover_running(const char *base_path, enum target_type type_mask, bool resolve_name, zhashx_t *targets);

#endif /* TARGET_H */