3 Star 0 Fork 0

Gitee 极速下载 / gitlab-workhorsesource

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://gitlab.com/gitlab-org/gitlab-workhorse
克隆/下载
responsewriter.go 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
Nick Thomas 提交于 2018-10-18 14:27 . Fix make verify / fmt on master
package git
import (
"net/http"
"strconv"
"github.com/prometheus/client_golang/prometheus"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/helper"
)
const (
directionIn = "in"
directionOut = "out"
)
var (
gitHTTPSessionsActive = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "gitlab_workhorse_git_http_sessions_active",
Help: "Number of Git HTTP request-response cycles currently being handled by gitlab-workhorse.",
})
gitHTTPRequests = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "gitlab_workhorse_git_http_requests",
Help: "How many Git HTTP requests have been processed by gitlab-workhorse, partitioned by request type and agent.",
},
[]string{"method", "code", "service", "agent"},
)
gitHTTPBytes = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "gitlab_workhorse_git_http_bytes",
Help: "How many Git HTTP bytes have been sent by gitlab-workhorse, partitioned by request type, agent and direction.",
},
[]string{"method", "code", "service", "agent", "direction"},
)
)
func init() {
prometheus.MustRegister(gitHTTPSessionsActive)
prometheus.MustRegister(gitHTTPRequests)
prometheus.MustRegister(gitHTTPBytes)
}
type HttpResponseWriter struct {
helper.CountingResponseWriter
}
func NewHttpResponseWriter(rw http.ResponseWriter) *HttpResponseWriter {
gitHTTPSessionsActive.Inc()
return &HttpResponseWriter{
CountingResponseWriter: helper.NewCountingResponseWriter(rw),
}
}
func (w *HttpResponseWriter) Log(r *http.Request, writtenIn int64) {
service := getService(r)
agent := getRequestAgent(r)
gitHTTPSessionsActive.Dec()
gitHTTPRequests.WithLabelValues(r.Method, strconv.Itoa(w.Status()), service, agent).Inc()
gitHTTPBytes.WithLabelValues(r.Method, strconv.Itoa(w.Status()), service, agent, directionIn).
Add(float64(writtenIn))
gitHTTPBytes.WithLabelValues(r.Method, strconv.Itoa(w.Status()), service, agent, directionOut).
Add(float64(w.Count()))
}
func getRequestAgent(r *http.Request) string {
u, _, ok := r.BasicAuth()
if !ok {
return "anonymous"
}
if u == "gitlab-ci-token" {
return "gitlab-ci"
}
return "logged"
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/gitlab-workhorsesource.git
git@gitee.com:mirrors/gitlab-workhorsesource.git
mirrors
gitlab-workhorsesource
gitlab-workhorsesource
v7.5.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891