Skip to content

Commit

Permalink
SOLR-15081: Metrics for core: isLeader, replicaState
Browse files Browse the repository at this point in the history
Note that getLastPublished returns an Enum type.  TextWriter.writeVal should probably support Enums, which would simplify.
  • Loading branch information
dsmiley committed Jan 19, 2021
1 parent 5328ced commit 5d1afe0
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions solr/core/src/java/org/apache/solr/core/SolrCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -1203,26 +1203,19 @@ public void initializeMetrics(SolrMetricsContext parentContext, String scope) {
parentContext.gauge(() -> isClosed() ? parentContext.nullString() : getIndexDir(), true, "indexDir", Category.CORE.toString());
parentContext.gauge(() -> isClosed() ? parentContext.nullNumber() : getIndexSize(), true, "sizeInBytes", Category.INDEX.toString());
parentContext.gauge(() -> isClosed() ? parentContext.nullString() : NumberUtils.readableSize(getIndexSize()), true, "size", Category.INDEX.toString());
if (coreContainer != null) {
final CloudDescriptor cd = getCoreDescriptor().getCloudDescriptor();
if (cd != null) {
parentContext.gauge(() -> {
if (cd.getCollectionName() != null) {
return cd.getCollectionName();
} else {
return parentContext.nullString();
}
}, true, "collection", Category.CORE.toString());

parentContext.gauge(() -> {
if (cd.getShardId() != null) {
return cd.getShardId();
} else {
return parentContext.nullString();
}
}, true, "shard", Category.CORE.toString());
}
final CloudDescriptor cd = getCoreDescriptor().getCloudDescriptor();
if (cd != null) {
parentContext.gauge(cd::getCollectionName, true, "collection", Category.CORE.toString());
parentContext.gauge(cd::getShardId, true, "shard", Category.CORE.toString());
parentContext.gauge(cd::isLeader, true, "isLeader", Category.CORE.toString());
parentContext.gauge(
() -> String.valueOf(cd.getLastPublished()),
true,
"replicaState",
Category.CORE.toString());
}

// initialize disk total / free metrics
Path dataDirPath = Paths.get(dataDir);
File dataDirFile = dataDirPath.toFile();
Expand Down

0 comments on commit 5d1afe0

Please sign in to comment.