Skip to content

Commit

Permalink
Minor fixes to the log and stream process (#262)
Browse files Browse the repository at this point in the history
- Added an environment variable to set the path for the log file `PRL_DEVOPS_LOG_FILE_PATH`
- Added an environment variable to disable the streaming process for the remote storage provider `DISABLE_CATALOG_PROVIDER_STREAMING`
  • Loading branch information
cjlapao authored Jan 7, 2025
1 parent 909bf5a commit 003e095
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/catalog/cacheservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (cs *CacheService) checkNeedCleanup() (*CleanupRequirements, error) {

manifestUsedSize := cs.manifest.Size * 2
// if we can stream then we do no need the double size request
if cs.rss.CanStream() {
if cs.rss.CanStream() && cs.cfg.IsRemoteProviderStreamEnabled() {
manifestUsedSize = cs.manifest.Size
}

Expand Down
3 changes: 2 additions & 1 deletion src/catalog/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,9 @@ func (s *CatalogManifestService) pullAndDecompressPackFile(r *models.PullCatalog
if rss == nil {
return errors.NewWithCode("Remote storage service is nil", 500)
}
cfg := config.Get()
cleanupSvc := cleanupservice.NewCleanupService()
if rss.CanStream() {
if rss.CanStream() && cfg.IsRemoteProviderStreamEnabled() {
if err := s.processFileWithStream(r.LocalMachineFolder, rss, manifest, cleanupSvc); err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions src/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,15 @@ func (c *Config) EnableReverseProxy(value bool) bool {
return true
}

func (c *Config) IsRemoteProviderStreamEnabled() bool {
streamingDisabled := c.GetKey(constants.DISABLE_CATALOG_PROVIDER_STREAMING_ENV_VAR)
if streamingDisabled == "" {
return true
}

return !helpers.StringToBool(streamingDisabled)
}

func (c *Config) GetKey(key string) string {
value := helper.GetFlagValue(key, "")
exists := false
Expand Down
2 changes: 2 additions & 0 deletions src/constants/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const (
REVERSE_PROXY_PORT_ENV_VAR = "REVERSE_PROXY_PORT"
REVERSE_PROXY_HOST_ENV_VAR = "REVERSE_PROXY_HOST"
LOG_TO_FILE_ENV_VAR = "PRL_DEVOPS_LOG_TO_FILE"
LOG_FILE_PATH_ENV_VAR = "PRL_DEVOPS_LOG_FILE_PATH"
DISABLE_CATALOG_PROVIDER_STREAMING_ENV_VAR = "DISABLE_CATALOG_PROVIDER_STREAMING"
)

const (
Expand Down
16 changes: 16 additions & 0 deletions src/helpers/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,19 @@ func ObfuscateString(value string) string {
func ClearLine() {
fmt.Printf("\r\033[K")
}

func StringToBool(s string) bool {
if s == "true" ||
s == "1" ||
s == "yes" ||
s == "y" ||
s == "t" ||
s == "on" ||
s == "enable" ||
s == "enabled" ||
s == "active" {
return true
}

return false
}
11 changes: 11 additions & 0 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"time"
Expand Down Expand Up @@ -82,6 +83,16 @@ func main() {
enableLogToFile := os.Getenv(constants.LOG_TO_FILE_ENV_VAR)
if enableLogToFile == "true" {
logFilename := "prldevops.log"
filePath := os.Getenv(constants.LOG_FILE_PATH_ENV_VAR)
if filePath != "" {
baseFolder := filepath.Dir(filePath)
if _, err := os.Stat(baseFolder); os.IsNotExist(err) {
ctx.LogErrorf("[Core] Log file path does not exist: %s, using executable path", filePath)
} else {
logFilename = filepath.Join(filePath, logFilename)
}
}

executable, err := os.Executable()
if err == nil && !strings.Contains(executable, "__debug") {
logFilename = executable + ".log"
Expand Down

0 comments on commit 003e095

Please sign in to comment.