Skip to content

Commit

Permalink
[metering] Fix dependency issue in io.monitor bundle (#2288) (#2289)
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Bach <[email protected]>
  • Loading branch information
pravussum authored Apr 28, 2021
1 parent cb36eb5 commit da05f8e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
4 changes: 3 additions & 1 deletion bundles/org.openhab.core.io.monitor/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ Import-Package: \
org.osgi.service.*,\
org.slf4j.*,\
com.google.gson.*;version="[2.8,3)"
Export-Package: io.micrometer.core.*
Export-Package: io.micrometer.core.*;-split-package:=merge-first,\
org.HdrHistogram.*;-split-package:=merge-first,\
org.LatencyUtils.*;-split-package:=merge-first
18 changes: 18 additions & 0 deletions bundles/org.openhab.core.io.monitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@
<version>1.6.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.1.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.latencyutils</groupId>
<artifactId>LatencyUtils</artifactId>
<version>2.0.3</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public RuleMetric(BundleContext bundleContext, Collection<Tag> tags, RuleRegistr
}

@Override
public void bindTo(@io.micrometer.core.lang.NonNull MeterRegistry meterRegistry) {
public void bindTo(MeterRegistry meterRegistry) {
unbind();
logger.debug("RuleMetric is being bound...");
this.meterRegistry = meterRegistry;
Expand All @@ -77,18 +77,20 @@ public void bindTo(@io.micrometer.core.lang.NonNull MeterRegistry meterRegistry)

@Override
public void unbind() {
if (meterRegistry == null) {
MeterRegistry mReg = meterRegistry;
if (mReg == null) {
return;
}
for (Meter meter : meterRegistry.getMeters()) {
if (meter.getId().getTags().contains(CORE_RULE_METRIC_TAG)) {
meterRegistry.remove(meter);
} else {
for (Meter meter : mReg.getMeters()) {
if (meter.getId().getTags().contains(CORE_RULE_METRIC_TAG)) {
mReg.remove(meter);
}
}
meterRegistry = null;
if (this.eventSubscriberRegistration != null) {
this.eventSubscriberRegistration.unregister();
this.eventSubscriberRegistration = null;
}
}
meterRegistry = null;
if (this.eventSubscriberRegistration != null) {
this.eventSubscriberRegistration.unregister();
this.eventSubscriberRegistration = null;
}
}

Expand All @@ -106,25 +108,27 @@ public Set<String> getSubscribedEventTypes() {

@Override
public void receive(Event event) {
if (meterRegistry == null) {
MeterRegistry mReg = meterRegistry;
if (mReg == null) {
logger.trace("Measurement not started. Skipping rule event processing");
return;
}
String topic = event.getTopic();
String ruleId = topic.substring(RULES_TOPIC_PREFIX.length(), topic.indexOf(RULES_TOPIC_SUFFIX));
if (!event.getPayload().contains(RuleStatus.RUNNING.name())) {
logger.trace("Skipping rule status info with status other than RUNNING {}", event.getPayload());
return;
}
} else {
String topic = event.getTopic();
String ruleId = topic.substring(RULES_TOPIC_PREFIX.length(), topic.indexOf(RULES_TOPIC_SUFFIX));
if (!event.getPayload().contains(RuleStatus.RUNNING.name())) {
logger.trace("Skipping rule status info with status other than RUNNING {}", event.getPayload());
return;
}

logger.debug("Rule {} RUNNING - updating metric.", ruleId);
Set<Tag> tagsWithRule = new HashSet<>(tags);
tagsWithRule.add(Tag.of(RULE_ID_TAG_NAME, ruleId));
String ruleName = getRuleName(ruleId);
if (ruleName != null) {
tagsWithRule.add(Tag.of(RULE_NAME_TAG_NAME, ruleName));
logger.debug("Rule {} RUNNING - updating metric.", ruleId);
Set<Tag> tagsWithRule = new HashSet<>(tags);
tagsWithRule.add(Tag.of(RULE_ID_TAG_NAME, ruleId));
String ruleName = getRuleName(ruleId);
if (ruleName != null) {
tagsWithRule.add(Tag.of(RULE_NAME_TAG_NAME, ruleName));
}
mReg.counter(METRIC_NAME, tagsWithRule).increment();
}
meterRegistry.counter(METRIC_NAME, tagsWithRule).increment();
}

private String getRuleName(String ruleId) {
Expand Down

0 comments on commit da05f8e

Please sign in to comment.