Skip to content

Commit

Permalink
Refactor prober gauges (#972)
Browse files Browse the repository at this point in the history
Move prober metric GaugeOpts into prober.go to reduce copy-n-paste.

Signed-off-by: SuperQ [email protected]
  • Loading branch information
SuperQ authored Sep 30, 2022
1 parent 4471071 commit 0e044cf
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
11 changes: 3 additions & 8 deletions prober/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
)

Expand Down
15 changes: 3 additions & 12 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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"},
)

Expand Down
17 changes: 17 additions & 0 deletions prober/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
15 changes: 3 additions & 12 deletions prober/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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{
Expand Down

0 comments on commit 0e044cf

Please sign in to comment.