Skip to content

Commit 08649be

Browse files
authored
Port ACLs, Management API and Health commands (netdata#4969)
##### Summary fixes netdata#2673 fixes netdata#2149 fixes netdata#5017 fixes netdata#3830 fixes netdata#3187 fixes netdata#5154 Implements a command API for health which will accept commands via a socket to selectively suppress health checks. Allows different ports to accept different request types (streaming, dashboard, api, registry, netdata.conf, badges, management) Removes support for multi-threaded and single-threaded web servers. ##### Component Name health, daemon
1 parent 67834f1 commit 08649be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2078
-1105
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ cgroup-network
5151
!cgroup-network/
5252

5353
# installation artifacts
54-
installer/.environment.sh
5554
packaging/installer/.environment.sh
5655
*.tar.*
5756
*.run
@@ -140,6 +139,7 @@ tests/profile/benchmark-line-parsing
140139
tests/profile/benchmark-procfile-parser
141140
tests/profile/benchmark-value-pairs
142141
tests/profile/statsd-stress
142+
tests/health_mgmtapi/health-cmdapi-test.sh
143143
oprofile_data/
144144
vgcore.*
145145
callgrind.out.*

CMakeLists.txt

+6-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ find_package(PkgConfig REQUIRED)
1313
#set(CMAKE_BUILD_TYPE "Release")
1414

1515
# set this to see the compilation commands
16-
#set(CMAKE_VERBOSE_MAKEFILE 1)
16+
# set(CMAKE_VERBOSE_MAKEFILE 1)
1717

1818

1919
# -----------------------------------------------------------------------------
@@ -30,8 +30,8 @@ IF("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
3030
set(CXX_FORMAT_SIGNEDNESS "-Wformat-signedness")
3131
set(CXX_FORMAT_SECURITY "-Werror=format-security")
3232
set(CXX_STACK_PROTECTOR "-fstack-protector-all")
33-
34-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -ggdb -Wall -Wextra -DNETDATA_INTERNAL_CHECKS=1 -DNETDATA_VERIFY_LOCKS=1 ${CXX_FORMAT_SIGNEDNESS} ${CXX_FORMAT_SECURITY} ${CXX_STACK_PROTECTOR}")
33+
set(CXX_FLAGS_DEBUG "-O0")
34+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -ggdb -Wall -Wextra -DNETDATA_INTERNAL_CHECKS=1 -DNETDATA_VERIFY_LOCKS=1 ${CXX_FORMAT_SIGNEDNESS} ${CXX_FORMAT_SECURITY} ${CXX_STACK_PROTECTOR} ${CXX_FLAGS_DEBUG}")
3535
ELSE()
3636
message(STATUS "building for: release")
3737
cmake_policy(SET CMP0069 "NEW")
@@ -221,8 +221,7 @@ set(HEALTH_PLUGIN_FILES
221221
health/health.h
222222
health/health_config.c
223223
health/health_json.c
224-
health/health_log.c
225-
)
224+
health/health_log.c)
226225

227226
set(IDLEJITTER_PLUGIN_FILES
228227
collectors/idlejitter.plugin/plugin_idlejitter.c
@@ -354,10 +353,6 @@ set(WEB_PLUGIN_FILES
354353
web/server/web_client.h
355354
web/server/web_server.c
356355
web/server/web_server.h
357-
web/server/single/single-threaded.c
358-
web/server/single/single-threaded.h
359-
web/server/multi/multi-threaded.c
360-
web/server/multi/multi-threaded.h
361356
web/server/static/static-threaded.c
362357
web/server/static/static-threaded.h
363358
web/server/web_client_cache.c
@@ -411,6 +406,7 @@ set(API_PLUGIN_FILES
411406
web/api/formatters/charts2json.h
412407
web/api/formatters/rrdset2json.c
413408
web/api/formatters/rrdset2json.h
409+
web/api/health/health_cmdapi.c
414410
)
415411

416412
set(STREAMING_PLUGIN_FILES
@@ -479,7 +475,7 @@ add_definitions(
479475
-DLIBCONFIG_DIR="/usr/lib/netdata/conf.d"
480476
-DLOG_DIR="/var/log/netdata"
481477
-DPLUGINS_DIR="/usr/libexec/netdata"
482-
-DWEB_DIR="/usr/share/netdata"
478+
-DWEB_DIR="/usr/share/netdata/web"
483479
-DVARLIB_DIR="/var/lib/netdata"
484480
)
485481

Makefile.am

+2-4
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ API_PLUGIN_FILES = \
337337
web/api/formatters/charts2json.h \
338338
web/api/formatters/rrdset2json.c \
339339
web/api/formatters/rrdset2json.h \
340+
web/api/health/health_cmdapi.c \
341+
web/api/health/health_cmdapi.h \
340342
web/api/web_api_v1.c \
341343
web/api/web_api_v1.h \
342344
$(NULL)
@@ -374,10 +376,6 @@ WEB_PLUGIN_FILES = \
374376
web/server/web_server.h \
375377
web/server/web_client_cache.c \
376378
web/server/web_client_cache.h \
377-
web/server/single/single-threaded.c \
378-
web/server/single/single-threaded.h \
379-
web/server/multi/multi-threaded.c \
380-
web/server/multi/multi-threaded.h \
381379
web/server/static/static-threaded.c \
382380
web/server/static/static-threaded.h \
383381
$(NULL)

build/subst.inc

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
-e 's#[@]configdir_POST@#$(configdir)#g' \
66
-e 's#[@]libconfigdir_POST@#$(libconfigdir)#g' \
77
-e 's#[@]cachedir_POST@#$(cachedir)#g' \
8+
-e 's#[@]registrydir_POST@#$(registrydir)#g' \
9+
-e 's#[@]varlibdir_POST@#$(varlibdir)#g' \
810
$< > [email protected]; then \
911
mv "[email protected]" "$@"; \
1012
else \

configure.ac

+1-2
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,9 @@ AC_CONFIG_FILES([
609609
web/api/queries/ses/Makefile
610610
web/api/queries/stddev/Makefile
611611
web/api/queries/sum/Makefile
612+
web/api/health/Makefile
612613
web/gui/Makefile
613614
web/server/Makefile
614-
web/server/single/Makefile
615-
web/server/multi/Makefile
616615
web/server/static/Makefile
617616
])
618617
AC_OUTPUT

daemon/main.c

+2-19
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ struct netdata_static_thread static_threads[] = {
6767

6868
// common plugins for all systems
6969
{"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main},
70-
{"WEB_SERVER[multi]", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
71-
{"WEB_SERVER[single]", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
7270
{"WEB_SERVER[static1]", NULL, NULL, 0, NULL, NULL, socket_listen_main_static_threaded},
7371
{"STREAM", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
7472

@@ -81,18 +79,10 @@ struct netdata_static_thread static_threads[] = {
8179
void web_server_threading_selection(void) {
8280
web_server_mode = web_server_mode_id(config_get(CONFIG_SECTION_WEB, "mode", web_server_mode_name(web_server_mode)));
8381

84-
int multi_threaded = (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED);
85-
int single_threaded = (web_server_mode == WEB_SERVER_MODE_SINGLE_THREADED);
8682
int static_threaded = (web_server_mode == WEB_SERVER_MODE_STATIC_THREADED);
8783

8884
int i;
8985
for (i = 0; static_threads[i].name; i++) {
90-
if (static_threads[i].start_routine == socket_listen_main_multi_threaded)
91-
static_threads[i].enabled = multi_threaded;
92-
93-
if (static_threads[i].start_routine == socket_listen_main_single_threaded)
94-
static_threads[i].enabled = single_threaded;
95-
9686
if (static_threads[i].start_routine == socket_listen_main_static_threaded)
9787
static_threads[i].enabled = static_threaded;
9888
}
@@ -113,6 +103,8 @@ void web_server_config_options(void) {
113103
web_allow_registry_from = simple_pattern_create(config_get(CONFIG_SECTION_REGISTRY, "allow from", "*"), NULL, SIMPLE_PATTERN_EXACT);
114104
web_allow_streaming_from = simple_pattern_create(config_get(CONFIG_SECTION_WEB, "allow streaming from", "*"), NULL, SIMPLE_PATTERN_EXACT);
115105
web_allow_netdataconf_from = simple_pattern_create(config_get(CONFIG_SECTION_WEB, "allow netdata.conf from", "localhost fd* 10.* 192.168.* 172.16.* 172.17.* 172.18.* 172.19.* 172.20.* 172.21.* 172.22.* 172.23.* 172.24.* 172.25.* 172.26.* 172.27.* 172.28.* 172.29.* 172.30.* 172.31.*"), NULL, SIMPLE_PATTERN_EXACT);
106+
web_allow_mgmt_from = simple_pattern_create(config_get(CONFIG_SECTION_WEB, "allow management from", "localhost"), NULL, SIMPLE_PATTERN_EXACT);
107+
116108

117109
#ifdef NETDATA_WITH_ZLIB
118110
web_enable_gzip = config_get_boolean(CONFIG_SECTION_WEB, "enable gzip compression", web_enable_gzip);
@@ -367,13 +359,6 @@ void log_init(void) {
367359
}
368360

369361
static void backwards_compatible_config() {
370-
// allow existing configurations to work with the current version of netdata
371-
372-
if(config_exists(CONFIG_SECTION_GLOBAL, "multi threaded web server")) {
373-
int mode = config_get_boolean(CONFIG_SECTION_GLOBAL, "multi threaded web server", 1);
374-
web_server_mode = (mode)?WEB_SERVER_MODE_MULTI_THREADED:WEB_SERVER_MODE_SINGLE_THREADED;
375-
}
376-
377362
// move [global] options to the [web] section
378363
config_move(CONFIG_SECTION_GLOBAL, "http port listen backlog",
379364
CONFIG_SECTION_WEB, "listen backlog");
@@ -876,7 +861,6 @@ int main(int argc, char **argv) {
876861
load_netdata_conf(NULL, 0);
877862
}
878863

879-
backwards_compatible_config();
880864
get_netdata_configured_variables();
881865

882866
const char *section = argv[optind];
@@ -1056,7 +1040,6 @@ int main(int argc, char **argv) {
10561040

10571041
rrd_init(netdata_configured_hostname);
10581042

1059-
10601043
// ------------------------------------------------------------------------
10611044
// enable log flood protection
10621045

database/rrdcalc.h

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define RRDCALC_FLAG_WARN_ERROR 0x00000010
2626
#define RRDCALC_FLAG_CRIT_ERROR 0x00000020
2727
#define RRDCALC_FLAG_RUNNABLE 0x00000040
28+
#define RRDCALC_FLAG_DISABLED 0x00000080
29+
#define RRDCALC_FLAG_SILENCED 0x00000100
2830
#define RRDCALC_FLAG_NO_CLEAR_NOTIFICATION 0x80000000
2931

3032
struct rrdcalc {

database/rrdhost.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ static inline void rrdhost_init_machine_guid(RRDHOST *host, const char *machine_
103103
host->hash_machine_guid = simple_hash(host->machine_guid);
104104
}
105105

106-
107106
// ----------------------------------------------------------------------------
108107
// RRDHOST - add a host
109108

@@ -149,6 +148,7 @@ RRDHOST *rrdhost_create(const char *hostname,
149148

150149
rrdhost_init_hostname(host, hostname);
151150
rrdhost_init_machine_guid(host, guid);
151+
152152
rrdhost_init_os(host, os);
153153
rrdhost_init_timezone(host, timezone);
154154
rrdhost_init_tags(host, tags);
@@ -442,7 +442,7 @@ void rrdhost_cleanup_orphan_hosts_nolock(RRDHOST *protected) {
442442
void rrd_init(char *hostname) {
443443
rrdset_free_obsolete_time = config_get_number(CONFIG_SECTION_GLOBAL, "cleanup obsolete charts after seconds", rrdset_free_obsolete_time);
444444
gap_when_lost_iterations_above = (int)config_get_number(CONFIG_SECTION_GLOBAL, "gap when lost iterations above", gap_when_lost_iterations_above);
445-
if(gap_when_lost_iterations_above < 1)
445+
if (gap_when_lost_iterations_above < 1)
446446
gap_when_lost_iterations_above = 1;
447447

448448
health_init();
@@ -471,6 +471,7 @@ void rrd_init(char *hostname) {
471471
, 1
472472
);
473473
rrd_unlock();
474+
web_client_api_v1_management_init();
474475
}
475476

476477
// ----------------------------------------------------------------------------

database/rrdsetvar.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ RRDSETVAR *rrdsetvar_custom_chart_variable_create(RRDSET *st, const char *name)
150150
if(hash == rs->hash && strcmp(n, rs->variable) == 0) {
151151
rrdset_unlock(st);
152152
if(rs->options & RRDVAR_OPTION_CUSTOM_CHART_VAR) {
153-
free(n);
153+
freez(n);
154154
return rs;
155155
}
156156
else {
157157
error("RRDSETVAR: custom variable '%s' on chart '%s' of host '%s', conflicts with an internal chart variable", n, st->id, host->hostname);
158-
free(n);
158+
freez(n);
159159
return NULL;
160160
}
161161
}

database/rrdvar.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static RRDVAR *rrdvar_custom_variable_create(const char *scope, avl_tree_lock *t
137137

138138
RRDVAR *rv = rrdvar_create_and_index(scope, tree_lock, name, RRDVAR_TYPE_CALCULATED, RRDVAR_OPTION_CUSTOM_HOST_VAR|RRDVAR_OPTION_ALLOCATED, v);
139139
if(unlikely(!rv)) {
140-
free(v);
140+
freez(v);
141141
debug(D_VARIABLES, "Requested variable '%s' already exists - possibly 2 plugins are updating it at the same time.", name);
142142

143143
char *variable = strdupz(name);

docs/generator/buildyaml.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ markdown_extensions:
9494
- pymdownx.caret
9595
- pymdownx.critic
9696
- pymdownx.details
97-
- pymdownx.emoji:
98-
emoji_generator: !!python/name:pymdownx.emoji.to_svg
9997
- pymdownx.inlinehilite
10098
- pymdownx.magiclink
10199
- pymdownx.mark
@@ -234,5 +232,5 @@ echo -ne "- Hacking netdata:
234232
navpart 2 makeself "" "" 4
235233
navpart 2 libnetdata "" "libnetdata" 4
236234
navpart 2 contrib
237-
navpart 2 tests
235+
navpart 2 tests "" "" 2
238236
navpart 2 diagrams/data_structures

docs/generator/requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
mkdocs>=1.0.1
22
mkdocs-material
3-

health/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ The simple pattern syntax and operation is explained in [simple patterns](../lib
159159

160160
#### Alarm line `lookup`
161161

162-
This lines makes a database lookup to find a value. This result of this lookup is available as `$this`.
162+
This line makes a database lookup to find a value. This result of this lookup is available as `$this`.
163163

164164
The format is:
165165

@@ -465,7 +465,7 @@ Although the `alarm_variables` link shows you variables for a particular chart,
465465
- `$status`, which is resolved to the current status of the alarm (the current = the last
466466
status, i.e. before the current database lookup and the evaluation of the `calc` line).
467467
This values can be compared with `$REMOVED`, `$UNINITIALIZED`, `$UNDEFINED`, `$CLEAR`,
468-
`$WARNING`, `$CRITICAL`. These values are incremental, ie. `$status > $CLEAL` works as
468+
`$WARNING`, `$CRITICAL`. These values are incremental, ie. `$status > $CLEAR` works as
469469
expected.
470470

471471
- `$now`, which is resolved to current unix timestamp.
@@ -653,5 +653,11 @@ You can find the context of charts by looking up the chart in either
653653

654654
You can find how netdata interpreted the expressions by examining the alarm at `http://your.netdata:19999/api/v1/alarms?all`. For each expression, netdata will return the expression as given in its config file, and the same expression with additional parentheses added to indicate the evaluation flow of the expression.
655655

656+
## Disabling health checks or silencing notifications at runtime
657+
658+
The health checks can be controlled at runtime via the [health management api](../web/api/health/#health-management-api).
656659

657660
[![analytics](https://www.google-analytics.com/collect?v=1&aip=1&t=pageview&_s=1&ds=github&dr=https%3A%2F%2Fgithub.com%2Fnetdata%2Fnetdata&dl=https%3A%2F%2Fmy-netdata.io%2Fgithub%2Fhealth%2FREADME&_u=MAC~&cid=5792dfd7-8dc4-476b-af31-da2fdb9f93d2&tid=UA-64295674-3)]()
661+
662+
663+

0 commit comments

Comments
 (0)