Browse code

xhttp_prom: replaced prom_counter_inc by prom_counter_update

Sergey Safarov authored on 16/09/2021 21:02:21
Showing 3 changed files
... ...
@@ -1132,29 +1132,6 @@ error:
1132 1132
 	return -1;
1133 1133
 }
1134 1134
 
1135
-/**
1136
- * @brief Add some positive amount to a counter.
1137
- */
1138
-int prom_counter_inc(str *s_name, int number, str *l1, str *l2, str *l3)
1139
-{
1140
-	lock_get(prom_lock);
1141
-
1142
-	/* Find a lvalue based on its metric name and labels. */
1143
-	prom_lvalue_t *p = NULL;
1144
-	p = prom_metric_lvalue_get(s_name, M_COUNTER, l1, l2, l3);
1145
-	if (!p) {
1146
-		LM_ERR("Cannot find counter: %.*s\n", s_name->len, s_name->s);
1147
-		lock_release(prom_lock);
1148
-		return -1;
1149
-	}
1150
-
1151
-	/* Add to counter value. */
1152
-	p->m.cval += number;
1153
-	
1154
-	lock_release(prom_lock);
1155
-	return 0;
1156
-}
1157
-
1158 1135
 /**
1159 1136
  * @brief Updates a counter.
1160 1137
  */
... ...
@@ -75,11 +75,6 @@ int prom_counter_reset(str *s_name, str *l1, str *l2, str *l3);
75 75
  */
76 76
 int prom_gauge_reset(str *s_name, str *l1, str *l2, str *l3);
77 77
 
78
-/**
79
- * @brief Add some positive amount to a counter.
80
- */
81
-int prom_counter_inc(str *s_name, int number, str *l1, str *l2, str *l3);
82
-
83 78
 /**
84 79
  * @brief Updates a counter.
85 80
  */
... ...
@@ -973,7 +973,7 @@ static int ki_xhttp_prom_counter_inc_l0(struct sip_msg* msg, str *s_name, int nu
973 973
 		return -1;
974 974
 	}
975 975
 
976
-	if (prom_counter_inc(s_name, number, NULL, NULL, NULL)) {
976
+	if (prom_counter_update(s_name, INCREMENT, number, NULL, NULL, NULL)) {
977 977
 		LM_ERR("Cannot add number: %d to counter: %.*s\n", number, s_name->len, s_name->s);
978 978
 		return -1;
979 979
 	}
... ...
@@ -1002,7 +1002,7 @@ static int ki_xhttp_prom_counter_inc_l1(struct sip_msg* msg, str *s_name, int nu
1002 1002
 		return -1;
1003 1003
 	}
1004 1004
 
1005
-	if (prom_counter_inc(s_name, number, l1, NULL, NULL)) {
1005
+	if (prom_counter_update(s_name, INCREMENT, number, l1, NULL, NULL)) {
1006 1006
 		LM_ERR("Cannot add number: %d to counter: %.*s (%.*s)\n",
1007 1007
 			   number, s_name->len, s_name->s,
1008 1008
 			   l1->len, l1->s
... ...
@@ -1044,7 +1044,7 @@ static int ki_xhttp_prom_counter_inc_l2(struct sip_msg* msg, str *s_name, int nu
1044 1044
 		return -1;
1045 1045
 	}
1046 1046
 
1047
-	if (prom_counter_inc(s_name, number, l1, l2, NULL)) {
1047
+	if (prom_counter_update(s_name, INCREMENT, number, l1, l2, NULL)) {
1048 1048
 		LM_ERR("Cannot add number: %d to counter: %.*s (%.*s, %.*s)\n",
1049 1049
 			   number, s_name->len, s_name->s,
1050 1050
 			   l1->len, l1->s,
... ...
@@ -1093,7 +1093,7 @@ static int ki_xhttp_prom_counter_inc_l3(struct sip_msg* msg, str *s_name, int nu
1093 1093
 		return -1;
1094 1094
 	}
1095 1095
 
1096
-	if (prom_counter_inc(s_name, number, l1, l2, l3)) {
1096
+	if (prom_counter_update(s_name, INCREMENT, number, l1, l2, l3)) {
1097 1097
 		LM_ERR("Cannot add number: %d to counter: %.*s (%.*s, %.*s, %.*s)\n",
1098 1098
 			   number, s_name->len, s_name->s,
1099 1099
 			   l1->len, l1->s,
... ...
@@ -2090,7 +2090,7 @@ static void rpc_prom_counter_inc(rpc_t *rpc, void *ct)
2090 2090
 	res = rpc->scan(ct, "*SSS", &l1, &l2, &l3);
2091 2091
 	if (res == 0) {
2092 2092
 		/* No labels */
2093
-		if (prom_counter_inc(&s_name, number, NULL, NULL, NULL)) {
2093
+		if (prom_counter_update(&s_name, INCREMENT, number, NULL, NULL, NULL)) {
2094 2094
 			LM_ERR("Cannot add %d to counter: %.*s\n", number, s_name.len, s_name.s);
2095 2095
 			rpc->fault(ct, 500, "Failed to add %d to counter: %.*s", number,
2096 2096
 					   s_name.len, s_name.s);
... ...
@@ -2099,7 +2099,7 @@ static void rpc_prom_counter_inc(rpc_t *rpc, void *ct)
2099 2099
 		LM_DBG("Added %d to counter: (%.*s)\n", number, s_name.len, s_name.s);
2100 2100
 		
2101 2101
 	} else if (res == 1) {
2102
-		if (prom_counter_inc(&s_name, number, &l1, NULL, NULL)) {
2102
+		if (prom_counter_update(&s_name, INCREMENT, number, &l1, NULL, NULL)) {
2103 2103
 			LM_ERR("Cannot add %d to counter: %.*s (%.*s)\n", number, s_name.len, s_name.s,
2104 2104
 				   l1.len, l1.s);
2105 2105
 			rpc->fault(ct, 500, "Failed to add %d to counter: %.*s (%.*s)",
... ...
@@ -2111,7 +2111,7 @@ static void rpc_prom_counter_inc(rpc_t *rpc, void *ct)
2111 2111
 			   l1.len, l1.s);
2112 2112
 
2113 2113
 	} else if (res == 2) {
2114
-		if (prom_counter_inc(&s_name, number, &l1, &l2, NULL)) {
2114
+		if (prom_counter_update(&s_name, INCREMENT, number, &l1, &l2, NULL)) {
2115 2115
 			LM_ERR("Cannot add %d to counter: %.*s (%.*s, %.*s)\n", number,
2116 2116
 				   s_name.len, s_name.s,
2117 2117
 				   l1.len, l1.s,
... ...
@@ -2128,7 +2128,7 @@ static void rpc_prom_counter_inc(rpc_t *rpc, void *ct)
2128 2128
 			   l2.len, l2.s);
2129 2129
 
2130 2130
 	} else if (res == 3) {
2131
-		if (prom_counter_inc(&s_name, number, &l1, &l2, &l3)) {
2131
+		if (prom_counter_update(&s_name, INCREMENT, number, &l1, &l2, &l3)) {
2132 2132
 			LM_ERR("Cannot add %d to counter: %.*s (%.*s, %.*s, %.*s)\n",
2133 2133
 				   number, s_name.len, s_name.s,
2134 2134
 				   l1.len, l1.s,