-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alfredops 715 fix ass 2.0.0 #74
Changes from all commits
1fb0412
57e3259
c6bf694
a923c7c
3574922
1043aa8
9c5933f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package eu.xenit.alfred.telemetry.solr.monitoring.binder; | ||
|
||
import eu.xenit.alfred.telemetry.solr.util.Util; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
import org.alfresco.solr.AlfrescoCoreAdminHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.management.MBeanServer; | ||
|
||
public class SolrMetrics implements MeterBinder { | ||
|
||
AlfrescoCoreAdminHandler coreAdminHandler; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? It is used outside package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any package-usages ? 🤷 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used by eu.xenit.alfred.telemetry.solr.monitoring.handler.MicrometerHandler, outside the package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will merge now and come back to this later if needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If used elsewhere, please create and use an accessor. |
||
MBeanServer mBeanServer; | ||
|
||
Logger logger = LoggerFactory.getLogger(SolrMetrics.class); | ||
|
||
public SolrMetrics(AlfrescoCoreAdminHandler coreAdminHandler, MBeanServer mBeanServer) { | ||
this.coreAdminHandler = coreAdminHandler; | ||
this.mBeanServer = mBeanServer; | ||
} | ||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
if(Util.isEnabled("METRICS_SOLR_CORESTATS_ENABLED")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use braces in https://google.github.io/styleguide/javaguide.html#s4.1.1-braces-always-used |
||
new SolrCoreStatsMetrics(coreAdminHandler).bindTo(registry); | ||
if(Util.isEnabled("METRICS_SOLR_FTS_ENABLED")) | ||
new SolrFTSMetrics(coreAdminHandler).bindTo(registry); | ||
if(Util.isEnabled("METRICS_SOLR_TRACKER_ENABLED")) | ||
new SolrTrackerMetrics(coreAdminHandler).bindTo(registry); | ||
if(Util.isEnabled("METRICS_SOLR_JMX_ENABLED")) | ||
new SolrBeansMetrics(mBeanServer).bindTo(registry); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
ext { | ||
solrVersion = '6.6.5' | ||
assVersion = '1.4.0' | ||
solrBaseImage = 'docker.io/xenit/alfresco-solr6:1.4.0' | ||
//assVersion = '1.4.0' | ||
//solrBaseImage = 'hub.xenit.eu/alfresco-enterprise/alfresco-solr6:1.4.0' | ||
assVersion = '2.0.0' | ||
solrBaseImage = 'hub.xenit.eu/alfresco-enterprise/alfresco-solr6:2.0.0' | ||
solrFlavor = 'solr6' | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package eu.xenit.alfred.telemetry.solr.monitoring.binder; | ||
|
||
import eu.xenit.alfred.telemetry.solr.util.Util; | ||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tags; | ||
import io.micrometer.core.instrument.binder.MeterBinder; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.Map.Entry; | ||
import java.util.Set; | ||
import org.alfresco.solr.AlfrescoCoreAdminHandler; | ||
import org.alfresco.solr.tracker.TrackerRegistry; | ||
import org.apache.solr.common.util.NamedList; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SolrFTSMetrics implements MeterBinder { | ||
|
||
AlfrescoCoreAdminHandler coreAdminHandler; | ||
MeterRegistry registry; | ||
|
||
Logger logger = LoggerFactory.getLogger(SolrFTSMetrics.class); | ||
|
||
public SolrFTSMetrics(AlfrescoCoreAdminHandler coreAdminHandler) { | ||
this.coreAdminHandler = coreAdminHandler; | ||
} | ||
|
||
private void registerFTSMetrics() { | ||
logger.info("Registering FTS metrics"); | ||
TrackerRegistry trackerRegistry = coreAdminHandler.getTrackerRegistry(); | ||
|
||
while (trackerRegistry.getCoreNames().size() == 0) { | ||
logger.error("Solr did not start tracking yet, waiting 10sec"); | ||
try { | ||
Thread.currentThread().sleep(10_000); | ||
trackerRegistry = coreAdminHandler.getTrackerRegistry(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a logger to log catched exceptions. |
||
} | ||
} | ||
|
||
Set<String> coreNames = coreAdminHandler.getTrackerRegistry().getCoreNames(); | ||
for (String coreName : coreNames) { | ||
Object server = coreAdminHandler.getInformationServers().get(coreName); | ||
NamedList<Object> report = new NamedList(); | ||
Method method = null; | ||
try { | ||
Class<?> solrInformationServerClass = Class.forName("org.alfresco.solr.SolrInformationServer"); | ||
Class<?>[] partypes = new Class[]{NamedList.class}; | ||
if(Util.isVersionLowerThan2()) { | ||
method = solrInformationServerClass.getMethod("addFTSStatusCounts", partypes); | ||
} else { | ||
method = solrInformationServerClass.getMethod("addContentOutdatedAndUpdatedCounts", partypes); | ||
} | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
Object[] arglist = new Object[1]; | ||
arglist[0] = report; | ||
try { | ||
method.invoke(server, arglist); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
// Keys in ASS >= 2.0.0 | ||
Tags tags = Tags.of("core", coreName, "state", "InSync"); | ||
Gauge.builder("alfresco.fts", server, x -> getValueFromReport(server, "Node count whose content is in sync")) | ||
.tags(tags) | ||
.register(registry); | ||
|
||
tags = Tags.of("core", coreName, "state", "ToBeUpdated"); | ||
Gauge.builder("alfresco.fts", server, x -> getValueFromReport(server, "Node count whose content needs to be updated")) | ||
.tags(tags) | ||
.register(registry); | ||
|
||
// Keys in ASS < 2.0.0 | ||
tags = Tags.of("core", coreName, "state", "Clean"); | ||
Gauge.builder("alfresco.fts", server, x -> getValueFromReport(server, "Node count with FTSStatus Clean")) | ||
.tags(tags) | ||
.register(registry); | ||
|
||
tags = Tags.of("core", coreName, "state", "Dirty"); | ||
Gauge.builder("alfresco.fts", server, x -> getValueFromReport(server, "Node count with FTSStatus Dirty")) | ||
.tags(tags) | ||
.register(registry); | ||
|
||
tags = Tags.of("core", coreName, "state", "New"); | ||
Gauge.builder("alfresco.fts", server, x -> getValueFromReport(server, "Node count with FTSStatus New")) | ||
.tags(tags) | ||
.register(registry); | ||
|
||
} | ||
} | ||
|
||
private long getValueFromReport(Object server, String key) { | ||
NamedList<Object> report = new NamedList(); | ||
Method method = null; | ||
try { | ||
Class<?> solrInformationServerClass = Class.forName("org.alfresco.solr.SolrInformationServer"); | ||
Class<?>[] partypes = new Class[]{NamedList.class}; | ||
if(Util.isVersionLowerThan2()) { | ||
method = solrInformationServerClass.getMethod("addFTSStatusCounts", partypes); | ||
} else { | ||
method = solrInformationServerClass.getMethod("addContentOutdatedAndUpdatedCounts", partypes); | ||
} | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} catch (NoSuchMethodException e) { | ||
e.printStackTrace(); | ||
} | ||
Object[] arglist = new Object[1]; | ||
arglist[0] = report; | ||
try { | ||
method.invoke(server, arglist); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
for (Entry fts : report) { | ||
if (fts.getKey().equals(key)) { | ||
return Long.parseLong(fts.getValue().toString()); | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
|
||
@Override | ||
public void bindTo(MeterRegistry registry) { | ||
this.registry = registry; | ||
registerFTSMetrics(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger should be at least
private
, preferably alsostatic final
private
- so that no other class can hijack your loggerstatic
- so there is only one logger instance per class, also avoiding attempts to serialize loggersfinal
- no need to change the logger over the lifetime of the classhttps://stackoverflow.com/a/6653577