Skip to content

Commit e97c84b

Browse files
PromyLOPhldbr587
authored andcommitted
prometheus_remote_write: Fix cutoff logic.
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. Signed-off-by: Lars-Dominik Braun <[email protected]>
1 parent 4651386 commit e97c84b

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/cmt_encode_prometheus_remote_write.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,11 @@ int pack_basic_type(struct cmt_prometheus_remote_write_context *context,
663663
int result;
664664
struct cfl_list *head;
665665
uint64_t now;
666+
int cutoff;
666667

667668
context->sequence_number++;
668669
add_metadata = CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_ADD_METADATA;
670+
cutoff = CMT_FALSE;
669671

670672
now = cfl_time_now();
671673

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

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

706-
return CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS;
709+
return cutoff == CMT_TRUE ?
710+
CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR :
711+
CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS;
707712
}
708713

709714
int pack_complex_metric_sample(struct cmt_prometheus_remote_write_context *context,
@@ -1111,7 +1116,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
11111116
}
11121117
}
11131118

1114-
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
1119+
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
1120+
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
11151121
/* Gauges */
11161122
cfl_list_foreach(head, &cmt->gauges) {
11171123
gauge = cfl_list_entry(head, struct cmt_gauge, _head);
@@ -1127,7 +1133,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
11271133
}
11281134
}
11291135

1130-
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
1136+
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
1137+
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
11311138
/* Untyped */
11321139
cfl_list_foreach(head, &cmt->untypeds) {
11331140
untyped = cfl_list_entry(head, struct cmt_untyped, _head);
@@ -1139,7 +1146,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
11391146
}
11401147
}
11411148

1142-
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
1149+
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
1150+
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
11431151
/* Summaries */
11441152
cfl_list_foreach(head, &cmt->summaries) {
11451153
summary = cfl_list_entry(head, struct cmt_summary, _head);
@@ -1155,7 +1163,8 @@ cfl_sds_t cmt_encode_prometheus_remote_write_create(struct cmt *cmt)
11551163
}
11561164
}
11571165

1158-
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS) {
1166+
if (result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_SUCCESS ||
1167+
result == CMT_ENCODE_PROMETHEUS_REMOTE_WRITE_CUTOFF_ERROR) {
11591168
/* Histograms */
11601169
cfl_list_foreach(head, &cmt->histograms) {
11611170
histogram = cfl_list_entry(head, struct cmt_histogram, _head);

0 commit comments

Comments
 (0)