Skip to content

Commit

Permalink
[metering] Fix dependency issue in io.monitor bundle (openhab#2288) (o…
Browse files Browse the repository at this point in the history
…penhab#2289)

Signed-off-by: Robert Bach <[email protected]>
GitOrigin-RevId: da05f8e
  • Loading branch information
pravussum authored and splatch committed Jul 11, 2023
1 parent 96f6b3e commit 095091e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
18 changes: 18 additions & 0 deletions bundles/org.opensmarthouse.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 095091e

Please sign in to comment.