Skip to content

Commit

Permalink
Add env property for disabling upload progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
radito3 committed Oct 20, 2023
1 parent f86b520 commit fe55c2a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The configuration of the MultiApps CF plugin is done via env variables. The foll
:rotating_light: Note: The total number of chunks in which an MTAR is split cannot exceed 50, since the multiapps-controller could interpret bigger values as a denial-of-service attack. For this reason, the minimum value for this environment variable is computed based on the formula: `MIN = MTAR_SIZE / 50`
For example, with a 100MB MTAR the minimum value for this environment variable would be 2, and for a 400MB MTAR it would be 8. Finally, the minimum value cannot grow over 50, so with a 4GB MTAR, the minimum value would be 50 and not 80.
* `MULTIAPPS_UPLOAD_CHUNKS_SEQUENTIALLY=<BOOLEAN>` - By default, MTAR chunks are uploaded in parallel for better performance. In case of a bad internet connection, the option to upload them sequentially will lessen network load.
* `MULTIAPPS_DISABLE_UPLOAD_PROGRESS_BAR=<BOOLEAN>` - By default, the file upload shows a progress bar. In case of CI/CD systems where console text escaping isn't supported, the bar can be disabled to reduce unnecessary logs.

# How to contribute
* [Did you find a bug?](CONTRIBUTING.md#did-you-find-a-bug)
Expand Down
20 changes: 12 additions & 8 deletions commands/file_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (

// FileUploader uploads files in chunks for the specified namespace
type FileUploader struct {
mtaClient mtaclient.MtaClientOperations
namespace string
uploadChunkSizeInMB uint64
sequentialUpload bool
mtaClient mtaclient.MtaClientOperations
namespace string
uploadChunkSizeInMB uint64
sequentialUpload bool
shouldDisableProgressBar bool
}

type progressBarReader struct {
Expand Down Expand Up @@ -64,11 +65,13 @@ func (r *progressBarReader) Close() error {

// NewFileUploader creates a new file uploader for the specified namespace
func NewFileUploader(mtaClient mtaclient.MtaClientOperations, namespace string, uploadChunkSizeInMB uint64) *FileUploader {
conf := configuration.NewSnapshot()
return &FileUploader{
mtaClient: mtaClient,
namespace: namespace,
uploadChunkSizeInMB: uploadChunkSizeInMB,
sequentialUpload: configuration.NewSnapshot().GetUploadChunksSequentially(),
mtaClient: mtaClient,
namespace: namespace,
uploadChunkSizeInMB: uploadChunkSizeInMB,
sequentialUpload: conf.GetUploadChunksSequentially(),
shouldDisableProgressBar: conf.GetDisableUploadProgressBar(),
}
}

Expand Down Expand Up @@ -157,6 +160,7 @@ func (f *FileUploader) uploadInChunks(fileToUpload *os.File) ([]*models.FileMeta
progressBar := pb.New64(fileInfo.Size()).SetUnits(pb.U_BYTES)
progressBar.ShowTimeLeft = false
progressBar.ShowElapsedTime = true
progressBar.NotPrint = f.shouldDisableProgressBar
progressBar.Start()
defer progressBar.Finish()

Expand Down
6 changes: 6 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ type Snapshot struct {
backendURL properties.ConfigurableProperty
uploadChunkSizeInMB properties.ConfigurableProperty
uploadChunksSequentially properties.ConfigurableProperty
disableProgressBar properties.ConfigurableProperty
}

func NewSnapshot() Snapshot {
return Snapshot{
backendURL: properties.BackendURL,
uploadChunkSizeInMB: properties.UploadChunkSizeInMB,
uploadChunksSequentially: properties.UploadChunksSequentially,
disableProgressBar: properties.DisableProgressBar,
}
}

Expand All @@ -34,6 +36,10 @@ func (c Snapshot) GetUploadChunksSequentially() bool {
return getBoolProperty(c.uploadChunksSequentially)
}

func (c Snapshot) GetDisableUploadProgressBar() bool {
return getBoolProperty(c.disableProgressBar)
}

func getStringProperty(property properties.ConfigurableProperty) string {
uncastedValue := getPropertyOrDefault(property)
value, ok := uncastedValue.(string)
Expand Down
9 changes: 9 additions & 0 deletions configuration/properties/disable_progress_bar_property.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package properties

var DisableProgressBar = ConfigurableProperty{
Name: "MULTIAPPS_DISABLE_UPLOAD_PROGRESS_BAR",
Parser: booleanParser{},
ParsingSuccessMessage: "Attention: You've specified %v for the environment variable %s.\n",
ParsingFailureMessage: "Invalid boolean value (%s) for environment variable %s. Using default value %v.\n",
DefaultValue: false,
}

0 comments on commit fe55c2a

Please sign in to comment.