Skip to content

Commit

Permalink
prometheus_remote_write: Fix cutoff logic.
Browse files Browse the repository at this point in the history
A single stale metric can suppress encoding of all following non-stale
metrics if the return code CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR
is not treated as success.
  • Loading branch information
PromyLOPh committed Oct 1, 2024
1 parent 4651386 commit 66ced89
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/cmt_encode_prometheus_remote_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,11 @@ int pack_basic_type(struct cmt_prometheus_remote_write_context *context,
int result;
struct cfl_list *head;
uint64_t now;
int cutoff;

context->sequence_number++;
add_metadata = CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_ADD_METADATA;
cutoff = CMT_FALSE;

now = cfl_time_now();

Expand All @@ -689,7 +691,8 @@ int pack_basic_type(struct cmt_prometheus_remote_write_context *context,
if (check_staled_timestamp(metric, now,
CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_THRESHOLD)) {
/* Skip processing metrics which are staled over over the threshold */
return CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR;
cutoff = CMT_TRUE;
continue;
}

result = pack_basic_metric_sample(context, map, metric, add_metadata);
Expand All @@ -703,7 +706,9 @@ int pack_basic_type(struct cmt_prometheus_remote_write_context *context,
}
}

return CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS;
return cutoff == CMT_TRUE ?
CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR :
CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS;
}

int pack_complex_metric_sample(struct cmt_prometheus_remote_write_context *context,
Expand Down Expand Up @@ -1111,7 +1116,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
}
}

if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
/* Gauges */
cfl_list_foreach(head, &cmt->gauges) {
gauge = cfl_list_entry(head, struct cmt_gauge, _head);
Expand All @@ -1127,7 +1133,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
}
}

if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
/* Untyped */
cfl_list_foreach(head, &cmt->untypeds) {
untyped = cfl_list_entry(head, struct cmt_untyped, _head);
Expand All @@ -1139,7 +1146,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
}
}

if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
/* Summaries */
cfl_list_foreach(head, &cmt->summaries) {
summary = cfl_list_entry(head, struct cmt_summary, _head);
Expand All @@ -1155,7 +1163,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
}
}

if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
/* Histograms */
cfl_list_foreach(head, &cmt->histograms) {
histogram = cfl_list_entry(head, struct cmt_histogram, _head);
Expand Down

0 comments on commit 66ced89

Please sign in to comment.