Refactor prober gauges (#972)
authorBen Kochie <superq@gmail.com>
Fri, 30 Sep 2022 10:12:24 +0000 (12:12 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Sep 2022 10:12:24 +0000 (15:42 +0530)
Move prober metric GaugeOpts into prober.go to reduce copy-n-paste.

Signed-off-by: SuperQ superq@gmail.com
prober/grpc.go
prober/http.go
prober/prober.go
prober/tcp.go

index 45e2d720ac4edc9c3aedb29e5829c12f940fbd27..e7a5921e387818f9986e0a3c2eac242e741d7a68 100644 (file)
@@ -97,15 +97,10 @@ func ProbeGRPC(ctx context.Context, target string, module config.Module, registr
                        Help: "Response HealthCheck response",
                }, []string{"serving_status"})
 
-               probeSSLEarliestCertExpiryGauge = prometheus.NewGauge(prometheus.GaugeOpts{
-                       Name: "probe_ssl_earliest_cert_expiry",
-                       Help: helpSSLEarliestCertExpiry,
-               })
+               probeSSLEarliestCertExpiryGauge = prometheus.NewGauge(sslEarliestCertExpiryGaugeOpts)
 
-               probeTLSVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
-                       Name: "probe_tls_version_info",
-                       Help: helpProbeTLSInfo,
-               },
+               probeTLSVersion = prometheus.NewGaugeVec(
+                       probeTLSInfoGaugeOpts,
                        []string{"version"},
                )
 
index 17d75d75409a7189c8f02d702a9394f8ca587ea9..af12c7e427985ac0239ebd011326fc48020aeeec 100644 (file)
@@ -264,15 +264,9 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
                        Help: "Response HTTP status code",
                })
 
-               probeSSLEarliestCertExpiryGauge = prometheus.NewGauge(prometheus.GaugeOpts{
-                       Name: "probe_ssl_earliest_cert_expiry",
-                       Help: helpSSLEarliestCertExpiry,
-               })
+               probeSSLEarliestCertExpiryGauge = prometheus.NewGauge(sslEarliestCertExpiryGaugeOpts)
 
-               probeSSLLastChainExpiryTimestampSeconds = prometheus.NewGauge(prometheus.GaugeOpts{
-                       Name: "probe_ssl_last_chain_expiry_timestamp_seconds",
-                       Help: helpSSLChainExpiryInTimeStamp,
-               })
+               probeSSLLastChainExpiryTimestampSeconds = prometheus.NewGauge(sslChainExpiryInTimeStampGaugeOpts)
 
                probeSSLLastInformation = prometheus.NewGaugeVec(
                        prometheus.GaugeOpts{
@@ -283,10 +277,7 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
                )
 
                probeTLSVersion = prometheus.NewGaugeVec(
-                       prometheus.GaugeOpts{
-                               Name: "probe_tls_version_info",
-                               Help: helpProbeTLSInfo,
-                       },
+                       probeTLSInfoGaugeOpts,
                        []string{"version"},
                )
 
index ec67e56c206a1ba349e209c33619b32f552416e9..850ee7c5b3e0990a99af0bef51173603887e566f 100644 (file)
@@ -29,3 +29,20 @@ const (
        helpSSLChainExpiryInTimeStamp = "Returns last SSL chain expiry in timestamp"
        helpProbeTLSInfo              = "Returns the TLS version used or NaN when unknown"
 )
+
+var (
+       sslEarliestCertExpiryGaugeOpts = prometheus.GaugeOpts{
+               Name: "probe_ssl_earliest_cert_expiry",
+               Help: helpSSLEarliestCertExpiry,
+       }
+
+       sslChainExpiryInTimeStampGaugeOpts = prometheus.GaugeOpts{
+               Name: "probe_ssl_last_chain_expiry_timestamp_seconds",
+               Help: helpSSLChainExpiryInTimeStamp,
+       }
+
+       probeTLSInfoGaugeOpts = prometheus.GaugeOpts{
+               Name: "probe_tls_version_info",
+               Help: helpProbeTLSInfo,
+       }
+)
index f70e5835b8a612a55f031173ee30cf58d1a1568b..dab140c59fa21f6b4e7fc959a4fc814414ac94d0 100644 (file)
@@ -89,14 +89,8 @@ func dialTCP(ctx context.Context, target string, module config.Module, registry
 }
 
 func ProbeTCP(ctx context.Context, target string, module config.Module, registry *prometheus.Registry, logger log.Logger) bool {
-       probeSSLEarliestCertExpiry := prometheus.NewGauge(prometheus.GaugeOpts{
-               Name: "probe_ssl_earliest_cert_expiry",
-               Help: helpSSLEarliestCertExpiry,
-       })
-       probeSSLLastChainExpiryTimestampSeconds := prometheus.NewGauge(prometheus.GaugeOpts{
-               Name: "probe_ssl_last_chain_expiry_timestamp_seconds",
-               Help: helpSSLChainExpiryInTimeStamp,
-       })
+       probeSSLEarliestCertExpiry := prometheus.NewGauge(sslEarliestCertExpiryGaugeOpts)
+       probeSSLLastChainExpiryTimestampSeconds := prometheus.NewGauge(sslChainExpiryInTimeStampGaugeOpts)
        probeSSLLastInformation := prometheus.NewGaugeVec(
                prometheus.GaugeOpts{
                        Name: "probe_ssl_last_chain_info",
@@ -105,10 +99,7 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
                []string{"fingerprint_sha256", "subject", "issuer", "subjectalternative"},
        )
        probeTLSVersion := prometheus.NewGaugeVec(
-               prometheus.GaugeOpts{
-                       Name: "probe_tls_version_info",
-                       Help: helpProbeTLSInfo,
-               },
+               probeTLSInfoGaugeOpts,
                []string{"version"},
        )
        probeFailedDueToRegex := prometheus.NewGauge(prometheus.GaugeOpts{