Skip to content

Commit fd25b13

Browse files
committed
use server_name over host in metrics naming
see #1162 (reply in thread); thanks @studersi Signed-off-by: Hans Zandbelt <[email protected]>
1 parent e14de9e commit fd25b13

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/metrics.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ static inline apr_hash_t *oidc_metrics_server_hash(request_rec *r, apr_hash_t *t
791791
apr_hash_t *server_hash = NULL;
792792
char *name = "_default_";
793793

794-
/* obtain the vhost name */
794+
/* obtain the server name */
795795
if (r->server->server_hostname)
796796
name = r->server->server_hostname;
797797

@@ -1060,7 +1060,7 @@ static int oidc_metrics_handle_internal(request_rec *r, char *s_json) {
10601060
return oidc_util_http_send(r, s_json, _oidc_strlen(s_json), OIDC_CONTENT_TYPE_JSON, OK);
10611061
}
10621062

1063-
#define OIDC_METRICS_VHOST_PARAM "vhost"
1063+
#define OIDC_METRICS_SERVER_PARAM "server_name"
10641064
#define OIDC_METRICS_COUNTER_PARAM "counter"
10651065
#define OIDC_METRICS_SPEC_PARAM "spec"
10661066

@@ -1069,24 +1069,24 @@ static int oidc_metrics_handle_internal(request_rec *r, char *s_json) {
10691069
*/
10701070
static int oidc_metrics_handle_status(request_rec *r, char *s_json) {
10711071
char *msg = "OK\n";
1072-
char *metric = NULL, *vhost = NULL, *spec = NULL;
1072+
char *metric = NULL, *s_server = NULL, *spec = NULL;
10731073
json_t *json = NULL, *j_server = NULL, *j_counters = NULL, *j_counter = NULL, *j_spec = NULL, *j_specs = NULL;
10741074
json_int_t type = 0;
10751075
const char *s_key = NULL, *s_name = NULL;
10761076
void *iter = NULL;
10771077

1078-
oidc_util_get_request_parameter(r, OIDC_METRICS_VHOST_PARAM, &vhost);
1078+
oidc_util_get_request_parameter(r, OIDC_METRICS_SERVER_PARAM, &s_server);
10791079
oidc_util_get_request_parameter(r, OIDC_METRICS_COUNTER_PARAM, &metric);
10801080
oidc_util_get_request_parameter(r, OIDC_METRICS_SPEC_PARAM, &spec);
10811081

1082-
if (vhost == NULL)
1083-
vhost = "localhost";
1082+
if (s_server == NULL)
1083+
s_server = "localhost";
10841084

1085-
if ((metric) && (vhost)) {
1085+
if ((metric) && (s_server)) {
10861086
json = oidc_metrics_json_parse_r(r, s_json);
10871087
if (json == NULL)
10881088
goto end;
1089-
j_server = json_object_get(json, vhost);
1089+
j_server = json_object_get(json, s_server);
10901090
if (j_server == NULL)
10911091
goto end;
10921092
j_counters = json_object_get(j_server, OIDC_METRICS_COUNTERS);
@@ -1101,8 +1101,9 @@ static int oidc_metrics_handle_status(request_rec *r, char *s_json) {
11011101
if (_oidc_strcmp(s_name, metric) == 0) {
11021102
j_specs = json_object_get(j_counter, OIDC_METRICS_SPECS);
11031103
j_spec = json_object_get(j_specs, _metrics_spec2key(spec));
1104-
msg = apr_psprintf(r->pool, "OK: %s\n",
1105-
_json_int2str(r->pool, json_integer_value(j_spec)));
1104+
if (j_spec)
1105+
msg = apr_psprintf(r->pool, "OK: %s\n",
1106+
_json_int2str(r->pool, json_integer_value(j_spec)));
11061107
break;
11071108
}
11081109
iter = json_object_iter_next(j_counters, iter);
@@ -1148,7 +1149,7 @@ static const char *oidc_metric_prometheus_normalize_name(apr_pool_t *pool, const
11481149

11491150
#define OIDC_METRICS_PROMETHEUS_CONTENT_TYPE "text/plain; version=0.0.4"
11501151

1151-
#define OIDC_METRICS_PROMETHEUS_SERVER "host"
1152+
#define OIDC_METRICS_PROMETHEUS_SERVER "server_name"
11521153
#define OIDC_METRICS_PROMETHEUS_BUCKET "bucket"
11531154

11541155
typedef struct oidc_metric_prometheus_callback_ctx_t {

0 commit comments

Comments
 (0)