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 support for Prometheus #150

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bb69917
Update the config loading mechanism to support the protocol type prom…
danielealbano Jul 6, 2022
c47103d
Import the http_parser from the nodejs project
danielealbano Jul 7, 2022
e21c518
Reorganize the stats to collect them per minute, to add some more inf…
danielealbano Jul 7, 2022
a619514
Reorganize program.c to have a global program_context and expose it v…
danielealbano Jul 7, 2022
d70f335
Rename per_second stat to per_minute, handle started_on_timestamp stat
danielealbano Jul 7, 2022
7614112
Add a wrapper function to fetch the wall clock time
danielealbano Jul 7, 2022
a0a5ca0
The redis parameter block is optional, it's required only when the pr…
danielealbano Jul 7, 2022
1397134
rename network_protocol_redis_process_events in network_protocol_redi…
danielealbano Jul 7, 2022
3a68a4f
Add a function to aggregate the statistics of all the workers
danielealbano Jul 7, 2022
8650074
Remove warning from test
danielealbano Jul 7, 2022
8ce9ca5
Update tests to reflect the refactoring
danielealbano Jul 7, 2022
3fa3d9e
Initial implementation of a prometheus module to provide metrics for …
danielealbano Jul 7, 2022
a106760
Clarify a comment for a test in test-fibers
danielealbano Jul 7, 2022
a59a686
Add error checking to the slab allocator
danielealbano Jul 7, 2022
3286173
Add a mechanism to reset the program context
danielealbano Jul 7, 2022
758427b
Add some basic tests for the prometheus module
danielealbano Jul 7, 2022
323140e
Update the redis commands test to use the new global program_context
danielealbano Jul 7, 2022
84ec714
Add the prometheus config block
danielealbano Jul 7, 2022
35f5f5d
Clean up unused variables and struct members
danielealbano Jul 7, 2022
1423152
Add documentation
danielealbano Jul 7, 2022
d99902b
Fix flaky url checking for routing, fix styles
danielealbano Jul 7, 2022
e08afa5
Merge branch 'fix-readme-links' into 149-add-an-module-for-prometheus…
danielealbano Jul 7, 2022
689b70a
Update docs
danielealbano Jul 7, 2022
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "3rdparty/xxHash"]
path = 3rdparty/xxHash
url = https://github.com/Cyan4973/xxHash.git
[submodule "3rdparty/nodejs-http-parser"]
path = 3rdparty/nodejs-http-parser
url = https://github.com/nodejs/http-parser
1 change: 1 addition & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include("libcyaml")
include("sentry")
include("t1ha")
include("xxhash")
include("nodejs-http-parser")

set(DEPS_LIST_LIBRARIES "${DEPS_LIST_LIBRARIES}" PARENT_SCOPE)
set(DEPS_LIST_INCLUDE_DIRS "${DEPS_LIST_INCLUDE_DIRS}" PARENT_SCOPE)
Expand Down
1 change: 1 addition & 0 deletions 3rdparty/nodejs-http-parser
Submodule nodejs-http-parser added at ec8b5e
25 changes: 25 additions & 0 deletions 3rdparty/nodejs-http-parser.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include(ExternalProject)
file(GLOB SRC_FILES_NODEJS_HTTP_PARSER "nodejs-http-parser/http_parser.c")

set(NODEJS_HTTP_PARSER_BUILD_PATH "${CMAKE_BINARY_DIR}/_deps/src/nodejs-http-parser-install-build")

add_library(
nodejs_http_parser
${SRC_FILES_NODEJS_HTTP_PARSER})

target_compile_options(
nodejs_http_parser
PRIVATE
-Wall -Wextra -Werror -O2 -fPIC)

target_compile_definitions(
nodejs_http_parser
PRIVATE
HTTP_PARSER_STRICT=0)

target_include_directories(
nodejs_http_parser
PUBLIC
nodejs-http-parser/)

