diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2022-06-13 20:35:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-13 20:35:45 +0300 |
commit | 1b0f6c6b2296dc082d85f38c298a61442dcf2490 (patch) | |
tree | 2cfee5101d9cae338d0635f44fe62b010f3548ee /daemon | |
parent | 4c64b8ea4ff720d946bbb9a11ca7474c5673bb6c (diff) |
Labels with dictionary (#13070)
* squashed and rebased to master
* fix overflow and single character bug in sanitize; include rrd.h instead of node_info.h
* added unittest for UTF-8 multibyte sanitization
* Fix unit test compilation
* Fix CMake build
* remove double sanitizer for opentsdb; cleanup sanitize_json_string()
* rename error_description to error_message to avoid conflict with json-c
* revert last and undef error_description from json-c
* more unittests; attempt to fix protobuf map issue
* get rid of rrdlabels_get() and replace it with a safe version that writes the value to a buffer
* added dictionary sorting unittest; rrdlabels_to_buffer() now is sorted
* better sorted dictionary checking
* proper unittesting for sorted dictionaries
* call dictionary deletion callback when destroying the dictionary
* remove obsolete variable
* Fix exporting unit tests
* Fix k8s label parsing test
* workaround for cmocka and strdupz()
* Bypass cmocka memory allocation check
* Revert "Bypass cmocka memory allocation check"
This reverts commit 4c49923839d9229bea23ca914dd8a0be1ebe2bf4.
* Revert "workaround for cmocka and strdupz()"
This reverts commit 7bebee04801db1865c748a7896d5fa54bb7104a5.
* Bypass cmocka memory allocation checks
* respect json formatting for chart labels
* cloud sends colons
* print the value only once
* allow parenthesis in values and spaces; make stream sender send quotes for values
Co-authored-by: Vladimir Kobal <vlad@prokk.net>
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/commands.c | 12 | ||||
-rw-r--r-- | daemon/get-kubernetes-labels.sh.in | 17 | ||||
-rw-r--r-- | daemon/main.c | 3 |
3 files changed, 13 insertions, 19 deletions
diff --git a/daemon/commands.c b/daemon/commands.c index 6efc37c960..13d8dbd40d 100644 --- a/daemon/commands.c +++ b/daemon/commands.c @@ -217,17 +217,7 @@ static cmd_status_t cmd_reload_labels_execute(char *args, char **message) reload_host_labels(); BUFFER *wb = buffer_create(10); - - rrdhost_rdlock(localhost); - netdata_rwlock_rdlock(&localhost->labels.labels_rwlock); - struct label *l = localhost->labels.head; - while (l != NULL) { - buffer_sprintf(wb,"Label [source id=%s]: \"%s\" -> \"%s\"\n", translate_label_source(l->label_source), l->key, l->value); - l = l->next; - } - netdata_rwlock_unlock(&localhost->labels.labels_rwlock); - rrdhost_unlock(localhost); - + rrdlabels_log_to_buffer(localhost->host_labels, wb); (*message)=strdupz(buffer_tostring(wb)); buffer_free(wb); diff --git a/daemon/get-kubernetes-labels.sh.in b/daemon/get-kubernetes-labels.sh.in index 7e11ba3dd5..bc82c2aee7 100644 --- a/daemon/get-kubernetes-labels.sh.in +++ b/daemon/get-kubernetes-labels.sh.in @@ -1,4 +1,5 @@ #!/usr/bin/env bash +me="$(basename "${0}")" # Checks if netdata is running in a kubernetes pod and fetches: # - pod's labels @@ -8,8 +9,8 @@ if [ -z "${KUBERNETES_SERVICE_HOST}" ] || [ -z "${KUBERNETES_PORT_443_TCP_PORT}" exit 0 fi -if ! command -v jq > /dev/null 2>&1; then - echo "jq command not available. Please install jq to get host labels for kubernetes pods." +if ! command -v jq >/dev/null 2>&1; then + echo >&2 "${me}: jq command not available. Please install jq to get host labels for kubernetes pods." exit 1 fi @@ -18,24 +19,24 @@ HEADER="Authorization: Bearer $TOKEN" HOST="$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT" URL="https://$HOST/api/v1/namespaces/$MY_POD_NAMESPACE/pods/$MY_POD_NAME" -if ! POD_DATA=$(curl -sSk -H "$HEADER" "$URL" 2>&1); then - echo "error on curl '${URL}': ${POD_DATA}." +if ! POD_DATA=$(curl --fail -sSk -H "$HEADER" "$URL" 2>&1); then + echo >&2 "${me}: error on curl '${URL}': ${POD_DATA}." exit 1 fi URL="https://$HOST/api/v1/namespaces/kube-system" -if ! KUBE_SYSTEM_NS_DATA=$(curl -sSk -H "$HEADER" "$URL" 2>&1); then - echo "error on curl '${URL}': ${KUBE_SYSTEM_NS_DATA}." +if ! KUBE_SYSTEM_NS_DATA=$(curl --fail -sSk -H "$HEADER" "$URL" 2>&1); then + echo >&2 "${me}: error on curl '${URL}': ${KUBE_SYSTEM_NS_DATA}." exit 1 fi if ! POD_LABELS=$(jq -r '.metadata.labels' <<< "$POD_DATA" | grep ':' | tr -d '," ' 2>&1); then - echo "error on 'jq' parse pod data: ${POD_LABELS}." + echo >&2 "${me}: error on 'jq' parse pod data: ${POD_LABELS}." exit 1 fi if ! KUBE_SYSTEM_NS_UID=$(jq -r '.metadata.uid' <<< "$KUBE_SYSTEM_NS_DATA" 2>&1); then - echo "error on 'jq' parse kube_system_ns: ${KUBE_SYSTEM_NS_UID}." + echo >&2 "${me}: error on 'jq' parse kube_system_ns: ${KUBE_SYSTEM_NS_UID}." exit 1 fi diff --git a/daemon/main.c b/daemon/main.c index e10d38b406..ef5ba97b43 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -898,6 +898,9 @@ int main(int argc, char **argv) { else if(strcmp(optarg, "dicttest") == 0) { return dictionary_unittest(10000); } + else if(strcmp(optarg, "rrdlabelstest") == 0) { + return rrdlabels_unittest(); + } else if(strncmp(optarg, createdataset_string, strlen(createdataset_string)) == 0) { optarg += strlen(createdataset_string); unsigned history_seconds = strtoul(optarg, NULL, 0); |