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

Fixed the issue with plugin - FOR-5318 #4215

Open
wants to merge 3 commits into
base: collectd-5.12
Choose a base branch
from

Conversation

rmahboubian
Copy link

What does this Change do?

Fixes the charts under performance charts.

Jira ticket number?

https://bigleafnetworks.atlassian.net/jira/software/c/projects/FOR/issues/FOR-5318

How should these changes be verified?

  • Build and register CPE.
  • Login to CPE and check if the python.so plugin file exists.
  • Run some traffic from LAN network
  • Check the charts under Web UI performance tab.

Checklist before approval and merge

  • Changes follow the rules and best practices defined in the [Bigleaf Coding Standards][bcs].
  • Commit messages provide useful information.

@rmahboubian rmahboubian requested review from a team as code owners December 27, 2023 00:06
@rmahboubian rmahboubian changed the base branch from main to collectd-5.12 December 27, 2023 00:10
@collectd-bot collectd-bot added this to the 5.12 milestone Dec 27, 2023
@rmahboubian rmahboubian changed the base branch from collectd-5.12 to main December 27, 2023 00:18
@rmahboubian rmahboubian changed the base branch from main to master December 27, 2023 00:18
@rmahboubian rmahboubian changed the base branch from master to collectd-5.13 December 27, 2023 00:19
@rmahboubian rmahboubian changed the base branch from collectd-5.13 to collectd-5.12 December 27, 2023 00:19
@octo
Copy link
Member

octo commented Dec 27, 2023

Hi @rmahboubian, thank you so much for your contribution!

Unfortunately I don't have access to https://bigleafnetworks.atlassian.net/jira/ – can you add to the PR description what the problem is this is solving? The PR description talks about the Python plugin, but the bulk of changes appear to be in the Ping plugin, is that intentional?

Best regards
—octo

Copy link
Member

@octo octo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rmahboubian, thank you for your PR! Overall this looks good, just some things we need to iron out ;)

Best regards
—octo

Comment on lines +656 to +658
if (src_host == NULL) {
ERROR("ping plugin: malloc failed to alloc src_host in submit");
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a return statement here so the rest of the function does not need to be indented in an else block.

https://google.github.io/styleguide/go/decisions.html#indent-error-flow

Comment on lines +659 to +661
sstrncpy(src_host, source, strlen(source) + 1);
strcat(src_host, "_");
strcat(src_host, host);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use utils/strbuf/strbuf.h here:

strbuf_t buf = STRBUF_CREATE;
strbuf_printf(&buf, "%s_%s", src_host, host);
/* use buf.ptr, which contains the string */
STRBUF_DESTROY(buf);

sstrncpy(vl.type, type, sizeof(vl.type));

plugin_dispatch_values(&vl);
char *src_host = (char *)malloc(strlen(source) + strlen(host) + 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src_host is only written to, but never read. Are you missing a

sstrncpy(vl.host, src_host, sizeof(vl.host));

in this function?

Comment on lines +514 to +516
hostlist_t *hl;
char *host = NULL;
hl = malloc(sizeof(*hl));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use calloc instead of malloc so that the buffer is zeroed.

Suggested change
hostlist_t *hl;
char *host = NULL;
hl = malloc(sizeof(*hl));
hostlist_t *hl = calloc(1, sizeof(*hl));
/* declare `host` just before calling `cf_util_get_string` */

Comment on lines +491 to +492
sourcelist_t *sl;
sl = calloc(1, sizeof(*sl));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sourcelist_t *sl;
sl = calloc(1, sizeof(*sl));
sourcelist_t *sl = calloc(1, sizeof(*sl));

Comment on lines +452 to +457
sourcelist_t *sl;
if (sourcelist_head == NULL) {
NOTICE("ping plugin: No sources have been configured.");
return -1;
}
sl = sourcelist_head;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sourcelist_t *sl;
if (sourcelist_head == NULL) {
NOTICE("ping plugin: No sources have been configured.");
return -1;
}
sl = sourcelist_head;
sourcelist_t *sl = sourcelist_head;
if (sl == NULL) {
NOTICE("ping plugin: No sources have been configured.");
return -1;
}

status = pthread_join(sl->ping_thread_id, /* return = */ NULL);
if (status != 0) {
ERROR("ping plugin: Stopping thread failed.");
status = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not work as intended: in the next iteration, status will be reset to the return value of pthread_join, which may be successful. So this function may return zero even though one of the joins failed.

I suggest to introduce a new variable, int last_err = 0; before the for loop and add last_err = status; to the error handling inside the loop.

if (status != 0) {
ping_thread_loop = 0;
ERROR("ping plugin: Starting thread failed.");
if (ping_thread_loop == 0) {
pthread_mutex_unlock(&ping_lock);
return -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for commenting on pre-existing code, but this really should return zero.

Suggested change
return -1;
return 0;

Comment on lines +292 to 301
if (sl->source != NULL && !sl->is_device)
if (ping_setopt(pingobj, PING_OPT_SOURCE, (void *)sl->source) != 0)
ERROR("ping plugin: Failed to set source address: %s",
ping_get_error(pingobj));

#ifdef HAVE_OPING_1_3
if (ping_device != NULL)
if (ping_setopt(pingobj, PING_OPT_DEVICE, (void *)ping_device) != 0)
if (sl->source != NULL && sl->is_device)
if (ping_setopt(pingobj, PING_OPT_DEVICE, (void *)sl->source) != 0)
ERROR("ping plugin: Failed to set device: %s", ping_get_error(pingobj));
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was previously possible to set source address and device. By using sourcelist_t.source for both, we lose this functionality.

I suggest that we have two char * fields in sourcelist_t, src_addr and device, and that we remove the is_device boolean. WDYT?

@octo octo added the Waiting for response - 1st time Waiting for contributor to respond - 1st call label Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Waiting for response - 1st time Waiting for contributor to respond - 1st call
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants