This repository was archived by the owner on May 30, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +27
-4
lines changed Expand file tree Collapse file tree 6 files changed +27
-4
lines changed Original file line number Diff line number Diff line change 60
60
}
61
61
62
62
Prometheus struct {
63
+ PrometheusEnabled bool `split_words:"true"`
63
64
PrometheusAuthSecret string `split_words:"true"`
64
65
}
65
66
)
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ func newServerConfig(c *Config) *server.ServerConfig {
96
96
ProxyHost : proxyHost ,
97
97
ProxyProto : proxyProto ,
98
98
WebhookSecret : c .WebhookSecret ,
99
+ PrometheusEnabled : c .PrometheusEnabled ,
99
100
PrometheusAuthSecret : c .PrometheusAuthSecret ,
100
101
}
101
102
}
Original file line number Diff line number Diff line change 1
1
# Metrics
2
2
3
- Gtiploy publishes and exposes metrics that Prometheus can consume at the standard ` /metrics ` endpoint.
3
+ Gtiploy publishes and exposes metrics that Prometheus can consume at the standard ` /metrics ` endpoint.
4
4
5
5
## Configuration
6
6
7
7
1\. Configure the server:
8
8
9
9
```
10
+ GITPLOY_PROMETHEUS_ENABLED=true
10
11
GITPLOY_PROMETHEUS_AUTH_SECRET=YOUR_SECRET
11
12
```
12
13
Original file line number Diff line number Diff line change
1
+ # GITPLOY_PROMETHEUS_ENABLED
2
+
3
+ Optional string value to enable exposing metrics that Prometheus can consume. The default value is ` false ` .
4
+
5
+ ```
6
+ GITPLOY_PROMETHEUS_ENABLED=true
7
+ ```
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Index of server configuration settings:
10
10
* [ GITPLOY_LICENSE] ( ./GITPLOY_LICENSE.md )
11
11
* [ GITPLOY_MEMBER_ENTRIES] ( ./GITPLOY_MEMBER_ENTRIES.md )
12
12
* [ GITPLOY_PROMETHEUS_AUTH_SECRET] ( ./GITPLOY_PROMETHEUS_AUTH_SECRET.md )
13
+ * [ GITPLOY_PROMETHEUS_ENABLED] ( ./GITPLOY_PROMETHEUS_ENABLED.md )
13
14
* [ GITPLOY_ORGANIZATION_ENTRIES] ( ./GITPLOY_ORGANIZATION_ENTRIES.md )
14
15
* [ GITPLOY_PROXY_SERVER_HOST] ( ./GITPLOY_PROXY_SERVER_HOST.md )
15
16
* [ GITPLOY_PROXY_SERVER_PROTO] ( ./GITPLOY_PROXY_SERVER_PROTO.md )
Original file line number Diff line number Diff line change 42
42
ProxyHost string
43
43
ProxyProto string
44
44
45
- WebhookSecret string
45
+ WebhookSecret string
46
+
47
+ PrometheusEnabled bool
46
48
PrometheusAuthSecret string
47
49
}
48
50
@@ -101,7 +103,6 @@ func NewRouter(c *RouterConfig) *gin.Engine {
101
103
gm := gb .NewMiddleware (c .Interactor )
102
104
r .Use (
103
105
gm .SetUser (),
104
- metrics .CollectRequestMetrics (),
105
106
)
106
107
107
108
v1 := r .Group ("/api/v1" )
@@ -201,11 +202,13 @@ func NewRouter(c *RouterConfig) *gin.Engine {
201
202
202
203
metricsapi := r .Group ("/metrics" )
203
204
{
205
+ r .Use (metrics .CollectRequestMetrics ())
206
+
204
207
m := metrics .NewMetric (& metrics.MetricConfig {
205
208
Interactor : c .Interactor ,
206
209
PrometheusAuthSecret : c .PrometheusAuthSecret ,
207
210
})
208
- metricsapi .GET ("" , m .CollectMetrics )
211
+ metricsapi .GET ("" , hasOptIn ( c . PrometheusEnabled ), m .CollectMetrics )
209
212
}
210
213
211
214
r .HEAD ("/slack" , func (gc * gin.Context ) {
@@ -303,3 +306,12 @@ func newSlackOauthConfig(c *RouterConfig) *oauth2.Config {
303
306
func isSlackEnabled (c * RouterConfig ) bool {
304
307
return c .ChatConfig != nil && c .ChatConfig .Type == ChatTypeSlack
305
308
}
309
+
310
+ func hasOptIn (enabled bool ) gin.HandlerFunc {
311
+ return func (c * gin.Context ) {
312
+ if ! enabled {
313
+ c .AbortWithStatus (http .StatusNotFound )
314
+ return
315
+ }
316
+ }
317
+ }
You can’t perform that action at this time.
0 commit comments