@@ -1200,11 +1200,11 @@ typedef struct oidc_metric_prometheus_callback_ctx_t {
12001200/*
12011201 * loop function for converting counter metrics to Prometheus output
12021202 */
1203- int oidc_metrics_prometheus_counters (void * rec , const char * key , const char * value ) {
1203+ static int oidc_metrics_prometheus_counters (oidc_metric_prometheus_callback_ctx_t * ctx , const char * key ,
1204+ json_t * value ) {
12041205 const char * s_server = NULL , * s_spec = NULL ;
12051206 json_t * j_counter = NULL , * j_specs = NULL , * j_spec = NULL ;
1206- oidc_metric_prometheus_callback_ctx_t * ctx = (oidc_metric_prometheus_callback_ctx_t * )rec ;
1207- json_t * o_counter = (json_t * )value ;
1207+ json_t * o_counter = value ;
12081208 unsigned int type = oidc_metrics_key2type (key );
12091209 const char * s_label =
12101210 oidc_metric_prometheus_normalize_name (ctx -> pool , oidc_metrics_counter_type2s (ctx -> pool , type ));
@@ -1241,11 +1241,10 @@ int oidc_metrics_prometheus_counters(void *rec, const char *key, const char *val
12411241 * loop function for converting timing metrics to Prometheus output
12421242 */
12431243
1244- int oidc_metrics_prometheus_timings (void * rec , const char * key , const char * value ) {
1244+ static int oidc_metrics_prometheus_timings (oidc_metric_prometheus_callback_ctx_t * ctx , const char * key , json_t * value ) {
12451245 const char * s_server = NULL , * s_key = NULL , * s_bucket = NULL ;
12461246 json_t * j_timing = NULL , * j_member = NULL ;
1247- oidc_metric_prometheus_callback_ctx_t * ctx = (oidc_metric_prometheus_callback_ctx_t * )rec ;
1248- json_t * o_timer = (json_t * )value ;
1247+ json_t * o_timer = value ;
12491248 unsigned int type = oidc_metrics_key2type (key );
12501249 const char * s_label =
12511250 oidc_metric_prometheus_normalize_name (ctx -> pool , oidc_metrics_timing_type2s (ctx -> pool , type ));
@@ -1282,20 +1281,20 @@ int oidc_metrics_prometheus_timings(void *rec, const char *key, const char *valu
12821281/*
12831282 * take a list of metrics from a server indexed list and add it to a type indexed list
12841283 */
1285- static void oidc_metrics_prometheus_convert (apr_table_t * table , const char * server , json_t * list ) {
1284+ static void oidc_metrics_prometheus_convert (apr_hash_t * hash , const char * server , json_t * list ) {
12861285 const char * type = NULL ;
12871286 json_t * src = NULL , * dst = NULL ;
12881287 void * iter = json_object_iter (list );
12891288 while (iter ) {
12901289 type = json_object_iter_key (iter );
12911290 src = json_object_iter_value (iter );
1292- dst = (json_t * )apr_table_get ( table , type );
1291+ dst = (json_t * )apr_hash_get ( hash , type , APR_HASH_KEY_STRING );
12931292 if (dst ) {
12941293 json_object_set (dst , server , src );
12951294 } else {
12961295 dst = json_object ();
12971296 json_object_set (dst , server , src );
1298- apr_table_setn ( table , type , ( const char * ) dst );
1297+ apr_hash_set ( hash , type , APR_HASH_KEY_STRING , dst );
12991298 }
13001299 iter = json_object_iter_next (list , iter );
13011300 }
@@ -1307,8 +1306,12 @@ static void oidc_metrics_prometheus_convert(apr_table_t *table, const char *serv
13071306static int oidc_metrics_handle_prometheus (request_rec * r , char * s_json ) {
13081307 json_t * json = NULL , * j_server = NULL ;
13091308 const char * s_server = NULL ;
1310- apr_table_t * t_counters = apr_table_make (r -> pool , 1 );
1311- apr_table_t * t_timings = apr_table_make (r -> pool , 1 );
1309+ apr_hash_t * t_counters = apr_hash_make (r -> pool );
1310+ apr_hash_t * t_timings = apr_hash_make (r -> pool );
1311+ apr_hash_index_t * hi = NULL ;
1312+ const char * name = NULL ;
1313+ void * value = NULL ;
1314+
13121315 oidc_metric_prometheus_callback_ctx_t ctx = {"" , r -> pool };
13131316 void * iter = NULL ;
13141317
@@ -1326,8 +1329,15 @@ static int oidc_metrics_handle_prometheus(request_rec *r, char *s_json) {
13261329 iter = json_object_iter_next (json , iter );
13271330 }
13281331
1329- apr_table_do (oidc_metrics_prometheus_counters , & ctx , t_counters , NULL );
1330- apr_table_do (oidc_metrics_prometheus_timings , & ctx , t_timings , NULL );
1332+ for (hi = apr_hash_first (r -> pool , t_counters ); hi ; hi = apr_hash_next (hi )) {
1333+ apr_hash_this (hi , (const void * * )& name , NULL , & value );
1334+ oidc_metrics_prometheus_counters (& ctx , name , value );
1335+ }
1336+
1337+ for (hi = apr_hash_first (r -> pool , t_timings ); hi ; hi = apr_hash_next (hi )) {
1338+ apr_hash_this (hi , (const void * * )& name , NULL , & value );
1339+ oidc_metrics_prometheus_timings (& ctx , name , value );
1340+ }
13311341
13321342 json_decref (json );
13331343
0 commit comments