Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add global name #1524

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add global name
qiujiayu committed Jun 26, 2020
commit 459f41960e5dfa47c67f28fddc15173bf5b17d2e
1 change: 1 addition & 0 deletions apisix/core.lua
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ log.info("use config_center: ", config_center)

return {
version = require("apisix.core.version"),
name = local_conf.apisix and local_conf.apisix.name or "APISIX",
log = log,
config = require("apisix.core.config_" .. config_center),
json = require("apisix.core.json"),
2 changes: 1 addition & 1 deletion apisix/core/config_etcd.lua
Original file line number Diff line number Diff line change
@@ -380,7 +380,7 @@ function _M.new(key, opts)
end

local etcd_conf = clone_tab(local_conf.etcd)
local prefix = etcd_conf.prefix
local prefix = etcd_conf.prefix or (local_conf.apisix.name and '/' .. local_conf.apisix.name) or "/apisix"
etcd_conf.http_host = etcd_conf.host
etcd_conf.host = nil
etcd_conf.prefix = nil
2 changes: 1 addition & 1 deletion apisix/core/etcd.lua
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ local function new()
end

local etcd_conf = clone_tab(local_conf.etcd)
local prefix = etcd_conf.prefix
local prefix = etcd_conf.prefix or (local_conf.apisix.name and '/' .. local_conf.apisix.name) or "/apisix"
etcd_conf.http_host = etcd_conf.host
etcd_conf.host = nil
etcd_conf.prefix = nil
28 changes: 16 additions & 12 deletions apisix/plugins/prometheus/exporter.lua
Original file line number Diff line number Diff line change
@@ -23,6 +23,8 @@ local re_gmatch = ngx.re.gmatch
local tonumber = tonumber
local select = select
local prometheus
local app_name_label_name = "application_name"


-- Default set of latency buckets, 1ms to 60s:
local DEFAULT_BUCKETS = { 1, 2, 5, 7, 10, 15, 20, 25, 30, 40, 50, 60, 70,
@@ -62,27 +64,28 @@ function _M.init()
prometheus = base_prometheus.init("prometheus-metrics", "apisix_")
metrics.connections = prometheus:gauge("nginx_http_current_connections",
"Number of HTTP connections",
{"state"})
{"state", app_name_label_name})

metrics.etcd_reachable = prometheus:gauge("etcd_reachable",
"Config server etcd reachable from APISIX, 0 is unreachable")
"Config server etcd reachable from APISIX, 0 is unreachable",
{app_name_label_name})

-- per service
metrics.status = prometheus:counter("http_status",
"HTTP status codes per service in APISIX",
{"code", "route", "service", "node"})
{"code", "route", "service", "node", app_name_label_name})

metrics.latency = prometheus:histogram("http_latency",
"HTTP request latency per service in APISIX",
{"type", "service", "node"}, DEFAULT_BUCKETS)
{"type", "service", "node", app_name_label_name}, DEFAULT_BUCKETS)

metrics.overhead = prometheus:histogram("http_overhead",
"HTTP request overhead per service in APISIX",
{"type", "service", "node"}, DEFAULT_BUCKETS)

metrics.bandwidth = prometheus:counter("bandwidth",
"Total bandwidth in bytes consumed per service in APISIX",
{"type", "route", "service", "node"})
{"type", "route", "service", "node", app_name_label_name})
end


@@ -102,24 +105,24 @@ function _M.log(conf, ctx)
end

metrics.status:inc(1,
gen_arr(vars.status, route_id, service_id, balancer_ip))
gen_arr(vars.status, route_id, service_id, balancer_ip, core.name))

local latency = (ngx.now() - ngx.req.start_time()) * 1000
metrics.latency:observe(latency,
gen_arr("request", service_id, balancer_ip))
gen_arr("request", service_id, balancer_ip, core.name))

local overhead = latency
if ctx.var.upstream_response_time then
overhead = overhead - tonumber(ctx.var.upstream_response_time) * 1000
end
metrics.overhead:observe(overhead,
gen_arr("request", service_id, balancer_ip))
gen_arr("request", service_id, balancer_ip, core.name))

metrics.bandwidth:inc(vars.request_length,
gen_arr("ingress", route_id, service_id, balancer_ip))
gen_arr("ingress", route_id, service_id, balancer_ip, core.name))

metrics.bandwidth:inc(vars.bytes_sent,
gen_arr("egress", route_id, service_id, balancer_ip))
gen_arr("egress", route_id, service_id, balancer_ip, core.name))
end


@@ -151,6 +154,7 @@ local function nginx_status()
end

label_values[1] = name
label_values[2] = core.name
metrics.connections:set(val[0], label_values)
end
end
@@ -170,10 +174,10 @@ function _M.collect()
local config = core.config.new()
local version, err = config:server_version()
if version then
metrics.etcd_reachable:set(1)
metrics.etcd_reachable:set(1, app_name_label_name)

else
metrics.etcd_reachable:set(0)
metrics.etcd_reachable:set(0, app_name_label_name)
core.log.error("prometheus: failed to reach config server while ",
"processing metrics endpoint: ", err)
end
3 changes: 2 additions & 1 deletion apisix/plugins/zipkin/reporter.lua
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local core = require "apisix.core"
local resty_http = require "resty.http"
local to_hex = require "resty.string".to_hex
local cjson = require "cjson".new()
@@ -39,7 +40,7 @@ local span_kind_map = {

function _M.new(conf)
local endpoint = conf.endpoint
local service_name = conf.service_name
local service_name = conf.service_name or core.name
local server_port = conf.server_port
local server_addr = conf.server_addr
assert(type(endpoint) == "string", "invalid http endpoint")
2 changes: 2 additions & 0 deletions apisix/utils/log-util.lua
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@ local function get_full_log(ngx, conf)
service_id = var.host
end


local log = {
request = {
url = url,
@@ -48,6 +49,7 @@ local function get_full_log(ngx, conf)
headers = ngx.resp.get_headers(),
size = var.bytes_sent
},
application_name = core.name,
upstream = var.upstream_addr,
service_id = service_id,
route_id = route_id,
1 change: 1 addition & 0 deletions conf/config.yaml
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
# limitations under the License.
#
apisix:
name: APISIX # APISIX gateway name
node_listen: 9080 # APISIX listening port
enable_heartbeat: true
enable_admin: true