Fix wrong metrics count for Dataset Template

This commit is contained in:
George Kalampokis 2022-01-27 11:05:40 +02:00
parent 01d32427c3
commit 70d37cead1
3 changed files with 8 additions and 3 deletions

View File

@ -73,7 +73,8 @@ public class Admin extends BaseController {
userDatasetProfile.setRole(0);
getApiContext().getOperationsContext().getDatabaseRepository().getUserDatasetProfileDao().createOrUpdate(userDatasetProfile);
datasetProfileManager.storeDatasetProfileUsers(datasetProfile, profile);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.TOTAL);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricsManager.datasetTemplateStatus.get(datasetProfile.getStatus()) );
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
}

View File

@ -97,7 +97,6 @@ public class DatasetProfileManager {
DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile);
profile.setId(null);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.TOTAL);
return profile;
}
@ -253,7 +252,7 @@ public class DatasetProfileManager {
File localFile = convert(multiPartFile);
eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile profile = xmlBuilder.build(localFile);
Files.deleteIfExists(localFile.toPath());
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.TOTAL);
metricsManager.increaseValue(MetricNames.DATASET_TEMPLATE, 1, MetricNames.DRAFT);
return profile;
} catch (IOException e) {
logger.error(e.getMessage(), e);

View File

@ -32,6 +32,11 @@ public class MetricsManager {
private final static Logger logger = LoggerFactory.getLogger(MetricsManager.class);
private final Map<String, Gauge> gauges;
public static final Map<Short, String> datasetTemplateStatus = Stream.of(new Object[][] {
{ DatasetProfile.Status.SAVED.getValue(), MetricNames.DRAFT },
{ DatasetProfile.Status.FINALIZED.getValue(), MetricNames.ACTIVE },
}).collect(Collectors.toMap(data -> (Short) data[0], data -> (String) data[1]));
public void increaseValue(String name, int amount, String label) {
if(label != null) {