File tree 3 files changed +52
-1
lines changed
3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 10
10
doc /apidoc /
11
11
.idea
12
12
* .swp
13
+ .DS_Store
Original file line number Diff line number Diff line change 100
100
local http_handlers = {
101
101
json = function (req )
102
102
local json_exporter = require (' metrics.plugins.json' )
103
- return req :render ({ text = json_exporter .export () })
103
+ return req :render ({ json = json_exporter .export () })
104
104
end ,
105
105
prometheus = function (...)
106
106
local http_handler = require (' metrics.plugins.prometheus' ).collect_http
Original file line number Diff line number Diff line change @@ -1140,3 +1140,53 @@ for name, case in pairs(test_tls_cases) do
1140
1140
end
1141
1141
end
1142
1142
end
1143
+
1144
+ local function assert_content_type (uri , expected_content_type , tls_opts )
1145
+ local response = http_client :get (uri , tls_opts )
1146
+ t .assert_equals (response .status , 200 ) -- Убедимся, что эндпоинт доступен
1147
+ t .assert_equals (response .headers [' content-type' ], expected_content_type ) -- Проверка Content-Type
1148
+ end
1149
+
1150
+ local test_content_type_cases = {
1151
+ [' json' ] = {
1152
+ cfg = {
1153
+ http = {
1154
+ {
1155
+ listen = 8081 ,
1156
+ endpoints = {
1157
+ {
1158
+ path = " /json_metrics" ,
1159
+ format = " json" ,
1160
+ },
1161
+ },
1162
+ },
1163
+ },
1164
+ },
1165
+ expected_url = " http://127.0.0.1:8081/json_metrics" ,
1166
+ expected_content_type = " application/json; charset=utf-8" ,
1167
+ },
1168
+ [' prometheus' ] = {
1169
+ cfg = {
1170
+ http = {
1171
+ {
1172
+ listen = 8081 ,
1173
+ endpoints = {
1174
+ {
1175
+ path = " /prometheus_metrics" ,
1176
+ format = " prometheus" ,
1177
+ },
1178
+ },
1179
+ },
1180
+ },
1181
+ },
1182
+ expected_url = " http://127.0.0.1:8081/prometheus_metrics" ,
1183
+ expected_content_type = " text/plain; charset=utf8" ,
1184
+ },
1185
+ }
1186
+
1187
+ for name , case in pairs (test_content_type_cases ) do
1188
+ g [' test_content_type_' .. name ] = function (cg )
1189
+ cg .role .apply (case .cfg )
1190
+ assert_content_type (case .expected_url , case .expected_content_type )
1191
+ end
1192
+ end
You can’t perform that action at this time.
0 commit comments