Skip to content

Commit

Permalink
feat: add http requests metrics (#495)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Jun 19, 2024
1 parent f10f441 commit dabb955
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/
4 changes: 3 additions & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions e2e/test-suite-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pkg/runner/http_reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dabb955

Please sign in to comment.