mirror of
https://github.com/go-gitea/gitea.git
synced 2025-02-20 11:43:57 +08:00
Compare commits
14 Commits
68ab3e37ec
...
ac03fca138
Author | SHA1 | Date | |
---|---|---|---|
|
ac03fca138 | ||
|
c2e23d3301 | ||
|
84d2159ef6 | ||
|
ce65613690 | ||
|
748b731612 | ||
|
241f799edf | ||
|
056a308b2a | ||
|
0b1e3254dd | ||
|
eddef36435 | ||
|
91919de720 | ||
|
c666f4d9cc | ||
|
3e06c39d2f | ||
|
1dad933ec5 | ||
|
73266df0f5 |
64
README.md
64
README.md
@ -150,10 +150,64 @@ for the full license text.
|
||||
<details>
|
||||
<summary>Looking for an overview of the interface? Check it out!</summary>
|
||||
|
||||
||||
|
||||
|:---:|:---:|:---:|
|
||||
||||
|
||||
||||
|
||||
||||
|
||||
### Login/Register Page
|
||||
|
||||

|
||||

|
||||
|
||||
### User Dashboard
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
### User Profile
|
||||
|
||||

|
||||
|
||||
### Explore
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
### Repository
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
#### Repository Issue
|
||||
|
||||

|
||||

|
||||
|
||||
#### Repository Pull Requests
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
#### Repository Actions
|
||||
|
||||

|
||||

