Skip to content

Commit

Permalink
fix(apisix/prometheus): patch to support custom default_buckets (#42)
Browse files Browse the repository at this point in the history
* fix(apisix/prometheus): patch to support custom default_buckets

* feat(prometheus/enable_official): add option enable_official
  • Loading branch information
wklken committed Aug 14, 2023
1 parent 3a2ed16 commit e3c940e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ RUN luarocks install multipart --tree=/usr/local/apisix/deps && \

ADD ./build/config-watcher ./src/build/bin/apisix-start.sh ./src/build/bin/config-watcher-start.sh /data/bkgateway/bin/
ADD ./src/apisix/plugins/ /usr/local/apisix/apisix/plugins/
# FIXME: remove the patch if upgrade to >=3.4.x, while the patch is only for 3.2.x ---
ADD ./src/build/patches /usr/local/apisix/patches
RUN ls /usr/local/apisix/patches | sort | xargs -L1 -I __patch_file__ sh -c 'cat ./patches/__patch_file__ | patch -t -p1'
# FIXME: remove the patch if upgrade to >=3.4.x, while the patch is only for 3.2.x ---

RUN chmod 755 /data/bkgateway/bin/* && chmod 777 /usr/local/apisix/logs

Expand Down
33 changes: 33 additions & 0 deletions src/build/patches/001_change_prometheus_default_buckets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
diff --git a/apisix/plugins/prometheus/exporter.lua b/apisix/plugins/prometheus/exporter.lua
index 45ff94c3..5434ce56 100644
--- a/apisix/plugins/prometheus/exporter.lua
+++ b/apisix/plugins/prometheus/exporter.lua
@@ -168,10 +168,15 @@ function _M.http_init(prometheus_enabled_in_stream)
{"code", "route", "matched_uri", "matched_host", "service", "consumer", "node",
unpack(extra_labels("http_status"))})

+ local buckets = DEFAULT_BUCKETS
+ if attr and attr.default_buckets then
+ buckets = attr.default_buckets
+ end
+
metrics.latency = prometheus:histogram("http_latency",
"HTTP request latency in milliseconds per service in APISIX",
{"type", "route", "service", "consumer", "node", unpack(extra_labels("http_latency"))},
- DEFAULT_BUCKETS)
+ buckets)

metrics.bandwidth = prometheus:counter("bandwidth",
"Total bandwidth in bytes consumed per service in APISIX",
@@ -208,6 +213,11 @@ end


function _M.http_log(conf, ctx)
+ local attr = plugin.plugin_attr("prometheus")
+ if attr and not attr.enable_official then
+ return
+ end
+
local vars = ctx.var

local route_id = ""

0 comments on commit e3c940e

Please sign in to comment.