diff --git a/pom.xml b/pom.xml index f38afb1..89a266e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,12 +7,12 @@ org.fireflyframework fireflyframework-parent - 26.04.01 + 26.05.06 fireflyframework-ecm - 26.04.01 + 26.05.06 jar Firefly Framework - Enterprise Content Management Library diff --git a/src/main/java/org/fireflyframework/ecm/observability/EcmMetrics.java b/src/main/java/org/fireflyframework/ecm/observability/EcmMetrics.java new file mode 100644 index 0000000..63531a9 --- /dev/null +++ b/src/main/java/org/fireflyframework/ecm/observability/EcmMetrics.java @@ -0,0 +1,72 @@ +/* + * 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.ecm.observability; + +import io.micrometer.core.instrument.MeterRegistry; +import org.fireflyframework.observability.metrics.FireflyMetricsSupport; +import reactor.core.publisher.Mono; + +/** + * Shared observability instrumentation for the ECM module and all its adapters + * (storage: S3/Azure Blob/local; e-signature: DocuSign/Adobe Sign/Logalty). + *

+ * Records: + *

+ */ +public class EcmMetrics extends FireflyMetricsSupport { + + private static final String TAG_OPERATION = "operation"; + private static final String TAG_PROVIDER = "provider"; + private static final String TAG_DIRECTION = "direction"; + + public EcmMetrics(MeterRegistry meterRegistry) { + super(meterRegistry, "ecm"); + } + + /** + * Wraps a document-storage or e-signature operation with a timer and success/failure counters. + */ + public Mono timedOperation(String operation, String provider, Mono op) { + return timed("operation.duration", op, TAG_OPERATION, operation, TAG_PROVIDER, provider) + .doOnSuccess(v -> recordSuccess("documents.operations", + TAG_OPERATION, operation, TAG_PROVIDER, provider)) + .doOnError(e -> { + recordFailure("documents.operations", e, + TAG_OPERATION, operation, TAG_PROVIDER, provider); + recordFailure("errors", e, + TAG_OPERATION, operation, TAG_PROVIDER, provider); + }); + } + + public void recordBytesTransferred(String direction, String provider, long bytes) { + distributionSummary("bytes.transferred", TAG_DIRECTION, direction, TAG_PROVIDER, provider) + .record(bytes); + } + + public void recordSignatureCompleted(String provider) { + counter("signatures.completed", TAG_PROVIDER, provider).increment(); + } +} diff --git a/src/main/java/org/fireflyframework/ecm/observability/EcmObservabilityAutoConfiguration.java b/src/main/java/org/fireflyframework/ecm/observability/EcmObservabilityAutoConfiguration.java new file mode 100644 index 0000000..aa5044a --- /dev/null +++ b/src/main/java/org/fireflyframework/ecm/observability/EcmObservabilityAutoConfiguration.java @@ -0,0 +1,43 @@ +/* + * 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.ecm.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 EcmMetrics} for all ECM adapter implementations + * (storage and e-signature providers). + */ +@AutoConfiguration +@ConditionalOnClass(MeterRegistry.class) +@ConditionalOnProperty(prefix = "firefly.observability.metrics", name = "enabled", + havingValue = "true", matchIfMissing = true) +public class EcmObservabilityAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(MeterRegistry.class) + EcmMetrics ecmMetrics(MeterRegistry meterRegistry) { + return new EcmMetrics(meterRegistry); + } +} diff --git a/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 3014da2..121fe14 100644 --- a/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1 +1,2 @@ org.fireflyframework.ecm.config.EcmAutoConfiguration +org.fireflyframework.ecm.observability.EcmObservabilityAutoConfiguration