Pull request #523: RED-6250
Merge in RED/redaction-service from RED-6250 to master * commit 'fe5121b1edf784d5cc57abd9cd8e27f70dea0f4a': RED-6250: Switched to new metrics-commons version to not have to instantiate a factory (reduces code duplication) RED-6250: Changed function-timer metric to use code from metric commons
This commit is contained in:
commit
4b42c8d13f
@ -93,6 +93,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.iqser.red.commons</groupId>
|
<groupId>com.iqser.red.commons</groupId>
|
||||||
<artifactId>metric-commons</artifactId>
|
<artifactId>metric-commons</artifactId>
|
||||||
|
<version>1.7.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- other external -->
|
<!-- other external -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import com.iqser.red.commons.spring.DefaultWebMvcConfiguration;
|
|
||||||
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
||||||
import com.iqser.red.service.redaction.v1.server.multitenancy.AsyncConfig;
|
import com.iqser.red.service.redaction.v1.server.multitenancy.AsyncConfig;
|
||||||
import com.iqser.red.service.redaction.v1.server.multitenancy.MultiTenancyMessagingConfiguration;
|
import com.iqser.red.service.redaction.v1.server.multitenancy.MultiTenancyMessagingConfiguration;
|
||||||
@ -19,7 +18,7 @@ import com.iqser.red.service.redaction.v1.server.settings.RedactionServiceSettin
|
|||||||
import io.micrometer.core.aop.TimedAspect;
|
import io.micrometer.core.aop.TimedAspect;
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
import io.micrometer.core.instrument.MeterRegistry;
|
||||||
|
|
||||||
@Import({MultiTenancyWebConfiguration.class, AsyncConfig.class, MultiTenancyMessagingConfiguration.class})
|
@Import({MultiTenancyWebConfiguration.class, AsyncConfig.class, MultiTenancyMessagingConfiguration.class, MetricsConfiguration.class})
|
||||||
@EnableFeignClients(basePackageClasses = RulesClient.class)
|
@EnableFeignClients(basePackageClasses = RulesClient.class)
|
||||||
@EnableConfigurationProperties(RedactionServiceSettings.class)
|
@EnableConfigurationProperties(RedactionServiceSettings.class)
|
||||||
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class})
|
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class})
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
package com.iqser.red.service.redaction.v1.server;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import com.iqser.gin4.commons.metrics.MetricCommonsConfiguration;
|
||||||
|
import com.iqser.gin4.commons.metrics.meters.FunctionTimerFactory;
|
||||||
|
import com.iqser.gin4.commons.metrics.meters.FunctionTimerValues;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({MetricCommonsConfiguration.class})
|
||||||
|
public class MetricsConfiguration {
|
||||||
|
|
||||||
|
private static final String REDACTMANAGER_ANALYZE_PAGEWISE_METRIC_NAME = "redactmanager_analyze.pagewise";
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@Qualifier(REDACTMANAGER_ANALYZE_PAGEWISE_METRIC_NAME)
|
||||||
|
public FunctionTimerValues redactmanagerAnalyzePagewise(FunctionTimerFactory factory) {
|
||||||
|
|
||||||
|
return factory.create(REDACTMANAGER_ANALYZE_PAGEWISE_METRIC_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -8,13 +8,13 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.kie.api.runtime.KieContainer;
|
import org.kie.api.runtime.KieContainer;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
import com.iqser.gin4.commons.metrics.meters.FunctionTimerValues;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.AnalyzeRequest;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.AnalyzeRequest;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.AnalyzeResult;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.AnalyzeResult;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileAttribute;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileAttribute;
|
||||||
@ -53,10 +53,8 @@ import com.iqser.red.service.redaction.v1.server.settings.RedactionServiceSettin
|
|||||||
import com.iqser.red.service.redaction.v1.server.storage.RedactionStorageService;
|
import com.iqser.red.service.redaction.v1.server.storage.RedactionStorageService;
|
||||||
|
|
||||||
import io.micrometer.core.annotation.Timed;
|
import io.micrometer.core.annotation.Timed;
|
||||||
import io.micrometer.core.instrument.FunctionTimer;
|
|
||||||
import io.micrometer.core.instrument.MeterRegistry;
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.experimental.FieldDefaults;
|
import lombok.experimental.FieldDefaults;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -64,8 +62,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class AnalyzeService {
|
public class AnalyzeService {
|
||||||
|
|
||||||
|
private static final String REDACTMANAGER_ANALYZE_PAGEWISE_METRIC_NAME = "redactmanager_analyze.pagewise";
|
||||||
|
|
||||||
DictionaryService dictionaryService;
|
DictionaryService dictionaryService;
|
||||||
DroolsExecutionService droolsExecutionService;
|
DroolsExecutionService droolsExecutionService;
|
||||||
EntityRedactionService entityRedactionService;
|
EntityRedactionService entityRedactionService;
|
||||||
@ -80,50 +81,8 @@ public class AnalyzeService {
|
|||||||
ImageService imageService;
|
ImageService imageService;
|
||||||
ImportedRedactionService importedRedactionService;
|
ImportedRedactionService importedRedactionService;
|
||||||
SectionFinder sectionFinder;
|
SectionFinder sectionFinder;
|
||||||
PagewiseCounter analyzeCounter = new PagewiseCounter();
|
|
||||||
|
|
||||||
|
FunctionTimerValues redactmanagerAnalyzePagewiseValues;
|
||||||
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
|
|
||||||
public AnalyzeService(DictionaryService dictionaryService,
|
|
||||||
DroolsExecutionService droolsExecutionService,
|
|
||||||
EntityRedactionService entityRedactionService,
|
|
||||||
RedactionLogCreatorService redactionLogCreatorService,
|
|
||||||
RedactionStorageService redactionStorageService,
|
|
||||||
PdfSegmentationService pdfSegmentationService,
|
|
||||||
RedactionChangeLogService redactionChangeLogService,
|
|
||||||
LegalBasisClient legalBasisClient,
|
|
||||||
RedactionServiceSettings redactionServiceSettings,
|
|
||||||
SectionTextBuilderService sectionTextBuilderService,
|
|
||||||
SectionGridCreatorService sectionGridCreatorService,
|
|
||||||
ImageService imageService,
|
|
||||||
ImportedRedactionService importedRedactionService,
|
|
||||||
SectionFinder sectionFinder,
|
|
||||||
MeterRegistry meterRegistry) {
|
|
||||||
|
|
||||||
this.dictionaryService = dictionaryService;
|
|
||||||
this.droolsExecutionService = droolsExecutionService;
|
|
||||||
this.entityRedactionService = entityRedactionService;
|
|
||||||
this.redactionLogCreatorService = redactionLogCreatorService;
|
|
||||||
this.redactionStorageService = redactionStorageService;
|
|
||||||
this.pdfSegmentationService = pdfSegmentationService;
|
|
||||||
this.redactionChangeLogService = redactionChangeLogService;
|
|
||||||
this.legalBasisClient = legalBasisClient;
|
|
||||||
this.redactionServiceSettings = redactionServiceSettings;
|
|
||||||
this.sectionTextBuilderService = sectionTextBuilderService;
|
|
||||||
this.sectionGridCreatorService = sectionGridCreatorService;
|
|
||||||
this.imageService = imageService;
|
|
||||||
this.importedRedactionService = importedRedactionService;
|
|
||||||
this.sectionFinder = sectionFinder;
|
|
||||||
|
|
||||||
// This is just here as an example of how to do a timer with a counter.
|
|
||||||
// For a full implementation this should be moved to a common helper class.
|
|
||||||
FunctionTimer.builder("redactmanager_analyze.pagewise", //
|
|
||||||
analyzeCounter, //
|
|
||||||
PagewiseCounter::getTotalPageCount, //
|
|
||||||
PagewiseCounter::getTotalTimeMillis, //
|
|
||||||
TimeUnit.MILLISECONDS) //
|
|
||||||
.register(meterRegistry);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Timed("redactmanager_analyzeDocumentStructure")
|
@Timed("redactmanager_analyzeDocumentStructure")
|
||||||
@ -296,7 +255,7 @@ public class AnalyzeService {
|
|||||||
|
|
||||||
long duration = System.currentTimeMillis() - startTime;
|
long duration = System.currentTimeMillis() - startTime;
|
||||||
|
|
||||||
analyzeCounter.increase(text.getNumberOfPages(), duration);
|
redactmanagerAnalyzePagewiseValues.increase(text.getNumberOfPages(), duration);
|
||||||
|
|
||||||
return AnalyzeResult.builder()
|
return AnalyzeResult.builder()
|
||||||
.dossierId(analyzeRequest.getDossierId())
|
.dossierId(analyzeRequest.getDossierId())
|
||||||
@ -347,21 +306,4 @@ public class AnalyzeService {
|
|||||||
return SimplifiedText.builder().numberOfPages(numberOfPages).sectionTexts(sectionTexts).build();
|
return SimplifiedText.builder().numberOfPages(numberOfPages).sectionTexts(sectionTexts).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@FieldDefaults(level = AccessLevel.PRIVATE)
|
|
||||||
@Getter
|
|
||||||
private static final class PagewiseCounter {
|
|
||||||
|
|
||||||
long totalPageCount;
|
|
||||||
long totalTimeMillis;
|
|
||||||
|
|
||||||
|
|
||||||
public void increase(long pageCount, long durationMillis) {
|
|
||||||
|
|
||||||
totalPageCount += pageCount;
|
|
||||||
totalTimeMillis += durationMillis;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user