Skip to content

Commit 4e8b9eb

Browse files
hdurand0710oktalz
authored andcommitted
MEDIUM: add prometheus metric haproxy_unable_to_sync_configuration
1 parent 350c507 commit 4e8b9eb

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

.aspell.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ allowed:
4242
- parallelize
4343
- maxconn
4444
- kubebuilder
45+
- cfg
46+
- optim
47+
- prometheus

documentation/prometheus.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ On top of the prometheus provided metrics, we added these three ones:
2626
haproxy_reloads_total: The number of haproxy reloads partitioned by result (success/failure)
2727
haproxy_restarts_total: The number of haproxy restarts partitioned by result (success/failure)
2828
haproxy_runtime_socket_connections_total: The number of haproxy runtime socket connections partitioned by object (server/map) and result (success/failure)
29+
haproxy_unable_to_sync_configuration 1 = there's a pending haproxy configuration that is not valid so not applicable, 0 = haproxy configuration applied
2930
```
3031

3132

@@ -46,4 +47,7 @@ haproxy_restarts_total{result="success"} 1
4647
# TYPE haproxy_runtime_socket_connections_total counter
4748
haproxy_runtime_socket_connections_total{object="map",result="success"} 4
4849
haproxy_runtime_socket_connections_total{object="server",result="success"} 50
50+
# HELP haproxy_unable_to_sync_configuration 1 = there's a pending haproxy configuration that is not valid so not applicable, 0 = haproxy configuration applied
51+
# TYPE haproxy_unable_to_sync_configuration gauge
52+
haproxy_unable_to_sync_configuration 1
4953
```

pkg/controller/controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func (c *HAProxyController) Stop() {
111111
func (c *HAProxyController) updateHAProxy() {
112112
var err error
113113
logger.Trace("HAProxy config sync started")
114+
c.prometheusMetricsManager.UnsetUnableSyncGauge()
114115

115116
err = c.haproxy.APIStartTransaction()
116117
if err != nil {
@@ -183,6 +184,7 @@ func (c *HAProxyController) updateHAProxy() {
183184

184185
err = c.haproxy.APICommitTransaction()
185186
if err != nil {
187+
c.prometheusMetricsManager.SetUnableSyncGauge()
186188
logger.Error("unable to Sync HAProxy configuration !!")
187189
logger.Error(err)
188190
rerun, errCfgSnippet := annotations.CheckBackendConfigSnippetError(err, c.haproxy.Env.CfgDir)

pkg/metrics/prometheus.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const (
1515
)
1616

1717
type PrometheusMetricsManager struct {
18+
unableToSyncGauge prometheus.Gauge
19+
1820
// reload
1921
reloadsCounterVec *prometheus.CounterVec
2022

@@ -47,9 +49,15 @@ func New() PrometheusMetricsManager {
4749
[]string{"object", "result"},
4850
)
4951

52+
unableToSyncGauge := promauto.NewGauge(prometheus.GaugeOpts{
53+
Name: "haproxy_unable_to_sync_configuration",
54+
Help: "1 = there's a pending haproxy configuration that is not valid so not applicable, 0 = haproxy configuration applied",
55+
})
56+
5057
pmm = PrometheusMetricsManager{
5158
reloadsCounterVec: reloadCounter,
5259
runtimeSocketCounterVec: runtimeSocketCounter,
60+
unableToSyncGauge: unableToSyncGauge,
5361
}
5462
})
5563
return pmm
@@ -70,3 +78,11 @@ func (pmm PrometheusMetricsManager) UpdateRuntimeMetrics(object string, err erro
7078
pmm.runtimeSocketCounterVec.WithLabelValues(object, ResultSuccess).Inc()
7179
}
7280
}
81+
82+
func (pmm PrometheusMetricsManager) SetUnableSyncGauge() {
83+
pmm.unableToSyncGauge.Set(float64(1))
84+
}
85+
86+
func (pmm PrometheusMetricsManager) UnsetUnableSyncGauge() {
87+
pmm.unableToSyncGauge.Set(float64(0))
88+
}

0 commit comments

Comments
 (0)