Skip to content

Commit

Permalink
[TMP] review(metrics) communicate failure via error code
Browse files Browse the repository at this point in the history
  • Loading branch information
casimiro committed Jun 11, 2024
1 parent 7897be6 commit 84b192a
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/common/metrics/ngx_wa_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,7 @@ ngx_wa_metrics_get(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_uint_t *out)

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &n, &cas);
if (rc != NGX_OK) {
ngx_wasm_log_error(NGX_LOG_ERR, metrics->shm->log, 0,
"metric \"%uD\" not found", mid);
return rc;
return NGX_DECLINED;
}

m = (ngx_wa_metric_t *) n->data;
Expand Down Expand Up @@ -392,19 +390,17 @@ ngx_wa_metrics_increment(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n)

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
if (rc != NGX_OK) {
ngx_wasm_log_error(NGX_LOG_ERR, metrics->shm->log, 0,
"metric \"%uD\" not found", mid);
goto error;
}

m = (ngx_wa_metric_t *) val->data;

if (m->type != NGX_WA_METRIC_COUNTER) {
ngx_wasm_log_error(NGX_LOG_ERR, metrics->shm->log, 0,
ngx_wasm_log_error(NGX_LOG_WARN, metrics->shm->log, 0,
"attempt to call increment_metric on a %V; "
"operation not supported",
metric_type_name(m->type));
rc = NGX_ERROR;
rc = NGX_ABORT;
goto error;
}

Expand Down Expand Up @@ -445,9 +441,6 @@ ngx_wa_metrics_record(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n)

rc = ngx_wasm_shm_kv_get_locked(metrics->shm, NULL, &mid, &val, &cas);
if (rc != NGX_OK) {
ngx_wasm_log_error(NGX_LOG_ERR, metrics->shm->log, 0,
"metric \"%uD\" not found", mid);

goto error;
}

Expand All @@ -469,10 +462,10 @@ ngx_wa_metrics_record(ngx_wa_metrics_t *metrics, uint32_t mid, ngx_int_t n)
break;

default:
ngx_wasm_log_error(NGX_LOG_ERR, metrics->shm->log, 0,
ngx_wasm_log_error(NGX_LOG_WARN, metrics->shm->log, 0,
"attempt to call record_metric on a counter; "
"operation not supported");
rc = NGX_ERROR;
rc = NGX_ABORT;
goto error;

break;
Expand Down

0 comments on commit 84b192a

Please sign in to comment.