Skip to content

Commit 627a72d

Browse files
Merge pull request #153 from xenit-eu/ALFREDOPS-850
ALFREDOPS-850 re-fetch trackers on each call
2 parents f0fbb78 + f3304c6 commit 627a72d

File tree

6 files changed

+145
-103
lines changed

6 files changed

+145
-103
lines changed

CHANGELOG.md

+30-11
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,46 @@ Version template:
2121
-->
2222

2323
# Alfred Telemetry Changelog
24+
## [0.10.1] - 2023-10-27
25+
### Fixed
26+
* re-fetch trackers on each call [[#153]]
27+
28+
[#153]: https://github.com/xenit-eu/alfred-telemetry/pull/153
29+
2430
## [0.10.0] - 2023-08-31
2531
### Added
26-
* Added support for alfresco 7.4 [#146]
32+
* Added support for alfresco 7.4 [[#146]]
33+
34+
[#146]: https://github.com/xenit-eu/alfred-telemetry/pull/146
35+
2736
## [0.9.3] - 2023-01-13
2837
### Added
29-
* Added TomcatMetrics [#142]
38+
* Added TomcatMetrics [[#142]]
39+
40+
[#142]: https://github.com/xenit-eu/alfred-telemetry/pull/142
3041

3142
## [0.9.2] - 2022-12-23
3243

3344
### Fixed
34-
* First call to Alfred Telemetry endpoint Solr always failing,Fix SolrSnapShot Metrics [#140]
45+
* First call to Alfred Telemetry endpoint Solr always failing,Fix SolrSnapShot Metrics [[#140]]
46+
47+
[#140]: https://github.com/xenit-eu/alfred-telemetry/pull/140
3548

3649
## [0.9.1] - 2022-12-23
3750

3851
### Fixed
39-
* Fix hazel cast metrics with micrometer [#137]
52+
* Fix hazel cast metrics with micrometer [[#137]]
53+
54+
[#137]: https://github.com/xenit-eu/alfred-telemetry/pull/137
4055

4156
## [0.9.0] - 2022-12-01
4257

4358
### Fixed
44-
* Fixes broken Apache Commons dbcp dependencies [#132]
45-
* Fixes broken common tags not added to Alfrescos Prometheus registry [#134]
59+
* Fixes broken Apache Commons dbcp dependencies [[#132]]
60+
* Fixes broken common tags not added to Alfrescos Prometheus registry [[#134]]
61+
62+
[#132]: https://github.com/xenit-eu/alfred-telemetry/pull/132
63+
[#134]: https://github.com/xenit-eu/alfred-telemetry/pull/134
4664

4765
### Added
4866
* Added support Alfresco 7.1, 7.2 and 7.3
@@ -54,11 +72,12 @@ Version template:
5472

5573
### BREAKING
5674

57-
* Alfred Telemetry declares `micrometer-core` and `micrometer-jvm-extras` as a provided-dependency [#129]
75+
* Alfred Telemetry declares `micrometer-core` and `micrometer-jvm-extras` as a provided-dependency [[#129]]
76+
5877
[#129]: https://github.com/xenit-eu/alfred-telemetry/pull/129
5978

6079
### Fixed
61-
* Fixes bug when tracker is explicitly disabled [#125]
80+
* Fixes bug when tracker is explicitly disabled [[#125]]
6281

6382

6483
## [0.7.2] - 2021-10-07
@@ -67,13 +86,13 @@ Version template:
6786
* Added Common tags to Alfred Telemetry Solr
6887

6988
### Fixed
70-
* Bug appearing when tracker is explicitly disabled [#125]
89+
* Bug appearing when tracker is explicitly disabled [[#125]]
7190

7291
[#125]: https://github.com/xenit-eu/alfred-telemetry/pull/125
7392

7493
### Added
75-
* Support more flexible Graphite step duration configuration [#123]
76-
* Add metrics for solr backup [#124]
94+
* Support more flexible Graphite step duration configuration [[#123]]
95+
* Add metrics for solr backup [[#124]]
7796

7897
[#123]: https://github.com/xenit-eu/alfred-telemetry/pull/123
7998
[#124]: https://github.com/xenit-eu/alfred-telemetry/pull/124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package eu.xenit.alfred.telemetry.solr.monitoring.binder;
2+
3+
import io.micrometer.core.instrument.MeterRegistry;
4+
import io.micrometer.core.instrument.binder.MeterBinder;
5+
import org.alfresco.solr.AlfrescoCoreAdminHandler;
6+
import org.alfresco.solr.tracker.TrackerRegistry;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
public abstract class AbstractSolrMetrics implements MeterBinder {
11+
private static final Logger logger = LoggerFactory.getLogger(AbstractSolrMetrics.class);
12+
protected final AlfrescoCoreAdminHandler coreAdminHandler;
13+
protected MeterRegistry registry;
14+
15+
AbstractSolrMetrics(AlfrescoCoreAdminHandler coreAdminHandler) {
16+
this.coreAdminHandler = coreAdminHandler;
17+
}
18+
19+
protected TrackerRegistry getTrackerRegistryWhenAvailable() {
20+
logger.info("Registering tracker metrics");
21+
TrackerRegistry trackerRegistry = coreAdminHandler.getTrackerRegistry();
22+
23+
while (trackerRegistry.getCoreNames().isEmpty()) {
24+
logger.error("Solr did not start tracking yet, waiting 10sec");
25+
try {
26+
Thread.currentThread().sleep(10_000);
27+
trackerRegistry = coreAdminHandler.getTrackerRegistry();
28+
} catch (InterruptedException e) {
29+
logger.error("Fail to wait 10 sec", e);
30+
}
31+
}
32+
return trackerRegistry;
33+
}
34+
35+
@Override
36+
public void bindTo(MeterRegistry registry) {
37+
this.registry = registry;
38+
registerMetrics();
39+
}
40+
41+
protected abstract void registerMetrics();
42+
}
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,85 @@
11
package eu.xenit.alfred.telemetry.solr.monitoring.binder;
22

33
import io.micrometer.core.instrument.Gauge;
4-
import io.micrometer.core.instrument.MeterRegistry;
54
import io.micrometer.core.instrument.Tags;
65
import io.micrometer.core.instrument.binder.MeterBinder;
7-
import java.io.IOException;
8-
import java.util.Map.Entry;
96
import org.alfresco.solr.AlfrescoCoreAdminHandler;
107
import org.alfresco.solr.SolrInformationServer;
118
import org.alfresco.solr.tracker.TrackerRegistry;
129
import org.slf4j.Logger;
1310
import org.slf4j.LoggerFactory;
1411

15-
public class SolrCoreStatsMetrics implements MeterBinder {
12+
import java.io.IOException;
13+
import java.util.Map.Entry;
14+
15+
public class SolrCoreStatsMetrics extends AbstractSolrMetrics implements MeterBinder {
1616

1717
private static final String METER_ALFRESCO_NODES = "alfresco.nodes";
1818
private static final String TAG_STATE = "state";
1919
private static final String TAG_VALUE_INDEXED = "Indexed";
2020

21-
private final AlfrescoCoreAdminHandler coreAdminHandler;
22-
private MeterRegistry registry;
2321

2422
private static final Logger logger = LoggerFactory.getLogger(SolrCoreStatsMetrics.class);
2523

2624
public SolrCoreStatsMetrics(AlfrescoCoreAdminHandler coreAdminHandler) {
27-
this.coreAdminHandler = coreAdminHandler;
25+
super(coreAdminHandler);
2826
}
2927

30-
private void registerCoreStats() {
31-
TrackerRegistry trackerRegistry = coreAdminHandler.getTrackerRegistry();
32-
33-
while (trackerRegistry.getCoreNames().size() == 0) {
34-
logger.error("Solr did not start tracking yet, waiting 10sec");
35-
try {
36-
Thread.currentThread().sleep(10_000);
37-
trackerRegistry = coreAdminHandler.getTrackerRegistry();
38-
} catch (InterruptedException e) {
39-
logger.error("Fail to wait 10 sec", e);
40-
}
41-
}
28+
@Override
29+
protected void registerMetrics() {
30+
TrackerRegistry trackerRegistry = getTrackerRegistryWhenAvailable();
4231

4332
for (String coreName : trackerRegistry.getCoreNames()) {
44-
SolrInformationServer server = (SolrInformationServer) coreAdminHandler.getInformationServers()
45-
.get(coreName);
46-
4733
Tags tags = Tags.of("core", coreName, TAG_STATE, TAG_VALUE_INDEXED);
48-
Gauge.builder(METER_ALFRESCO_NODES, server,
49-
x -> getCoreStat(server, "Alfresco Nodes in Index"))
34+
Gauge.builder(METER_ALFRESCO_NODES, coreAdminHandler,
35+
x -> getCoreStat(x, coreName, "Alfresco Nodes in Index"))
5036
.tags(tags)
5137
.register(registry);
5238

5339
tags = Tags.of("core", coreName, TAG_STATE, "Unindexed");
54-
Gauge.builder(METER_ALFRESCO_NODES, server,
55-
x -> getCoreStat(server, "Alfresco Unindexed Nodes"))
40+
Gauge.builder(METER_ALFRESCO_NODES, coreAdminHandler,
41+
x -> getCoreStat(x, coreName, "Alfresco Unindexed Nodes"))
5642
.tags(tags)
5743
.register(registry);
5844

5945
tags = Tags.of("core", coreName, TAG_STATE, "Error");
60-
Gauge.builder(METER_ALFRESCO_NODES, trackerRegistry,
61-
x -> getCoreStat(server, "Alfresco Error Nodes in Index"))
46+
Gauge.builder(METER_ALFRESCO_NODES, coreAdminHandler,
47+
x -> getCoreStat(x, coreName, "Alfresco Error Nodes in Index"))
6248
.tags(tags)
6349
.register(registry);
6450

6551
tags = Tags.of("core", coreName, TAG_STATE, TAG_VALUE_INDEXED);
66-
Gauge.builder("alfresco.acls", trackerRegistry,
67-
x -> getCoreStat(server, "Alfresco Acls in Index"))
52+
Gauge.builder("alfresco.acls", coreAdminHandler,
53+
x -> getCoreStat(x, coreName, "Alfresco Acls in Index"))
6854
.tags(tags)
6955
.register(registry);
7056

7157
tags = Tags.of("core", coreName, TAG_STATE, "States");
72-
Gauge.builder("alfresco.states", trackerRegistry,
73-
x -> getCoreStat(server, "Alfresco States in Index"))
58+
Gauge.builder("alfresco.states", coreAdminHandler,
59+
x -> getCoreStat(x, coreName, "Alfresco States in Index"))
7460
.tags(tags)
7561
.register(registry);
7662

7763
// technically these metrics are not per core, but in order to filter in grafana the core is added as a tag
7864
tags = Tags.of("core", coreName, TAG_STATE, TAG_VALUE_INDEXED);
79-
Gauge.builder("alfresco.transactions.nodes", trackerRegistry,
80-
x -> getCoreStat(server, "Alfresco Transactions in Index"))
65+
Gauge.builder("alfresco.transactions.nodes", coreAdminHandler,
66+
x -> getCoreStat(x, coreName, "Alfresco Transactions in Index"))
8167
.tags(tags)
8268
.register(registry);
8369

8470
tags = Tags.of("core", coreName, TAG_STATE, TAG_VALUE_INDEXED);
85-
Gauge.builder("alfresco.transactions.acls", trackerRegistry,
86-
x -> getCoreStat(server, "Alfresco Acl Transactions in Index"))
71+
Gauge.builder("alfresco.transactions.acls", coreAdminHandler,
72+
x -> getCoreStat(x, coreName, "Alfresco Acl Transactions in Index"))
8773
.tags(tags)
8874
.register(registry);
8975

9076
}
9177
}
9278

9379

94-
private long getCoreStat(SolrInformationServer server, String key) {
80+
private static long getCoreStat(AlfrescoCoreAdminHandler coreAdminHandler, String coreName, String key) {
81+
SolrInformationServer server = (SolrInformationServer) coreAdminHandler.getInformationServers()
82+
.get(coreName);
9583
try {
9684
for (Entry<String, Object> entry : server.getCoreStats()) {
9785
if (key.equals(entry.getKey())) {
@@ -104,9 +92,4 @@ private long getCoreStat(SolrInformationServer server, String key) {
10492
return -1;
10593
}
10694

107-
@Override
108-
public void bindTo(MeterRegistry registry) {
109-
this.registry = registry;
110-
registerCoreStats();
111-
}
11295
}

0 commit comments

Comments
 (0)