2323import java .util .ArrayList ;
2424import java .util .Collection ;
2525import java .util .Comparator ;
26- import java .util .EnumSet ;
2726import java .util .HashSet ;
2827import java .util .List ;
2928import java .util .Map ;
3029import java .util .Set ;
3130import java .util .concurrent .ConcurrentHashMap ;
3231
33- import io .micrometer .core .instrument .Gauge ;
3432import io .micrometer .core .instrument .MeterRegistry ;
3533import io .micrometer .core .instrument .MultiGauge ;
3634import io .micrometer .core .instrument .MultiGauge .Row ;
4240import org .springframework .boot .info .SslInfo .BundleInfo ;
4341import org .springframework .boot .info .SslInfo .CertificateChainInfo ;
4442import org .springframework .boot .info .SslInfo .CertificateInfo ;
45- import org .springframework .boot .info .SslInfo .CertificateValidityInfo ;
46- import org .springframework .boot .info .SslInfo .CertificateValidityInfo .Status ;
4743import org .springframework .boot .ssl .SslBundles ;
4844
4945/**
50- * {@link MeterBinder} which registers the SSL chain validity (soonest to expire
51- * certificate in the chain) as a {@link TimeGauge}. Also contributes two {@link Gauge
52- * gauges} to count the valid and invalid chains.
46+ * {@link MeterBinder} which registers the SSL chain expiry (soonest to expire certificate
47+ * in the chain) as a {@link TimeGauge}.
5348 *
5449 * @author Moritz Halbritter
5550 */
5651class SslMeterBinder implements MeterBinder {
5752
58- private static final String CHAINS_METRIC_NAME = "ssl.chains" ;
59-
6053 private static final String CHAIN_EXPIRY_METRIC_NAME = "ssl.chain.expiry" ;
6154
6255 private final Clock clock ;
@@ -91,18 +84,6 @@ public void bindTo(MeterRegistry meterRegistry) {
9184 for (BundleInfo bundle : this .sslInfo .getBundles ()) {
9285 createOrUpdateBundleMetrics (meterRegistry , bundle );
9386 }
94- Gauge .builder (CHAINS_METRIC_NAME , () -> countChainsByStatus (Status .VALID ))
95- .tag ("status" , "valid" )
96- .register (meterRegistry );
97- Gauge .builder (CHAINS_METRIC_NAME , () -> countChainsByStatus (Status .EXPIRED ))
98- .tag ("status" , "expired" )
99- .register (meterRegistry );
100- Gauge .builder (CHAINS_METRIC_NAME , () -> countChainsByStatus (Status .NOT_YET_VALID ))
101- .tag ("status" , "not-yet-valid" )
102- .register (meterRegistry );
103- Gauge .builder (CHAINS_METRIC_NAME , () -> countChainsByStatus (Status .WILL_EXPIRE_SOON ))
104- .tag ("status" , "will-expire-soon" )
105- .register (meterRegistry );
10687 }
10788
10889 private void createOrUpdateBundleMetrics (MeterRegistry meterRegistry , BundleInfo bundle ) {
@@ -130,36 +111,6 @@ private Row<CertificateInfo> createRowForChain(BundleInfo bundle, CertificateCha
130111 return Row .of (tags , leastValidCertificate , this ::getChainExpiry );
131112 }
132113
133- private long countChainsByStatus (Status status ) {
134- long count = 0 ;
135- for (BundleInfo bundle : this .bundleMetrics .getBundles ()) {
136- for (CertificateChainInfo chain : bundle .getCertificateChains ()) {
137- if (getChainStatus (chain ) == status ) {
138- count ++;
139- }
140- }
141- }
142- return count ;
143- }
144-
145- private Status getChainStatus (CertificateChainInfo chain ) {
146- EnumSet <Status > statuses = EnumSet .noneOf (Status .class );
147- for (CertificateInfo certificate : chain .getCertificates ()) {
148- CertificateValidityInfo validity = certificate .getValidity ();
149- statuses .add (validity .getStatus ());
150- }
151- if (statuses .contains (Status .EXPIRED )) {
152- return Status .EXPIRED ;
153- }
154- if (statuses .contains (Status .NOT_YET_VALID )) {
155- return Status .NOT_YET_VALID ;
156- }
157- if (statuses .contains (Status .WILL_EXPIRE_SOON )) {
158- return Status .WILL_EXPIRE_SOON ;
159- }
160- return statuses .isEmpty () ? null : Status .VALID ;
161- }
162-
163114 private long getChainExpiry (CertificateInfo certificate ) {
164115 Duration valid = Duration .between (Instant .now (this .clock ), certificate .getValidityEnds ());
165116 return valid .get (ChronoUnit .SECONDS );
@@ -184,18 +135,6 @@ MultiGauge getGauge(BundleInfo bundleInfo, MeterRegistry meterRegistry) {
184135 return gauges .getGauge (meterRegistry );
185136 }
186137
187- /**
188- * Returns all bundles.
189- * @return all bundles
190- */
191- Collection <BundleInfo > getBundles () {
192- List <BundleInfo > result = new ArrayList <>();
193- for (Gauges metrics : this .gauges .values ()) {
194- result .add (metrics .bundle ());
195- }
196- return result ;
197- }
198-
199138 /**
200139 * Returns all meter registries.
201140 * @return all meter registries
0 commit comments