Skip to content

Commit

Permalink
fix: fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Nov 29, 2024
1 parent e636884 commit 4260001
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -282,6 +283,16 @@ public void uploadObject(String location, InputStream file, ValidationSecretsApp
throw new ProcessorContentUploadFailureException(e.getMessage());
}

Integer fileSize;

try {
fileSize = file.available();
} catch (IOException e) {
StateService.getTransactionProcessorGuard().unlock();

throw new ProcessorContentUploadFailureException(e.getMessage());
}

String workspaceUnitKey =
workspaceFacade.createWorkspaceUnitKey(validationSecretsApplication);

Expand Down Expand Up @@ -329,6 +340,13 @@ public void uploadObject(String location, InputStream file, ValidationSecretsApp
}

StateService.getTransactionProcessorGuard().unlock();

StateService.getWatcherService().increaseFilesUploadCounter();

StateService.getWatcherService().increaseUploadedFilesSize(fileSize);

telemetryService.setAverageUploadFileSizeQueue(
StateService.getWatcherService().getAverageFileSize());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ public class StateService {
* Represents ObjectStorage watcher service instance.
*/
@Getter
private static WatcherService watcherService;
private static final WatcherService watcherService = new WatcherService();
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,47 @@
package com.objectstorage.service.state.watcher;

import lombok.Getter;
import lombok.Setter;
import org.apache.commons.io.FileUtils;

/**
* Service used to track state metrics for the current session in the application.
*/
public class WatcherService {

/**
* Represents amount of files uploaded to ObjectStorage Temporate Storage in the current session.
*/
@Getter
@Setter
private static Double filesUploadCounter = (double) 0;
private Integer filesUploadCounter = 0;

/**
* Increases amount of files uploaded to ObjectStorage Temporate Storage in the current session.
*/
public void increaseFilesUploadCounter() {
filesUploadCounter++;
}

/**
* Represents global amount of files content uploaded in the current session.
* Represents global files size uploaded in the current session.
*/
@Getter
@Setter
private static Double uploadedFilesSize = (double) 0;
private Integer uploadedFilesSize = 0;

/**
* Increases global files size uploaded in the current session with the given value.
*
* @param value given value of uploaded file size.
*/
public void increaseUploadedFilesSize(Integer value) {
uploadedFilesSize += value;
}

/**
* Calculates average file size in the current session.
*
* @return calculated average file size.
*/
public Double getAverageFileSize() {
if (filesUploadCounter > 0) {
return Double.valueOf(uploadedFilesSize) / Double.valueOf(filesUploadCounter) / 1024 / 1024;
}

return (double) 0;
}
}
5 changes: 3 additions & 2 deletions config/grafana/dashboards/diagnostics.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@
"value": 80
}
]
}
},
"unit": "decmbytes"
},
"overrides": []
},
Expand Down Expand Up @@ -1051,6 +1052,6 @@
"timezone": "browser",
"title": "ObjectStorage Diagnostics",
"uid": "64nrElFmk",
"version": 3,
"version": 7,
"weekStart": ""
}

0 comments on commit 4260001

Please sign in to comment.