diff --git a/fireflyframework-rule-engine-core/pom.xml b/fireflyframework-rule-engine-core/pom.xml index 4697e8b..a5af6d9 100644 --- a/fireflyframework-rule-engine-core/pom.xml +++ b/fireflyframework-rule-engine-core/pom.xml @@ -6,7 +6,7 @@ org.fireflyframework fireflyframework-rule-engine - 26.04.01 + 26.05.06 fireflyframework-rule-engine-core diff --git a/fireflyframework-rule-engine-core/src/main/java/org/fireflyframework/rules/core/observability/RuleEngineMetrics.java b/fireflyframework-rule-engine-core/src/main/java/org/fireflyframework/rules/core/observability/RuleEngineMetrics.java new file mode 100644 index 0000000..89855c0 --- /dev/null +++ b/fireflyframework-rule-engine-core/src/main/java/org/fireflyframework/rules/core/observability/RuleEngineMetrics.java @@ -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. + *

+ * Records: + *

+ */ +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 Mono timedEvaluation(String ruleId, Mono 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(); + } +} diff --git a/fireflyframework-rule-engine-core/src/main/java/org/fireflyframework/rules/core/observability/RuleEngineObservabilityAutoConfiguration.java b/fireflyframework-rule-engine-core/src/main/java/org/fireflyframework/rules/core/observability/RuleEngineObservabilityAutoConfiguration.java new file mode 100644 index 0000000..e2c18f1 --- /dev/null +++ b/fireflyframework-rule-engine-core/src/main/java/org/fireflyframework/rules/core/observability/RuleEngineObservabilityAutoConfiguration.java @@ -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); + } +} diff --git a/fireflyframework-rule-engine-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/fireflyframework-rule-engine-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 517593c..4da25cc 100644 --- a/fireflyframework-rule-engine-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/fireflyframework-rule-engine-core/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1,2 @@ org.fireflyframework.rules.core.config.RuleEngineCacheAutoConfiguration +org.fireflyframework.rules.core.observability.RuleEngineObservabilityAutoConfiguration diff --git a/fireflyframework-rule-engine-interfaces/pom.xml b/fireflyframework-rule-engine-interfaces/pom.xml index e544cab..1706b9f 100644 --- a/fireflyframework-rule-engine-interfaces/pom.xml +++ b/fireflyframework-rule-engine-interfaces/pom.xml @@ -6,7 +6,7 @@ org.fireflyframework fireflyframework-rule-engine - 26.04.01 + 26.05.06 fireflyframework-rule-engine-interfaces diff --git a/fireflyframework-rule-engine-models/pom.xml b/fireflyframework-rule-engine-models/pom.xml index 8354fc6..587af91 100644 --- a/fireflyframework-rule-engine-models/pom.xml +++ b/fireflyframework-rule-engine-models/pom.xml @@ -6,7 +6,7 @@ org.fireflyframework fireflyframework-rule-engine - 26.04.01 + 26.05.06 fireflyframework-rule-engine-models diff --git a/fireflyframework-rule-engine-sdk/pom.xml b/fireflyframework-rule-engine-sdk/pom.xml index aa0d202..0e0a5b9 100644 --- a/fireflyframework-rule-engine-sdk/pom.xml +++ b/fireflyframework-rule-engine-sdk/pom.xml @@ -6,7 +6,7 @@ org.fireflyframework fireflyframework-rule-engine - 26.04.01 + 26.05.06 fireflyframework-rule-engine-sdk diff --git a/fireflyframework-rule-engine-web/pom.xml b/fireflyframework-rule-engine-web/pom.xml index 3e5b003..9af6f59 100644 --- a/fireflyframework-rule-engine-web/pom.xml +++ b/fireflyframework-rule-engine-web/pom.xml @@ -6,7 +6,7 @@ org.fireflyframework fireflyframework-rule-engine - 26.04.01 + 26.05.06 fireflyframework-rule-engine-web diff --git a/pom.xml b/pom.xml index cbd1e11..02db30c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,13 @@ org.fireflyframework fireflyframework-parent - 26.04.01 + 26.05.06 org.fireflyframework fireflyframework-rule-engine - 26.04.01 + 26.05.06 pom Firefly Framework - Rule Engine Library