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

CIRC-9456 - Implicit Tag Support #833

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e57418e
implicit tag implementation
RobBoeckermann Jan 18, 2023
2da45c6
rework & testing
RobBoeckermann Jan 18, 2023
a8c8f00
fix bug preventing adding tags to existing tagset due to inability to…
RobBoeckermann Jan 18, 2023
dbfaf75
reduce calls to builder functions by adding multiple tags at the same…
RobBoeckermann Jan 18, 2023
bfbe5f0
test el7 failure
RobBoeckermann Jan 18, 2023
f4a5653
revert logging from last commit. error is no longer occurring
RobBoeckermann Jan 18, 2023
3ee3273
convert test_tags.c to test_tags.cpp
RobBoeckermann Jan 19, 2023
d6ea76b
make test_tags c++ compatible
RobBoeckermann Jan 19, 2023
9818ad2
update makefile
RobBoeckermann Jan 19, 2023
673dcf3
review
RobBoeckermann Jan 20, 2023
6c793aa
rename to avoid confusion when using with `noit_metric_tagset_decode_…
RobBoeckermann Jan 20, 2023
bd1a402
use `NOIT_METRIC_TAGSET_CHECK` for hook so snowth's `check_tag_tagset…
RobBoeckermann Jan 23, 2023
f92847d
update test
RobBoeckermann Jan 23, 2023
7022bc4
keep string around
RobBoeckermann Jan 23, 2023
d01f772
initialize array to ensure no data is kept from previous calls
RobBoeckermann Jan 23, 2023
9d42dd3
const
RobBoeckermann Jan 23, 2023
0b219f8
initialize array to ensure lack of previous data
RobBoeckermann Jan 23, 2023
aec6bb7
use `noit_metric_tagset_cleanup` for tagsets
RobBoeckermann Jan 23, 2023
506fad4
properly initialize and clean tagsets
RobBoeckermann Jan 23, 2023
ee46b9f
fix testing leaks
RobBoeckermann Jan 24, 2023
823df65
fix seg fault
RobBoeckermann Mar 22, 2023
5b14a1f
formatting
RobBoeckermann Mar 22, 2023
8ecc00a
noit_metric_tag_t must have their members copied individually.
RobBoeckermann Apr 4, 2023
d0da8df
use `parsed_tag_count` instead of `tag_count` in case they differ.
RobBoeckermann Apr 10, 2023
9ebf3e8
cast char* to void*
RobBoeckermann Apr 11, 2023
5922d6e
Revert "cast char* to void*"
RobBoeckermann Apr 19, 2023
839fcdd
Revert "noit_metric_tag_t must have their members copied individually."
RobBoeckermann Apr 19, 2023
9ede60f
formatting
RobBoeckermann Apr 20, 2023
ca5d1f8
generate tag pairs and assert their lengths
RobBoeckermann Apr 20, 2023
43ea246
don't init out arg
RobBoeckermann Apr 24, 2023
62fb17f
"not" is reserved. use different name to avoid use of `_`.
RobBoeckermann Apr 24, 2023
f3b38f0
pass string by reference
RobBoeckermann Apr 24, 2023
bd7fedd
properly init tagsets
RobBoeckermann Apr 24, 2023
0b01bd4
const
RobBoeckermann Apr 24, 2023
82d4c48
use fmt::format
RobBoeckermann Apr 24, 2023
40663c3
add circonus-platform-library-fmt dependency
RobBoeckermann Apr 24, 2023
aa29143
avoid needing to define an additional value for `noit_metric_tagset_c…
RobBoeckermann Apr 25, 2023
303a7cd
+1 to ensured length to account for for colon added to cat-only tags
RobBoeckermann May 30, 2023
13b7ea7
call base64 functions instead of defining identical logic in multiple…
RobBoeckermann May 30, 2023
1a4e727
dynamically allocate memory
RobBoeckermann Jun 14, 2023
00c6540
free calloced memory
RobBoeckermann Jun 20, 2023
4efaf6d
Use the c++ extern "C" to properly link C functions to a cpp file
vasuraman11 Jun 20, 2023
ae0990a
get string length instead of array size
RobBoeckermann Jun 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions buildtools/el7/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ DEPS_BUILD="
DEPS_CIRC="
circonus-platform-lua-luasocket
circonus-developer-mtevbusted
circonus-platform-library-fmt
"

echo "Installing buildenv and reconnoiter deps"
Expand Down
1 change: 1 addition & 0 deletions buildtools/u2004/install-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ DEPS_CIRC="
circonus-platform-library-apr-util
circonus-platform-library-curl
circonus-platform-library-flatcc
circonus-platform-library-fmt
circonus-platform-library-grpc
circonus-platform-library-jemalloc
circonus-platform-library-jlog
Expand Down
11 changes: 11 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ AC_TRY_LINK([
[ AC_MSG_ERROR([failed]) ])
PTOOLSLIBS="$LIBS"
LIBS="$old_LIBS"
AC_CHECK_HEADER(fmt/core.h, [], [AC_MSG_ERROR(*** fmtlib (headers) required ***)])
SAVED_LIBS=$LIBS
LIBS="-lfmt"
AC_LINK_IFELSE(
[ AC_LANG_PROGRAM(
[ #include <fmt/core.h> ],
[ auto cant_discard_this_da_na_na_na = fmt::format("{}", 10); ]
)], ,
[ AC_MSG_ERROR([ "Could not find fmtlib" ]) ]
)
LIBS="$SAVED_LIBS"
AC_LANG_POP([C++])

AC_CHECK_HEADERS(gcrypt.h)
Expand Down
8 changes: 8 additions & 0 deletions src/libnoit.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
#ifndef LIBNOIT_H
#define LIBNOIT_H

#ifdef __cplusplus
extern "C" {
#endif

API_EXPORT(void)
libnoit_init_globals(void);


#ifdef __cplusplus
}
#endif
#endif
6 changes: 3 additions & 3 deletions src/modules/histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ log_histo(noit_check_t *check, uint64_t whence_s,
mtevL(noit_error, "malloc(%d) failed\n", (int)est);
goto cleanup;
}
enc_est = ((est + 2)/3)*4;
enc_est = mtev_b64_encode_len(est);
hist_encode = malloc(enc_est);
if(!hist_encode) {
mtevL(noit_error, "malloc(%d) failed\n", (int)enc_est);
Expand Down Expand Up @@ -676,7 +676,7 @@ histogram_stats_populate_xml_impl(void *closure, xmlNodePtr doc, noit_check_t *c
if(!hist_serial) {
mtevL(noit_error, "malloc(%d) failed\n", (int)est);
} else {
ssize_t enc_est = ((est + 2)/3)*4 + 1;
ssize_t enc_est = mtev_b64_encode_len(est) + 1;
hist_encode = malloc(enc_est+1);
if(!hist_encode) {
mtevL(noit_error, "malloc(%d) failed\n", (int)enc_est);
Expand Down Expand Up @@ -723,7 +723,7 @@ histogram_stats_populate_json_impl(void *closure, struct mtev_json_object *doc,
if(!hist_serial) {
mtevL(noit_error, "malloc(%d) failed\n", (int)est);
} else {
ssize_t enc_est = ((est + 2)/3)*4;
ssize_t enc_est = mtev_b64_encode_len(est);
hist_encode = malloc(enc_est);
if(!hist_encode) {
mtevL(noit_error, "malloc(%d) failed\n", (int)enc_est);
Expand Down
5 changes: 2 additions & 3 deletions src/noit_check_log_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ noit_check_log_bundle_compress_b64(noit_compression_type_t ctype,
}

/* Encode */
// Problems with the calculation?
initial_dlen = ((dlen + 2) / 3 * 4);
initial_dlen = mtev_b64_encode_len(dlen);
b64buff = malloc(initial_dlen);
if (!b64buff) {
free(compbuff);
Expand Down Expand Up @@ -130,7 +129,7 @@ noit_check_log_bundle_decompress_b64(noit_compression_type_t ctype,
char *compbuff, *rawbuff;

/* Decode */
initial_dlen = (((len_in + 3) / 4) * 3);
initial_dlen = mtev_b64_max_decode_len(len_in);
compbuff = malloc(initial_dlen);
if (!compbuff) return -1;
dlen = mtev_b64_decode((char *)buf_in, len_in,
Expand Down
59 changes: 36 additions & 23 deletions src/noit_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@

#include <mtev_defines.h>

#include <mtev_log.h>
#include <mtev_hash.h>
#include <mtev_watchdog.h>
#include <mtev_b64.h>
#include <mtev_capabilities_listener.h>
#include <mtev_conf.h>
#include <mtev_hash.h>
#include <mtev_log.h>
#include <mtev_watchdog.h>

#include "noit_mtev_bridge.h"
#include "noit_check.h"
Expand Down Expand Up @@ -644,9 +645,9 @@ noit_apply_filterrule(mtev_hash_table *m,
return mtev_false;
}
static mtev_boolean
noit_apply_filterrule_metric(filterrule_t *r,
const char *subj, int subj_len,
noit_metric_tagset_t *stset, noit_metric_tagset_t *mtset) {
noit_apply_filterrule_metric(filterrule_t *r, const char *subj, int subj_len,
noit_metric_tagset_t *stset,
noit_metric_tagset_t *mtset) {
int rc, ovector[30];
char canonicalcheck[MAX_METRIC_TAGGED_NAME];
canonicalcheck[0] = '\0';
Expand Down Expand Up @@ -774,27 +775,32 @@ noit_apply_filterset(const char *filterset,
const char *local_metric_name = noit_metric_get_full_metric_name(metric);
mtev_gettimeofday(&now, NULL);

char encoded_nametag[NOIT_TAG_MAX_PAIR_LEN+1];
char decoded_nametag[NOIT_TAG_MAX_PAIR_LEN+1];
noit_metric_tag_t stags[MAX_TAGS], mtags[MAX_TAGS];
noit_metric_tagset_t stset = { .tags = stags, .tag_count = MAX_TAGS };
noit_metric_tagset_t mtset = { .tags = mtags, .tag_count = MAX_TAGS };
noit_metric_tagset_t stset, mtset;
noit_metric_tagset_init(&stset, 0, 0);
stset.tags = calloc((MAX_TAGS + 1), sizeof(noit_metric_tag_t));
stset.tag_count = MAX_TAGS + 1;
noit_metric_tagset_init(&mtset, 0, 0);
mtset.tags = calloc(MAX_TAGS, sizeof(noit_metric_tag_t));
mtset.tag_count = MAX_TAGS;
int mlen = noit_metric_parse_tags(local_metric_name, strlen(metric->metric_name), &stset, &mtset);
if(mlen < 0) {
stset.tag_count = mtset.tag_count = 0;
mlen = strlen(local_metric_name);
}
if(stset.tag_count < MAX_TAGS-1) {
/* add __name */
snprintf(decoded_nametag, sizeof(decoded_nametag), "__name%c%.*s",
NOIT_TAG_DECODED_SEPARATOR, mlen, local_metric_name);
size_t nlen = noit_metric_tagset_encode_tag(encoded_nametag, sizeof(encoded_nametag),
decoded_nametag, strlen(decoded_nametag));
stset.tags[stset.tag_count].category_size = 7;
stset.tags[stset.tag_count].total_size = nlen;
stset.tags[stset.tag_count].tag = encoded_nametag;
stset.tag_count++;
}

// add __name tag to stream tags
mtev_dyn_buffer_t dbuff;
mtev_dyn_buffer_init(&dbuff);
const size_t max_encoded_len = mtev_b64_encode_len(NOIT_IMPLICIT_TAG_MAX_PAIR_LEN);
mtev_dyn_buffer_ensure(&dbuff, max_encoded_len);
mtev_dyn_buffer_add_printf(&dbuff, "__name%c%.*s", NOIT_TAG_DECODED_SEPARATOR,
mlen, local_metric_name);
const size_t nlen = noit_metric_tagset_encode_tag(
(char *)mtev_dyn_buffer_data(&dbuff), max_encoded_len,
(char *)mtev_dyn_buffer_data(&dbuff), mtev_dyn_buffer_used(&dbuff));
noit_metric_add_implicit_tags_to_tagset((char *)mtev_dyn_buffer_data(&dbuff),
nlen, &stset, NULL);

bool mt_modified = false;
int mt_tag_start = mtset.tag_count;
char *expanded_metric_name = NULL;
Expand All @@ -819,7 +825,8 @@ noit_apply_filterset(const char *filterset,
need_target = !MATCHES(target, check->target);
need_module = !MATCHES(module, check->module);
need_name = !MATCHES(name, check->name);
need_metric = !noit_apply_filterrule_metric(r, metric->metric_name, mlen, &stset, &mtset);
need_metric = !noit_apply_filterrule_metric(r, metric->metric_name, mlen,
&stset, &mtset);

if(!need_target && !need_module && !need_name && !need_metric) {
if(r->type == NOIT_FILTER_SKIPTO) {
Expand Down Expand Up @@ -922,14 +929,20 @@ noit_apply_filterset(const char *filterset,
break;
}
}
mtev_dyn_buffer_destroy(&dbuff);
noit_filter_filterset_free(fs);
if(!ret) ck_pr_inc_32(&fs->denies);
noit_metric_tagset_cleanup(&stset);
noit_metric_tagset_cleanup(&mtset);
return ret;
}
UNLOCKFS();
if (mt_modified) {
noit_update_metric_name(expanded_metric_name, &mtset, mt_tag_start, metric);
}
mtev_dyn_buffer_destroy(&dbuff);
noit_metric_tagset_cleanup(&stset);
noit_metric_tagset_cleanup(&mtset);
return mtev_false;
}

Expand Down