list(APPEND DEPS_LIST_LIBRARIES "nodejs_http_parser")
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ system to process the network data
Key features:
- [Modular](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules.md) architecture to support widely used protocols, e.g.
[Redis](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/redis.md),
[Prometheus](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/prometheus.md), etc.
- [Time-series database](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/timeseries-db.md) for fast data writes and retrieval with
primitives built to handle different data types (e.g. small strings, large blobs, jsons, etc.);
- [Hashtable](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/hashtable.md) GET Lock-free and Wait-free operations, SET and DELETE use
Expand All @@ -33,9 +34,9 @@ Key features:
[benches](https://github.com/danielealbano/cachegrand/blob/main/docs/benchmarks/linear-vertical-scalability.md));

Planned Key Features:
- More modules for additional platforms compatibility, e.g. [Memcache](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/memcache.md),
etc., or to add support for monitoring, e.g. [Prometheus](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/prometheus.md),
[DataDog](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/datadog.md), etc.;
- More modules for additional platforms compatibility, e.g. [Memcache](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/memcache.md), AWS S3,
etc., or to add support for monitoring, e.g. [DataDog](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/datadog.md),
- etc.;
- Ad ad-hoc network stack based on DPDK / Linux XDP (eXpress Data Path) and the FreeBSD network stack;
- [Built for flash memories](https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/timeseries-db.md#flash-memories) to be able to efficiently saturate the
available IOPS in modern DC NVMEs and SSDs;
Expand Down
3 changes: 2 additions & 1 deletion docs/architecture/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Modules
cachegrand is a modular platform that provide the necessary infrastructure to implement high level business logic to
provide end-user functionalities.

Currently, the only module implemented is the one to expose Redis-like functionalities
Currently, there are two modules implemented, one that exposes Redis-like functionalities and one to provide an endpoint
for Prometheus to be able to collect metrics and setup monitoring & alerting.

## Architecture

Expand Down
59 changes: 58 additions & 1 deletion docs/architecture/modules/prometheus.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
Module - Prometheus
===================

Planned to be implemented
[Prometheus](https://prometheus.io/) is a well known and widely used monitoring and time-series database, often used in
combination with [Grafana](https://grafana.com/).

cachegrand provides a module to expose metrics for Prometheus via an HTTP endpoint that can be configured using the
config file.

## Configuration

To enable the module is enough to add the protocol configuration to the `protocols` section in the config file:
```yaml
- type: prometheus
timeout:
read_ms: 10000
write_ms: 10000
bindings:
- host: 127.0.0.1
port: 9090
```

The module currently doesn't provide any sort of authentication or https support.

### Metrics

The metrics are exposed on the `/metrics` endpoint.

The available metrics are:

| Name | Description | Type |
|----------------------------------------------------|-----------------------------------------------|---------|
| cachegrand_network_total_received_packets | Total amount of received packets | Counter |
| cachegrand_network_total_received_data | Total amount of received data (in bytes) | Counter |
| cachegrand_network_total_sent_packets | Total amount of sent packets | Counter |
| cachegrand_network_total_sent_data | Total amount of sent data | Counter |
| cachegrand_network_total_accepted_connections | Total amount of accepted connections | Counter |
| cachegrand_network_total_active_connections | Total amount of active connections | Counter |
| cachegrand_storage_total_written_data | Total amount of data written to disk | Counter |
| cachegrand_storage_total_write_iops | Total amount of write IOPS | Counter |
| cachegrand_storage_total_read_data | Total amount of read data from disk | Counter |
| cachegrand_storage_total_read_iops | Total amount of read IOPS | Counter |
| cachegrand_storage_total_open_files | Total amount of open files | Counter |
| cachegrand_network_per_minute_received_packets | Per minute amount of received packets | Counter |
| cachegrand_network_per_minute_received_data | Per minute amount of received data (in bytes) | Counter |
| cachegrand_network_per_minute_sent_packets | Per minute amount of sent packets | Counter |
| cachegrand_network_per_minute_sent_data | Per minute amount of sent data | Counter |
| cachegrand_network_per_minute_accepted_connections | Per minute amount of accepted connections | Counter |
| cachegrand_storage_per_minute_written_data | Per minute amount of data written to disk | Counter |
| cachegrand_storage_per_minute_write_iops | Per minute amount of write IOPS | Counter |
| cachegrand_storage_per_minute_read_data | Per minute amount of read data from disk | Counter |
| cachegrand_storage_per_minute_read_iops | Per minute amount of read IOPS | Counter |
| cachegrand_uptime | Uptime in seconds | Counter |

### Metrics labels

It is possible to tag the metrics with any amount of arbitrary labels using environment variables.

If one or more environment variables prefixed with `CACHEGRAND_METRIC_ENV_` exist then these will be parsed by
cachegrand and the suffix will be converted to lowercase and used as name of the label and the value of the environment
variable will be used as value.
4 changes: 4 additions & 0 deletions docs/benchmarks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Benchmarks
==========

TODO
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions etc/cachegrand.yaml.skel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ network:
- host: "::"
port: 6379

# Uncomment to enable prometheus support, more information available at
# https://github.com/danielealbano/cachegrand/blob/main/docs/architecture/modules/prometheus.md
# - type: prometheus
# timeout:
# read_ms: -1
# write_ms: 10000
# bindings:
# - host: 127.0.0.1
# port: 9090

database:
# Currently the internal cachegrand hashtable doesn't support the automatic resizing, if there isn't enough room the
# SET command will just fail with a generic error.
Expand Down
6 changes: 6 additions & 0 deletions src/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ void clock_monotonic(timespec_t *timespec) {
}
}

void clock_realtime(timespec_t *timespec) {
if (clock_gettime(CLOCK_REALTIME, timespec) < 0) {
FATAL(TAG, "Unable to fetch the time");
}
}

void clock_diff(timespec_t *result, timespec_t *a, timespec_t *b) {
result->tv_sec = a->tv_sec - b->tv_sec;
result->tv_nsec = a->tv_nsec - b->tv_nsec;
Expand Down
1 change: 1 addition & 0 deletions src/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
typedef struct timespec timespec_t;

void clock_monotonic(timespec_t *timespec);
void clock_realtime(timespec_t *timespec);
void clock_diff(timespec_t *result, timespec_t *a, timespec_t *b);

#ifdef __cplusplus
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {

enum config_network_protocol_type {
CONFIG_PROTOCOL_TYPE_REDIS,
CONFIG_PROTOCOL_TYPE_PROMETHEUS
};
typedef enum config_network_protocol_type config_network_protocol_type_t;

Expand Down
3 changes: 2 additions & 1 deletion src/config_cyaml_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const cyaml_schema_field_t config_network_protocol_redis_schema[] = {
// Allowed strings for for config -> network -> protocols -> protocol-> type (config_network_protocol_type_t)
const cyaml_strval_t config_network_protocol_type_schema_strings[] = {
{ "redis", CONFIG_PROTOCOL_TYPE_REDIS },
{ "prometheus", CONFIG_PROTOCOL_TYPE_PROMETHEUS },
};

typedef enum config_network_protocol_type config_network_protocol_type_t;
Expand All @@ -94,7 +95,7 @@ const cyaml_schema_field_t config_network_protocol_fields_schema[] = {
"keepalive", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
config_network_protocol_t, keepalive, config_network_protocol_keepalive_schema),
CYAML_FIELD_MAPPING_PTR(
"redis", CYAML_FLAG_POINTER,
"redis", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL,
config_network_protocol_t, redis, config_network_protocol_redis_schema),
CYAML_FIELD_SEQUENCE(
"bindings", CYAML_FLAG_POINTER,
Expand Down
8 changes: 6 additions & 2 deletions src/network/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ network_op_result_t network_receive(
channel->address.str);

worker_stats_t *stats = worker_stats_get();
stats->network.per_second.received_packets++;
stats->network.per_minute.received_packets++;
stats->network.total.received_packets++;
stats->network.per_minute.received_data += receive_length;
stats->network.total.received_data += receive_length;

return NETWORK_OP_RESULT_OK;
}
Expand Down Expand Up @@ -194,8 +196,10 @@ network_op_result_t network_send(
channel->address.str);

worker_stats_t *stats = worker_stats_get();
stats->network.per_second.sent_packets++;
stats->network.per_minute.sent_packets++;
stats->network.total.sent_packets++;
stats->network.per_minute.sent_data += send_length;
stats->network.total.sent_data += send_length;

return NETWORK_OP_RESULT_OK;
}
Expand Down
1 change: 1 addition & 0 deletions src/network/protocol/network_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
enum network_protocols {
NETWORK_PROTOCOLS_UNKNOWN = 0,
NETWORK_PROTOCOLS_REDIS,
NETWORK_PROTOCOLS_PROMETHEUS
};
typedef enum network_protocols network_protocols_t;

Expand Down
Loading