proxy-wasm-cpp-sdk
proxy-wasm-cpp-sdk copied to clipboard
metric API not working
I'm testing http filter compiled with latest sdk master branch in istio-1.5.8.
The metric methods seems not working.
Here are my related code:
bool AddHeaderRootContext::onConfigure(size_t length) {
logWarn("onConfigure");
defineMetric(MetricType::Counter, "test_counter_config", &metric_id);
defineMetric(MetricType::Gauge, "test_gauge", &gauge_metric);
defineMetric(MetricType::Histogram, "test_gauge", &histogram_metric);
return true;
}
// ...
FilterHeadersStatus AddHeaderContext::onResponseHeaders(uint32_t) {
logWarn(std::string("onResponseHeaders ") + std::to_string(id()));
addResponseHeader(root_->header_name_, root_->header_value_);
auto res = incrementMetric(root_->metric_id, 1);
uint64_t value = 0;
getMetric(root_->metric_id, &value);
replaceResponseHeader("location", "envoy-wasm:" + std::to_string(int(value)));
logWarn("incrementMetric res:" + std::to_string(int(res)) + ", current value:" + std::to_string(int(value)));
recordMetric(root_->gauge_metric, 3);
recordMetric(root_->histogram_metric, 1);
return FilterHeadersStatus::Continue;
}
I see no metric in promethues, and according to log, the metric counter value is always 0 even after incrementMetric()
below are the logs:
[Envoy (Epoch 0)] [2020-08-14 09:48:38.071][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onCreate 14
[Envoy (Epoch 0)] [2020-08-14 09:48:38.071][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onRequestHeaders 14
[Envoy (Epoch 0)] [2020-08-14 09:48:38.071][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onResponseHeaders 14
[Envoy (Epoch 0)] [2020-08-14 09:48:38.071][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: incrementMetric res:0, current value:0
[Envoy (Epoch 0)] [2020-08-14 09:48:38.071][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDone 14
[Envoy (Epoch 0)] [2020-08-14 09:48:38.071][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onLog 14
[Envoy (Epoch 0)] [2020-08-14 09:48:38.071][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDelete 14
[Envoy (Epoch 0)] [2020-08-14 09:48:39.942][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onCreate 15
[Envoy (Epoch 0)] [2020-08-14 09:48:39.942][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onRequestHeaders 15
[Envoy (Epoch 0)] [2020-08-14 09:48:39.942][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onResponseHeaders 15
[Envoy (Epoch 0)] [2020-08-14 09:48:39.942][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: incrementMetric res:0, current value:0
[Envoy (Epoch 0)] [2020-08-14 09:48:39.942][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDone 15
[Envoy (Epoch 0)] [2020-08-14 09:48:39.942][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onLog 15
[Envoy (Epoch 0)] [2020-08-14 09:48:39.942][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDelete 15
[Envoy (Epoch 0)] [2020-08-14 09:48:41.250][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onCreate 16
[Envoy (Epoch 0)] [2020-08-14 09:48:41.250][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onRequestHeaders 16
[Envoy (Epoch 0)] [2020-08-14 09:48:41.250][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onResponseHeaders 16
[Envoy (Epoch 0)] [2020-08-14 09:48:41.250][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: incrementMetric res:0, current value:0
[Envoy (Epoch 0)] [2020-08-14 09:48:41.250][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDone 16
[Envoy (Epoch 0)] [2020-08-14 09:48:41.251][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onLog 16
[Envoy (Epoch 0)] [2020-08-14 09:48:41.251][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDelete 16
[Envoy (Epoch 0)] [2020-08-14 09:48:42.625][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onCreate 17
[Envoy (Epoch 0)] [2020-08-14 09:48:42.625][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onRequestHeaders 17
[Envoy (Epoch 0)] [2020-08-14 09:48:42.625][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onResponseHeaders 17
[Envoy (Epoch 0)] [2020-08-14 09:48:42.625][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: incrementMetric res:0, current value:0
[Envoy (Epoch 0)] [2020-08-14 09:48:42.626][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDone 17
[Envoy (Epoch 0)] [2020-08-14 09:48:42.626][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onLog 17
[Envoy (Epoch 0)] [2020-08-14 09:48:42.626][31][warning][wasm] [external/envoy/source/extensions/common/wasm/context.cc:1092] wasm log http-test8 add_header_root_id: onDelete 17
defineMetric, getMetric, and recordMetric are all low level metrics API. You probably want to high level metrics API, Counter
, Gauge
, Histogram
https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/blob/b3a4ea9a4700e9e1d9edbd028ad68100289c7900/proxy_wasm_api.h#L1120
https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/blob/b3a4ea9a4700e9e1d9edbd028ad68100289c7900/proxy_wasm_api.h#L1169
https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/blob/b3a4ea9a4700e9e1d9edbd028ad68100289c7900/proxy_wasm_api.h#L1215
as https://github.com/taegyunkim/proxy-wasm-examples/blob/65b4b82597971bef5664595d57e972fe30fcc437/dump/rpc-count/filter.cc#L11
Thank you for the examples. I tried these lower level APIs because the high level ones also don't work. I'll try again later. But it's very confusing for that how can we expect the high level ones to be good if the low level ones are not. After all the high level ones call the low level ones to implement its functionality.