23
23
import java .util .ArrayList ;
24
24
import java .util .Collection ;
25
25
import java .util .Comparator ;
26
- import java .util .EnumSet ;
27
26
import java .util .HashSet ;
28
27
import java .util .List ;
29
28
import java .util .Map ;
30
29
import java .util .Set ;
31
30
import java .util .concurrent .ConcurrentHashMap ;
32
31
33
- import io .micrometer .core .instrument .Gauge ;
34
32
import io .micrometer .core .instrument .MeterRegistry ;
35
33
import io .micrometer .core .instrument .MultiGauge ;
36
34
import io .micrometer .core .instrument .MultiGauge .Row ;
42
40
import org .springframework .boot .info .SslInfo .BundleInfo ;
43
41
import org .springframework .boot .info .SslInfo .CertificateChainInfo ;
44
42
import org .springframework .boot .info .SslInfo .CertificateInfo ;
45
- import org .springframework .boot .info .SslInfo .CertificateValidityInfo ;
46
- import org .springframework .boot .info .SslInfo .CertificateValidityInfo .Status ;
47
43
import org .springframework .boot .ssl .SslBundles ;
48
44
49
45
/**
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}.
53
48
*
54
49
* @author Moritz Halbritter
55
50
*/
56
51
class SslMeterBinder implements MeterBinder {
57
52
58
- private static final String CHAINS_METRIC_NAME = "ssl.chains" ;
59
-
60
53
private static final String CHAIN_EXPIRY_METRIC_NAME = "ssl.chain.expiry" ;
61
54
62
55
private final Clock clock ;
@@ -91,18 +84,6 @@ public void bindTo(MeterRegistry meterRegistry) {
91
84
for (BundleInfo bundle : this .sslInfo .getBundles ()) {
92
85
createOrUpdateBundleMetrics (meterRegistry , bundle );
93
86
}
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 );
106
87
}
107
88
108
89
private void createOrUpdateBundleMetrics (MeterRegistry meterRegistry , BundleInfo bundle ) {
@@ -130,36 +111,6 @@ private Row<CertificateInfo> createRowForChain(BundleInfo bundle, CertificateCha
130
111
return Row .of (tags , leastValidCertificate , this ::getChainExpiry );
131
112
}
132
113
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
-
163
114
private long getChainExpiry (CertificateInfo certificate ) {
164
115
Duration valid = Duration .between (Instant .now (this .clock ), certificate .getValidityEnds ());
165
116
return valid .get (ChronoUnit .SECONDS );
@@ -184,18 +135,6 @@ MultiGauge getGauge(BundleInfo bundleInfo, MeterRegistry meterRegistry) {
184
135
return gauges .getGauge (meterRegistry );
185
136
}
186
137
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
-
199
138
/**
200
139
* Returns all meter registries.
201
140
* @return all meter registries
0 commit comments