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 6060 }
6161
6262 Prometheus struct {
63+ PrometheusEnabled bool `split_words:"true"`
6364 PrometheusAuthSecret string `split_words:"true"`
6465 }
6566)
Original file line number Diff line number Diff line change @@ -96,6 +96,7 @@ func newServerConfig(c *Config) *server.ServerConfig {
9696 ProxyHost : proxyHost ,
9797 ProxyProto : proxyProto ,
9898 WebhookSecret : c .WebhookSecret ,
99+ PrometheusEnabled : c .PrometheusEnabled ,
99100 PrometheusAuthSecret : c .PrometheusAuthSecret ,
100101 }
101102}
Original file line number Diff line number Diff line change 11# Metrics
22
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.
44
55## Configuration
66
771\. Configure the server:
88
99```
10+ GITPLOY_PROMETHEUS_ENABLED=true
1011GITPLOY_PROMETHEUS_AUTH_SECRET=YOUR_SECRET
1112```
1213
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:
1010* [ GITPLOY_LICENSE] ( ./GITPLOY_LICENSE.md )
1111* [ GITPLOY_MEMBER_ENTRIES] ( ./GITPLOY_MEMBER_ENTRIES.md )
1212* [ GITPLOY_PROMETHEUS_AUTH_SECRET] ( ./GITPLOY_PROMETHEUS_AUTH_SECRET.md )
13+ * [ GITPLOY_PROMETHEUS_ENABLED] ( ./GITPLOY_PROMETHEUS_ENABLED.md )
1314* [ GITPLOY_ORGANIZATION_ENTRIES] ( ./GITPLOY_ORGANIZATION_ENTRIES.md )
1415* [ GITPLOY_PROXY_SERVER_HOST] ( ./GITPLOY_PROXY_SERVER_HOST.md )
1516* [ GITPLOY_PROXY_SERVER_PROTO] ( ./GITPLOY_PROXY_SERVER_PROTO.md )
Original file line number Diff line number Diff line change 4242 ProxyHost string
4343 ProxyProto string
4444
45- WebhookSecret string
45+ WebhookSecret string
46+
47+ PrometheusEnabled bool
4648 PrometheusAuthSecret string
4749 }
4850
@@ -101,7 +103,6 @@ func NewRouter(c *RouterConfig) *gin.Engine {
101103 gm := gb .NewMiddleware (c .Interactor )
102104 r .Use (
103105 gm .SetUser (),
104- metrics .CollectRequestMetrics (),
105106 )
106107
107108 v1 := r .Group ("/api/v1" )
@@ -201,11 +202,13 @@ func NewRouter(c *RouterConfig) *gin.Engine {
201202
202203 metricsapi := r .Group ("/metrics" )
203204 {
205+ r .Use (metrics .CollectRequestMetrics ())
206+
204207 m := metrics .NewMetric (& metrics.MetricConfig {
205208 Interactor : c .Interactor ,
206209 PrometheusAuthSecret : c .PrometheusAuthSecret ,
207210 })
208- metricsapi .GET ("" , m .CollectMetrics )
211+ metricsapi .GET ("" , hasOptIn ( c . PrometheusEnabled ), m .CollectMetrics )
209212 }
210213
211214 r .HEAD ("/slack" , func (gc * gin.Context ) {
@@ -303,3 +306,12 @@ func newSlackOauthConfig(c *RouterConfig) *oauth2.Config {
303306func isSlackEnabled (c * RouterConfig ) bool {
304307 return c .ChatConfig != nil && c .ChatConfig .Type == ChatTypeSlack
305308}
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