|
||||
|
||||
#### Repository Activity
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
### Organization
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
64
README_ZH.md
64
README_ZH.md
@ -93,10 +93,64 @@ Gitea 提供官方的 [go-sdk](https://gitea.com/gitea/go-sdk),以及名为 [t
|
||||
<details>
|
||||
<summary>截图</summary>
|
||||
|
||||
||||
|
||||
|:---:|:---:|:---:|
|
||||
||||
|
||||
||||
|
||||
||||
|
||||
### 登录界面
|
||||
|
||||

|
||||

|
||||
|
||||
### 用户首页
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
### 用户资料
|
||||
|
||||

|
||||
|
||||
### 探索
|
||||
|
||||

|
||||

|
||||

|
||||
|
||||
### 仓库
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
#### 仓库工单
|
||||
|
||||

|
||||

|
||||
|
||||
#### 仓库合并请求
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
#### 仓库 Actions
|
||||
|
||||

|
||||

|
||||
|
||||
#### 仓库动态
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
### 组织
|
||||
|
||||

|
||||
|
||||
</details>
|
||||
|
5
assets/go-licenses.json
generated
5
assets/go-licenses.json
generated
@ -439,6 +439,11 @@
|
||||
"path": "github.com/felixge/fgprof/LICENSE.txt",
|
||||
"licenseText": "The MIT License (MIT)\nCopyright © 2020 Felix Geisendörfer \u003cfelix@felixge.de\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
|
||||
},
|
||||
{
|
||||
"name": "github.com/felixge/httpsnoop",
|
||||
"path": "github.com/felixge/httpsnoop/LICENSE.txt",
|
||||
"licenseText": "Copyright (c) 2016 Felix Geisendörfer (felix@debuggable.com)\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in\n all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n THE SOFTWARE.\n"
|
||||
},
|
||||
{
|
||||
"name": "github.com/fsnotify/fsnotify",
|
||||
"path": "github.com/fsnotify/fsnotify/LICENSE",
|
||||
|
3
go.mod
3
go.mod
@ -98,6 +98,7 @@ require (
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/pquerna/otp v1.4.0
|
||||
github.com/prometheus/client_golang v1.20.5
|
||||
github.com/prometheus/common v0.60.1
|
||||
github.com/quasoft/websspi v1.1.2
|
||||
github.com/redis/go-redis/v9 v9.7.0
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
@ -240,6 +241,7 @@ require (
|
||||
github.com/klauspost/pgzip v1.2.6 // indirect
|
||||
github.com/kr/pretty v0.3.1 // indirect
|
||||
github.com/kr/text v0.2.0 // indirect
|
||||
github.com/kylelemons/godebug v1.1.0 // indirect
|
||||
github.com/libdns/libdns v0.2.2 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
@ -267,7 +269,6 @@ require (
|
||||
github.com/pjbgf/sha1cd v0.3.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.60.1 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/rhysd/actionlint v1.7.3 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
repo_model "code.gitea.io/gitea/models/repo"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/container"
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
webhook_module "code.gitea.io/gitea/modules/webhook"
|
||||
|
||||
"xorm.io/builder"
|
||||
@ -112,14 +113,14 @@ type StatusInfo struct {
|
||||
}
|
||||
|
||||
// GetStatusInfoList returns a slice of StatusInfo
|
||||
func GetStatusInfoList(ctx context.Context) []StatusInfo {
|
||||
func GetStatusInfoList(ctx context.Context, lang translation.Locale) []StatusInfo {
|
||||
// same as those in aggregateJobStatus
|
||||
allStatus := []Status{StatusSuccess, StatusFailure, StatusWaiting, StatusRunning}
|
||||
statusInfoList := make([]StatusInfo, 0, 4)
|
||||
for _, s := range allStatus {
|
||||
statusInfoList = append(statusInfoList, StatusInfo{
|
||||
Status: int(s),
|
||||
DisplayedStatus: s.String(),
|
||||
DisplayedStatus: s.LocaleString(lang),
|
||||
})
|
||||
}
|
||||
return statusInfoList
|
||||
|
@ -152,7 +152,7 @@ func (p *Permission) ReadableUnitTypes() []unit.Type {
|
||||
}
|
||||
|
||||
func (p *Permission) LogString() string {
|
||||
format := "<Permission AccessMode=%s, %d Units, %d UnitsMode(s): [ "
|
||||
format := "<Permission AccessMode=%s, %d Units, %d UnitsMode(s): ["
|
||||
args := []any{p.AccessMode.ToString(), len(p.units), len(p.unitsMode)}
|
||||
|
||||
for i, u := range p.units {
|
||||
@ -164,14 +164,16 @@ func (p *Permission) LogString() string {
|
||||
config = err.Error()
|
||||
}
|
||||
}
|
||||
format += "\nUnits[%d]: ID: %d RepoID: %d Type: %s Config: %s"
|
||||
format += "\n\tunits[%d]: ID=%d RepoID=%d Type=%s Config=%s"
|
||||
args = append(args, i, u.ID, u.RepoID, u.Type.LogString(), config)
|
||||
}
|
||||
for key, value := range p.unitsMode {
|
||||
format += "\nUnitMode[%-v]: %-v"
|
||||
format += "\n\tunitsMode[%-v]: %-v"
|
||||
args = append(args, key.LogString(), value.LogString())
|
||||
}
|
||||
format += " ]>"
|
||||
format += "\n\teveryoneAccessMode: %-v"
|
||||
args = append(args, p.everyoneAccessMode)
|
||||
format += "\n\t]>"
|
||||
return fmt.Sprintf(format, args...)
|
||||
}
|
||||
|
||||
|
31
modules/cache/cache.go
vendored
31
modules/cache/cache.go
vendored
@ -10,10 +10,39 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
|
||||
_ "gitea.com/go-chi/cache/memcache" //nolint:depguard // memcache plugin for cache, it is required for config "ADAPTER=memcache"
|
||||
)
|
||||
|
||||
var defaultCache StringCache
|
||||
var (
|
||||
defaultCache StringCache
|
||||
|
||||
// TODO: Combine hit and miss into one
|
||||
hitCounter = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "gitea",
|
||||
Help: "Cache count",
|
||||
Subsystem: "cache",
|
||||
Name: "response",
|
||||
ConstLabels: prometheus.Labels{"state": "hit"},
|
||||
})
|
||||
missCounter = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "gitea",
|
||||
Help: "Cache count",
|
||||
Subsystem: "cache",
|
||||
Name: "response",
|
||||
ConstLabels: prometheus.Labels{"state": "miss"},
|
||||
})
|
||||
latencyHistogram = promauto.NewHistogram(
|
||||
prometheus.HistogramOpts{
|
||||
Namespace: "gitea",
|
||||
Help: "Cache latency",
|
||||
Subsystem: "cache",
|
||||
Name: "duration",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
// Init start cache service
|
||||
func Init() error {
|
||||
|
6
modules/cache/string_cache.go
vendored
6
modules/cache/string_cache.go
vendored
@ -6,6 +6,7 @@ package cache
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
@ -63,10 +64,15 @@ func (sc *stringCache) Ping() error {
|
||||
}
|
||||
|
||||
func (sc *stringCache) Get(key string) (string, bool) {
|
||||
start := time.Now()
|
||||
v := sc.chiCache.Get(key)
|
||||
elapsed := time.Since(start).Seconds()
|
||||
latencyHistogram.Observe(elapsed)
|
||||
if v == nil {
|
||||
missCounter.Add(1)
|
||||
return "", false
|
||||
}
|
||||
hitCounter.Add(1)
|
||||
s, ok := v.(string)
|
||||
return s, ok
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ package log
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -175,6 +176,20 @@ func (l *LoggerImpl) IsEnabled() bool {
|
||||
return l.level.Load() < int32(FATAL) && len(l.eventWriters) > 0
|
||||
}
|
||||
|
||||
func asLogStringer(v any) LogStringer {
|
||||
if s, ok := v.(LogStringer); ok {
|
||||
return s
|
||||
} else if a := reflect.ValueOf(v); a.Kind() == reflect.Struct {
|
||||
// in case the receiver is a pointer, but the value is a struct
|
||||
vp := reflect.New(a.Type())
|
||||
vp.Elem().Set(a)
|
||||
if s, ok := vp.Interface().(LogStringer); ok {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Log prepares the log event, if the level matches, the event will be sent to the writers
|
||||
func (l *LoggerImpl) Log(skip int, level Level, format string, logArgs ...any) {
|
||||
if Level(l.level.Load()) > level {
|
||||
@ -207,11 +222,11 @@ func (l *LoggerImpl) Log(skip int, level Level, format string, logArgs ...any) {
|
||||
// handle LogStringer values
|
||||
for i, v := range msgArgs {
|
||||
if cv, ok := v.(*ColoredValue); ok {
|
||||
if s, ok := cv.v.(LogStringer); ok {
|
||||
cv.v = logStringFormatter{v: s}
|
||||
if ls := asLogStringer(cv.v); ls != nil {
|
||||
cv.v = logStringFormatter{v: ls}
|
||||
}
|
||||
} else if s, ok := v.(LogStringer); ok {
|
||||
msgArgs[i] = logStringFormatter{v: s}
|
||||
} else if ls := asLogStringer(v); ls != nil {
|
||||
msgArgs[i] = logStringFormatter{v: ls}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,14 @@ func (t testLogString) LogString() string {
|
||||
return "log-string"
|
||||
}
|
||||
|
||||
type testLogStringPtrReceiver struct {
|
||||
Field string
|
||||
}
|
||||
|
||||
func (t *testLogStringPtrReceiver) LogString() string {
|
||||
return "log-string-ptr-receiver"
|
||||
}
|
||||
|
||||
func TestLoggerLogString(t *testing.T) {
|
||||
logger := NewLoggerWithWriters(context.Background(), "test")
|
||||
|
||||
@ -124,9 +132,13 @@ func TestLoggerLogString(t *testing.T) {
|
||||
logger.AddWriters(w1)
|
||||
|
||||
logger.Info("%s %s %#v %v", testLogString{}, &testLogString{}, testLogString{Field: "detail"}, NewColoredValue(testLogString{}, FgRed))
|
||||
logger.Info("%s %s %#v %v", testLogStringPtrReceiver{}, &testLogStringPtrReceiver{}, testLogStringPtrReceiver{Field: "detail"}, NewColoredValue(testLogStringPtrReceiver{}, FgRed))
|
||||
logger.Close()
|
||||
|
||||
assert.Equal(t, []string{"log-string log-string log.testLogString{Field:\"detail\"} \x1b[31mlog-string\x1b[0m\n"}, w1.GetLogs())
|
||||
assert.Equal(t, []string{
|
||||
"log-string log-string log.testLogString{Field:\"detail\"} \x1b[31mlog-string\x1b[0m\n",
|
||||
"log-string-ptr-receiver log-string-ptr-receiver &log.testLogStringPtrReceiver{Field:\"detail\"} \x1b[31mlog-string-ptr-receiver\x1b[0m\n",
|
||||
}, w1.GetLogs())
|
||||
}
|
||||
|
||||
func TestLoggerExpressionFilter(t *testing.T) {
|
||||
|
@ -11,10 +11,15 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/common/model"
|
||||
)
|
||||
|
||||
const namespace = "gitea_"
|
||||
|
||||
func init() {
|
||||
model.NameValidationScheme = model.UTF8Validation
|
||||
}
|
||||
|
||||
// Collector implements the prometheus.Collector interface and
|
||||
// exposes gitea metrics for prometheus
|
||||
type Collector struct {
|
||||
@ -89,7 +94,7 @@ func NewCollector() Collector {
|
||||
Issues: prometheus.NewDesc(
|
||||
namespace+"issues",
|
||||
"Number of Issues",
|
||||
nil, nil,
|
||||
[]string{"state"}, nil,
|
||||
),
|
||||
IssuesByLabel: prometheus.NewDesc(
|
||||
namespace+"issues_by_label",
|
||||
@ -103,12 +108,12 @@ func NewCollector() Collector {
|
||||
),
|
||||
IssuesOpen: prometheus.NewDesc(
|
||||
namespace+"issues_open",
|
||||
"Number of open Issues",
|
||||
"DEPRECATED: Use Issues with state: open",
|
||||
nil, nil,
|
||||
),
|
||||
IssuesClosed: prometheus.NewDesc(
|
||||
namespace+"issues_closed",
|
||||
"Number of closed Issues",
|
||||
"DEPRECATED: Use Issues with state: closed",
|
||||
nil, nil,
|
||||
),
|
||||
Labels: prometheus.NewDesc(
|
||||
@ -272,8 +277,14 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.Issues,
|
||||
prometheus.GaugeValue,
|
||||
float64(stats.Counter.Issue),
|
||||
float64(stats.Counter.IssueOpen), "open",
|
||||
)
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.Issues,
|
||||
prometheus.GaugeValue,
|
||||
float64(stats.Counter.IssueClosed), "closed",
|
||||
)
|
||||
|
||||
for _, il := range stats.Counter.IssueByLabel {
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
c.IssuesByLabel,
|
||||
|
@ -1702,7 +1702,9 @@ issues.time_estimate_invalid = Time estimate format is invalid
|
||||
issues.start_tracking_history = started working %s
|
||||
issues.tracker_auto_close = Timer will be stopped automatically when this issue gets closed
|
||||
issues.tracking_already_started = `You have already started time tracking on <a href="%s">another issue</a>!`
|
||||
issues.stop_tracking = Stop Timer
|
||||
issues.stop_tracking_history = worked for <b>%[1]s</b> %[2]s
|
||||
issues.cancel_tracking = Discard
|
||||
issues.cancel_tracking_history = `canceled time tracking %s`
|
||||
issues.del_time = Delete this time log
|
||||
issues.add_time_history = added spent time <b>%[1]s</b> %[2]s
|
||||
|
@ -6,7 +6,9 @@ package common
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/modules/cache"
|
||||
"code.gitea.io/gitea/modules/gtprof"
|
||||
@ -19,6 +21,45 @@ import (
|
||||
"gitea.com/go-chi/session"
|
||||
"github.com/chi-middleware/proxy"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
const (
|
||||
httpRequestMethod = "http_request_method"
|
||||
httpResponseStatusCode = "http_response_status_code"
|
||||
httpRoute = "http_route"
|
||||
)
|
||||
|
||||
var (
|
||||
// reqInflightGauge tracks the amount of currently handled requests
|
||||
reqInflightGauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: "http",
|
||||
Subsystem: "server",
|
||||
Name: "active_requests",
|
||||
Help: "Number of active HTTP server requests.",
|
||||
}, []string{httpRequestMethod})
|
||||
// reqDurationHistogram tracks the time taken by http request
|
||||
reqDurationHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: "http",
|
||||
Subsystem: "server",
|
||||
Name: "request_duration",
|
||||
Help: "Measures the latency of HTTP requests processed by the server",
|
||||
}, []string{httpRequestMethod, httpResponseStatusCode, httpRoute})
|
||||
// reqSizeHistogram tracks the size of request
|
||||
reqSizeHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: "http",
|
||||
Subsystem: "server_request",
|
||||
Name: "body_size",
|
||||
Help: "Size of HTTP server request bodies.",
|
||||
}, []string{httpRequestMethod, httpResponseStatusCode, httpRoute})
|
||||
// respSizeHistogram tracks the size of the response
|
||||
respSizeHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: "http",
|
||||
Subsystem: "server_response",
|
||||
Name: "body_size",
|
||||
Help: "Size of HTTP server response bodies.",
|
||||
}, []string{httpRequestMethod, httpResponseStatusCode, httpRoute})
|
||||
)
|
||||
|
||||
// ProtocolMiddlewares returns HTTP protocol related middlewares, and it provides a global panic recovery
|
||||
@ -38,6 +79,9 @@ func ProtocolMiddlewares() (handlers []any) {
|
||||
if setting.IsAccessLogEnabled() {
|
||||
handlers = append(handlers, context.AccessLogger())
|
||||
}
|
||||
if setting.Metrics.Enabled {
|
||||
handlers = append(handlers, RouteMetrics())
|
||||
}
|
||||
|
||||
return handlers
|
||||
}
|
||||
@ -107,6 +151,30 @@ func ForwardedHeadersHandler(limit int, trustedProxies []string) func(h http.Han
|
||||
return proxy.ForwardedHeaders(opt)
|
||||
}
|
||||
|
||||
// RouteMetrics instruments http requests and responses
|
||||
func RouteMetrics() func(h http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
inflight := reqInflightGauge.WithLabelValues(req.Method)
|
||||
inflight.Inc()
|
||||
defer inflight.Dec()
|
||||
start := time.Now()
|
||||
|
||||
next.ServeHTTP(resp, req)
|
||||
m := context.WrapResponseWriter(resp)
|
||||
route := chi.RouteContext(req.Context()).RoutePattern()
|
||||
code := strconv.Itoa(m.WrittenStatus())
|
||||
reqDurationHistogram.WithLabelValues(req.Method, code, route).Observe(time.Since(start).Seconds())
|
||||
respSizeHistogram.WithLabelValues(req.Method, code, route).Observe(float64(m.WrittenSize()))
|
||||
size := req.ContentLength
|
||||
if size < 0 {
|
||||
size = 0
|
||||
}
|
||||
reqSizeHistogram.WithLabelValues(req.Method, code, route).Observe(float64(size))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Sessioner() func(next http.Handler) http.Handler {
|
||||
return session.Sessioner(session.Options{
|
||||
Provider: setting.SessionConfig.Provider,
|
||||
|
38
routers/common/middleware_test.go
Normal file
38
routers/common/middleware_test.go
Normal file
@ -0,0 +1,38 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMetricsMiddlewere(t *testing.T) {
|
||||
middleware := RouteMetrics()
|
||||
r := chi.NewRouter()
|
||||
r.Use(middleware)
|
||||
r.Get("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("test"))
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}))
|
||||
testServer := httptest.NewServer(r)
|
||||
// Check all defined metrics
|
||||
verify := func(i int) {
|
||||
assert.Equal(t, testutil.CollectAndCount(reqDurationHistogram, "http_server_request_duration"), i)
|
||||
assert.Equal(t, testutil.CollectAndCount(reqSizeHistogram, "http_server_request_body_size"), i)
|
||||
assert.Equal(t, testutil.CollectAndCount(respSizeHistogram, "http_server_response_body_size"), i)
|
||||
assert.Equal(t, testutil.CollectAndCount(reqInflightGauge, "http_server_active_requests"), i)
|
||||
}
|
||||
|
||||
// Check they don't exist before making a request
|
||||
verify(0)
|
||||
_, err := http.Get(testServer.URL)
|
||||
require.NoError(t, err)
|
||||
// Check they do exist after making the request
|
||||
verify(1)
|
||||
}
|
@ -306,7 +306,7 @@ func prepareWorkflowList(ctx *context.Context, workflows []Workflow) {
|
||||
}
|
||||
ctx.Data["Actors"] = shared_user.MakeSelfOnTop(ctx.Doer, actors)
|
||||
|
||||
ctx.Data["StatusInfoList"] = actions_model.GetStatusInfoList(ctx)
|
||||
ctx.Data["StatusInfoList"] = actions_model.GetStatusInfoList(ctx, ctx.Locale)
|
||||
|
||||
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
|
||||
pager.AddParamFromRequest(ctx.Req)
|
||||
|
@ -53,6 +53,7 @@ import (
|
||||
"github.com/go-chi/cors"
|
||||
"github.com/klauspost/compress/gzhttp"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/collectors"
|
||||
)
|
||||
|
||||
var GzipMinSize = 1400 // min size to compress for the body size of response
|
||||
@ -259,6 +260,7 @@ func Routes() *web.Router {
|
||||
}
|
||||
|
||||
if setting.Metrics.Enabled {
|
||||
prometheus.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{Namespace: "gitea"}))
|
||||
prometheus.MustRegister(metrics.NewCollector())
|
||||
routes.Get("/metrics", append(mid, Metrics)...)
|
||||
}
|
||||
@ -1196,6 +1198,10 @@ func registerRoutes(m *web.Router) {
|
||||
})
|
||||
})
|
||||
}
|
||||
// FIXME: many "pulls" requests are sent to "issues" endpoints correctly, so the issue endpoints have to tolerate pull request permissions at the moment
|
||||
m.Group("/{username}/{reponame}/{type:issues}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, context.RequireUnitReader(unit.TypeIssues, unit.TypePullRequests))
|
||||
m.Group("/{username}/{reponame}/{type:pulls}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, reqUnitPullsReader)
|
||||
|
||||
m.Group("/{username}/{reponame}", func() {
|
||||
m.Get("/comments/{id}/attachments", repo.GetCommentAttachments)
|
||||
m.Get("/labels", repo.RetrieveLabelsForList, repo.Labels)
|
||||
@ -1203,9 +1209,6 @@ func registerRoutes(m *web.Router) {
|
||||
m.Get("/milestone/{id}", context.RepoRef(), repo.MilestoneIssuesAndPulls)
|
||||
m.Get("/issues/suggestions", repo.IssueSuggestions)
|
||||
}, optSignIn, context.RepoAssignment, reqRepoIssuesOrPullsReader) // issue/pull attachments, labels, milestones
|
||||
|
||||
m.Group("/{username}/{reponame}/{type:issues}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, reqUnitIssuesReader)
|
||||
m.Group("/{username}/{reponame}/{type:pulls}", addIssuesPullsViewRoutes, optSignIn, context.RepoAssignment, reqUnitPullsReader)
|
||||
// end "/{username}/{reponame}": view milestone, label, issue, pull, etc
|
||||
|
||||
m.Group("/{username}/{reponame}/{type:issues}", func() {
|
||||
@ -1224,7 +1227,7 @@ func registerRoutes(m *web.Router) {
|
||||
m.Get("/search", repo.SearchRepoIssuesJSON)
|
||||
}, reqUnitIssuesReader)
|
||||
|
||||
addIssuesPullsRoutes := func() {
|
||||
addIssuesPullsUpdateRoutes := func() {
|
||||
// for "/{username}/{reponame}/issues" or "/{username}/{reponame}/pulls"
|
||||
m.Group("/{index}", func() {
|
||||
m.Post("/title", repo.UpdateIssueTitle)
|
||||
@ -1267,8 +1270,9 @@ func registerRoutes(m *web.Router) {
|
||||
m.Delete("/unpin/{index}", reqRepoAdmin, repo.IssueUnpin)
|
||||
m.Post("/move_pin", reqRepoAdmin, repo.IssuePinMove)
|
||||
}
|
||||
m.Group("/{type:issues}", addIssuesPullsRoutes, reqUnitIssuesReader, context.RepoMustNotBeArchived())
|
||||
m.Group("/{type:pulls}", addIssuesPullsRoutes, reqUnitPullsReader, context.RepoMustNotBeArchived())
|
||||
// FIXME: many "pulls" requests are sent to "issues" endpoints incorrectly, so the issue endpoints have to tolerate pull request permissions at the moment
|
||||
m.Group("/{type:issues}", addIssuesPullsUpdateRoutes, context.RequireUnitReader(unit.TypeIssues, unit.TypePullRequests), context.RepoMustNotBeArchived())
|
||||
m.Group("/{type:pulls}", addIssuesPullsUpdateRoutes, reqUnitPullsReader, context.RepoMustNotBeArchived())
|
||||
|
||||
m.Group("/comments/{id}", func() {
|
||||
m.Post("", repo.UpdateCommentContent)
|
||||
@ -1292,7 +1296,7 @@ func registerRoutes(m *web.Router) {
|
||||
m.Post("/delete", repo.DeleteMilestone)
|
||||
}, reqRepoIssuesOrPullsWriter, context.RepoRef())
|
||||
|
||||
// FIXME: need to move these routes to the proper place
|
||||
// FIXME: many "pulls" requests are sent to "issues" endpoints incorrectly, need to move these routes to the proper place
|
||||
m.Group("/issues", func() {
|
||||
m.Post("/request_review", repo.UpdatePullReviewRequest)
|
||||
m.Post("/dismiss_review", reqRepoAdmin, web.Bind(forms.DismissReviewForm{}), repo.DismissReview)
|
||||
|
@ -21,6 +21,14 @@ import (
|
||||
base "code.gitea.io/gitea/modules/migration"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var (
|
||||
repoMigrationsInflightGauge = promauto.NewGauge(prometheus.GaugeOpts{Namespace: "gitea", Subsystem: "repository", Name: "inflight_migrations", Help: "Number of inflight repository migrations"})
|
||||
repoMigrationsCounter = promauto.NewGaugeVec(prometheus.GaugeOpts{Namespace: "gitea", Subsystem: "repository", Name: "migrations", Help: "Total migrations"}, []string{"result"})
|
||||
)
|
||||
|
||||
// MigrateOptions is equal to base.MigrateOptions
|
||||
@ -124,6 +132,9 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
|
||||
return nil, err
|
||||
}
|
||||
|
||||
repoMigrationsInflightGauge.Inc()
|
||||
defer repoMigrationsInflightGauge.Dec()
|
||||
|
||||
uploader := NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName)
|
||||
uploader.gitServiceType = opts.GitServiceType
|
||||
|
||||
@ -134,8 +145,10 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str
|
||||
if err2 := system_model.CreateRepositoryNotice(fmt.Sprintf("Migrate repository from %s failed: %v", opts.OriginalURL, err)); err2 != nil {
|
||||
log.Error("create respotiry notice failed: ", err2)
|
||||
}
|
||||
repoMigrationsCounter.WithLabelValues("fail").Inc()
|
||||
return nil, err
|
||||
}
|
||||
repoMigrationsCounter.WithLabelValues("success").Inc()
|
||||
return uploader.repo, nil
|
||||
}
|
||||
|
||||
|
@ -16,10 +16,10 @@
|
||||
{{if .ShowMemberAndTeamTab}}
|
||||
<div class="ui five wide column">
|
||||
{{if .CanCreateOrgRepo}}
|
||||
<div class="center aligned tw-mb-4">
|
||||
<a class="ui primary button" href="{{AppSubUrl}}/repo/create?org={{.Org.ID}}">{{ctx.Locale.Tr "new_repo"}}</a>
|
||||
<div class="tw-flex tw-flex-wrap tw-justify-center tw-gap-x-1 tw-gap-y-2 tw-mb-4">
|
||||
<a class="ui primary button tw-grow" href="{{AppSubUrl}}/repo/create?org={{.Org.ID}}">{{ctx.Locale.Tr "new_repo"}}</a>
|
||||
{{if not .DisableNewPullMirrors}}
|
||||
<a class="ui primary button" href="{{AppSubUrl}}/repo/migrate?org={{.Org.ID}}&mirror=1">{{ctx.Locale.Tr "new_migrate"}}</a>
|
||||
<a class="ui primary button tw-grow" href="{{AppSubUrl}}/repo/migrate?org={{.Org.ID}}&mirror=1">{{ctx.Locale.Tr "new_migrate"}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user