feat: add http requests metrics (#495)
* feat: add http requests metrics * add more error log * move the api-testing-scema.json * copy api-testing-schema.json during the docs build process * do not ignore helm directory --------- Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
This commit is contained in:
parent
f10f441a53
commit
dabb95542d
|
@ -0,0 +1,8 @@
|
|||
bin/
|
||||
extensions/
|
||||
dist/
|
||||
console/atest-desktop/
|
||||
console/atest-ui/node_modules/
|
||||
docs/site/node_modules/
|
||||
docs/site/public/
|
||||
docs/site/resources/
|
|
@ -62,7 +62,9 @@ jobs:
|
|||
node-version: '18'
|
||||
|
||||
- name: Install Site Dependencies and Build Site
|
||||
run: make docs # docs-check-links
|
||||
run: |
|
||||
cp docs/api-testing-schema.json docs/site/static/api-testing-schema.json
|
||||
make docs # docs-check-links
|
||||
|
||||
# Upload docs for GitHub Pages
|
||||
- name: Upload GitHub Pages artifact
|
||||
|
|
|
@ -336,6 +336,7 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
|
|||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
collectors.NewBuildInfoCollector(),
|
||||
server.ExecutionCountNum, server.ExecutionSuccessNum, server.ExecutionFailNum,
|
||||
server.RequestCounter,
|
||||
runner.RunnersNum,
|
||||
)
|
||||
mux.HandlePath(http.MethodGet, "/metrics", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
|
||||
|
|
|
@ -376,3 +376,4 @@ items:
|
|||
- indexOf(data, "atest_execution_fail") != -1
|
||||
- indexOf(data, "atest_execution_success") != -1
|
||||
- indexOf(data, "atest_runners_count") != -1
|
||||
- indexOf(data, "http_requests_total") != -1
|
||||
|
|
|
@ -141,7 +141,7 @@ func (r *reverseHTTPRunner) RunTestCase(testcase *testing.TestCase, dataContext
|
|||
mutationCase := mutator.Render(testcase)
|
||||
_, reverseErr := r.TestCaseRunner.RunTestCase(mutationCase, dataContext, ctx)
|
||||
if reverseErr == nil {
|
||||
err = fmt.Errorf("failed when: %q", mutator.Message())
|
||||
err = fmt.Errorf("testcase %q failed when: %q", testcase.Name, mutator.Message())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ package server
|
|||
|
||||
import (
|
||||
context "context"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -93,7 +95,18 @@ func (s *defaultCombineHandler) GetHandler() http.Handler {
|
|||
return s
|
||||
}
|
||||
|
||||
var RequestCounter = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "http_requests_total",
|
||||
Help: "The total number of HTTP requests",
|
||||
}, []string{"method", "source", "path"})
|
||||
|
||||
func (s *defaultCombineHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
sourceIP := r.RemoteAddr
|
||||
if len(strings.Split(sourceIP, ":")) > 1 {
|
||||
sourceIP = strings.Split(sourceIP, ":")[0]
|
||||
}
|
||||
RequestCounter.WithLabelValues(r.Method, sourceIP, r.RequestURI).Inc()
|
||||
|
||||
for prefix, handler := range s.handlerMapping {
|
||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||
handler.ServeHTTP(w, r)
|
||||
|
|
Loading…
Reference in New Issue