Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fireflyframework-rule-engine-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.fireflyframework</groupId>
<artifactId>fireflyframework-rule-engine</artifactId>
<version>26.04.01</version>
<version>26.05.06</version>
</parent>

<artifactId>fireflyframework-rule-engine-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2024-2026 Firefly Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.fireflyframework.rules.core.observability;

import io.micrometer.core.instrument.MeterRegistry;
import org.fireflyframework.observability.metrics.FireflyMetricsSupport;
import reactor.core.publisher.Mono;

/**
* Observability instrumentation for the Firefly rule engine.
* <p>
* Records:
* <ul>
* <li>{@code firefly.ruleengine.evaluations} — total rule evaluations, tagged
* by {@code rule.id} and {@code result} (matched/unmatched/error)</li>
* <li>{@code firefly.ruleengine.evaluation.duration} — timer of evaluation latency,
* tagged by {@code rule.id}</li>
* <li>{@code firefly.ruleengine.conditions.matched} — counter of matched conditions,
* tagged by {@code rule.id}, {@code condition.id}</li>
* <li>{@code firefly.ruleengine.compilations} — counter of YAML→AST compilations,
* tagged by {@code status} (success/failure)</li>
* <li>{@code firefly.ruleengine.errors} — counter of evaluation errors,
* tagged by {@code rule.id}, {@code error.type}</li>
* </ul>
*/
public class RuleEngineMetrics extends FireflyMetricsSupport {

private static final String TAG_RULE_ID = "rule.id";
private static final String TAG_CONDITION_ID = "condition.id";
private static final String TAG_RESULT = "result";

public RuleEngineMetrics(MeterRegistry meterRegistry) {
super(meterRegistry, "ruleengine");
}

public <T> Mono<T> timedEvaluation(String ruleId, Mono<T> evaluation) {
return timed("evaluation.duration", evaluation, TAG_RULE_ID, ruleId)
.doOnSuccess(v -> counter("evaluations",
TAG_RULE_ID, ruleId, TAG_RESULT, "matched").increment())
.doOnError(e -> {
counter("evaluations", TAG_RULE_ID, ruleId, TAG_RESULT, "error").increment();
recordFailure("errors", e, TAG_RULE_ID, ruleId);
});
}

public void recordUnmatched(String ruleId) {
counter("evaluations", TAG_RULE_ID, ruleId, TAG_RESULT, "unmatched").increment();
}

public void recordConditionMatched(String ruleId, String conditionId) {
counter("conditions.matched", TAG_RULE_ID, ruleId, TAG_CONDITION_ID, conditionId).increment();
}

public void recordCompilation(boolean success) {
counter("compilations", "status", success ? "success" : "failure").increment();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024-2026 Firefly Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.fireflyframework.rules.core.observability;

import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
* Auto-configures {@link RuleEngineMetrics} as a Spring bean.
*/
@AutoConfiguration
@ConditionalOnClass(MeterRegistry.class)
@ConditionalOnProperty(prefix = "firefly.observability.metrics", name = "enabled",
havingValue = "true", matchIfMissing = true)
public class RuleEngineObservabilityAutoConfiguration {

@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(MeterRegistry.class)
RuleEngineMetrics ruleEngineMetrics(MeterRegistry meterRegistry) {
return new RuleEngineMetrics(meterRegistry);
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.fireflyframework.rules.core.config.RuleEngineCacheAutoConfiguration
org.fireflyframework.rules.core.observability.RuleEngineObservabilityAutoConfiguration
2 changes: 1 addition & 1 deletion fireflyframework-rule-engine-interfaces/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.fireflyframework</groupId>
<artifactId>fireflyframework-rule-engine</artifactId>
<version>26.04.01</version>
<version>26.05.06</version>
</parent>

<artifactId>fireflyframework-rule-engine-interfaces</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion fireflyframework-rule-engine-models/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.fireflyframework</groupId>
<artifactId>fireflyframework-rule-engine</artifactId>
<version>26.04.01</version>
<version>26.05.06</version>
</parent>

<artifactId>fireflyframework-rule-engine-models</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion fireflyframework-rule-engine-sdk/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.fireflyframework</groupId>
<artifactId>fireflyframework-rule-engine</artifactId>
<version>26.04.01</version>
<version>26.05.06</version>
</parent>

<artifactId>fireflyframework-rule-engine-sdk</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion fireflyframework-rule-engine-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.fireflyframework</groupId>
<artifactId>fireflyframework-rule-engine</artifactId>
<version>26.04.01</version>
<version>26.05.06</version>
</parent>

<artifactId>fireflyframework-rule-engine-web</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
<parent>
<groupId>org.fireflyframework</groupId>
<artifactId>fireflyframework-parent</artifactId>
<version>26.04.01</version>
<version>26.05.06</version>
<relativePath/>
</parent>

<groupId>org.fireflyframework</groupId>
<artifactId>fireflyframework-rule-engine</artifactId>
<version>26.04.01</version>
<version>26.05.06</version>
<packaging>pom</packaging>

<name>Firefly Framework - Rule Engine Library</name>
Expand Down
Loading