|
29 | 29 | import eu.openanalytics.containerproxy.model.runtime.Proxy; |
30 | 30 | import eu.openanalytics.containerproxy.model.runtime.runtimevalues.BackendContainerName; |
31 | 31 | import eu.openanalytics.containerproxy.model.runtime.runtimevalues.BackendContainerNameKey; |
| 32 | +import eu.openanalytics.containerproxy.service.StructuredLogger; |
32 | 33 | import eu.openanalytics.containerproxy.stat.IStatCollector; |
33 | 34 | import io.micrometer.core.instrument.Gauge; |
34 | 35 | import io.micrometer.core.instrument.MeterRegistry; |
35 | 36 | import io.micrometer.core.instrument.Tags; |
36 | 37 | import io.micrometer.core.instrument.search.MeterNotFoundException; |
| 38 | +import org.slf4j.Logger; |
| 39 | +import org.slf4j.LoggerFactory; |
37 | 40 | import org.springframework.beans.factory.annotation.Autowired; |
38 | 41 | import org.springframework.context.event.EventListener; |
39 | 42 |
|
@@ -72,6 +75,7 @@ public class ProxySharingMicrometer implements IStatCollector { |
72 | 75 | ); |
73 | 76 |
|
74 | 77 | private Cache<String, String> recentProxies; |
| 78 | + private final Logger logger = LoggerFactory.getLogger(getClass()); |
75 | 79 |
|
76 | 80 | /** |
77 | 81 | * Wraps a function that returns an Integer into a function that returns a double. |
@@ -138,59 +142,63 @@ public void onNewProxyEvent(NewProxyEvent event) { |
138 | 142 | } |
139 | 143 |
|
140 | 144 | private void updateDelegateAppInfo() { |
141 | | - Map<String, Gauge> existingGauges = getDelegateAppInfoGauges(); |
142 | | - for (ProxySharingScaler scaler : proxySharingScalers) { |
143 | | - String specId = scaler.getSpec().getId(); |
144 | | - for (DelegateProxy delegateProxy : scaler.getAllDelegateProxies()) { |
145 | | - Proxy proxy = delegateProxy.getProxy(); |
146 | | - recentProxies.put(proxy.getId(), proxy.getId()); |
147 | | - Gauge existingGauge = existingGauges.remove(proxy.getId()); |
148 | | - if (existingGauge != null && existingGauge.value() == PROXY_STATUS_TO_INTEGER.get(delegateProxy.getDelegateProxyStatus())) { |
149 | | - // gauge already exists and value is correct |
150 | | - continue; |
151 | | - } |
152 | | - if (existingGauge != null) { |
153 | | - registry.remove(existingGauge); |
| 145 | + try { |
| 146 | + Map<String, Gauge> existingGauges = getDelegateAppInfoGauges(); |
| 147 | + for (ProxySharingScaler scaler : proxySharingScalers) { |
| 148 | + String specId = scaler.getSpec().getId(); |
| 149 | + for (DelegateProxy delegateProxy : scaler.getAllDelegateProxies()) { |
| 150 | + Proxy proxy = delegateProxy.getProxy(); |
| 151 | + recentProxies.put(proxy.getId(), proxy.getId()); |
| 152 | + Gauge existingGauge = existingGauges.remove(proxy.getId()); |
| 153 | + if (existingGauge != null && existingGauge.value() == PROXY_STATUS_TO_INTEGER.get(delegateProxy.getDelegateProxyStatus())) { |
| 154 | + // gauge already exists and value is correct |
| 155 | + continue; |
| 156 | + } |
| 157 | + if (existingGauge != null) { |
| 158 | + registry.remove(existingGauge); |
| 159 | + } |
| 160 | + |
| 161 | + BackendContainerName backendContainerName = getBackendContainerName(proxy); |
| 162 | + if (backendContainerName == null) { |
| 163 | + // container not fully ready, will be registered later |
| 164 | + continue; |
| 165 | + } |
| 166 | + |
| 167 | + registry.gauge("delegate_app_info", |
| 168 | + Tags.of( |
| 169 | + "spec.id", specId, |
| 170 | + "proxy.id", proxy.getId(), |
| 171 | + "proxy.created.timestamp", Long.toString(proxy.getCreatedTimestamp()), |
| 172 | + "resource.id", backendContainerName.getName(), |
| 173 | + "proxy.namespace", backendContainerName.getNamespace()), |
| 174 | + PROXY_STATUS_TO_INTEGER.get(delegateProxy.getDelegateProxyStatus()) |
| 175 | + ); |
154 | 176 | } |
155 | | - |
156 | | - BackendContainerName backendContainerName = getBackendContainerName(proxy); |
157 | | - if (backendContainerName == null) { |
158 | | - // container not fully ready, will be registered later |
| 177 | + } |
| 178 | + for (Gauge gauge : existingGauges.values()) { |
| 179 | + String proxyId = gauge.getId().getTag("proxy.id"); |
| 180 | + if (proxyId != null && recentProxies.getIfPresent(proxyId) != null) { |
| 181 | + // this DelegateProxy has been removed, mark it as ToRemove |
| 182 | + // when the TTL of this proxy in recentProxies expires, the gauge will be removed |
| 183 | + // this waiting period allows the metric system to pick up that the proxy is being removed |
| 184 | + registry.remove(gauge); |
| 185 | + registry.gauge("delegate_app_info", |
| 186 | + Tags.of( |
| 187 | + "spec.id", gauge.getId().getTag("spec.id"), |
| 188 | + "proxy.id", gauge.getId().getTag("proxy.id"), |
| 189 | + "proxy.created.timestamp", gauge.getId().getTag("proxy.created.timestamp"), |
| 190 | + "resource.id", gauge.getId().getTag("resource.id"), |
| 191 | + "proxy.namespace", gauge.getId().getTag("proxy.namespace")), |
| 192 | + PROXY_STATUS_TO_INTEGER.get(DelegateProxyStatus.ToRemove) |
| 193 | + ); |
159 | 194 | continue; |
160 | 195 | } |
161 | 196 |
|
162 | | - registry.gauge("delegate_app_info", |
163 | | - Tags.of( |
164 | | - "spec.id", specId, |
165 | | - "proxy.id", proxy.getId(), |
166 | | - "proxy.created.timestamp", Long.toString(proxy.getCreatedTimestamp()), |
167 | | - "resource.id", backendContainerName.getName(), |
168 | | - "proxy.namespace", backendContainerName.getNamespace()), |
169 | | - PROXY_STATUS_TO_INTEGER.get(delegateProxy.getDelegateProxyStatus()) |
170 | | - ); |
171 | | - } |
172 | | - } |
173 | | - for (Gauge gauge : existingGauges.values()) { |
174 | | - String proxyId = gauge.getId().getTag("proxy.id"); |
175 | | - if (proxyId != null && recentProxies.getIfPresent(proxyId) != null) { |
176 | | - // this DelegateProxy has been removed, mark it as ToRemove |
177 | | - // when the TTL of this proxy in recentProxies expires, the gauge will be removed |
178 | | - // this waiting period allows the metric system to pick up that the proxy is being removed |
| 197 | + // the proxy of this gauge no longer exists -> remove the gauge |
179 | 198 | registry.remove(gauge); |
180 | | - registry.gauge("delegate_app_info", |
181 | | - Tags.of( |
182 | | - "spec.id", gauge.getId().getTag("spec.id"), |
183 | | - "proxy.id", gauge.getId().getTag("proxy.id"), |
184 | | - "proxy.created.timestamp", gauge.getId().getTag("proxy.created.timestamp"), |
185 | | - "resource.id", gauge.getId().getTag("resource.id"), |
186 | | - "proxy.namespace", gauge.getId().getTag("proxy.namespace")), |
187 | | - PROXY_STATUS_TO_INTEGER.get(DelegateProxyStatus.ToRemove) |
188 | | - ); |
189 | | - continue; |
190 | 199 | } |
191 | | - |
192 | | - // the proxy of this gauge no longer exists -> remove the gauge |
193 | | - registry.remove(gauge); |
| 200 | + } catch (Exception e) { |
| 201 | + logger.warn("Error while updating delegateAppInfo", e); |
194 | 202 | } |
195 | 203 | } |
196 | 204 |
|
|
0 commit comments