Skip to content

Commit

Permalink
cli:chore - deprecate monitor-retry-count flag
Browse files Browse the repository at this point in the history
Previously we control all execution of tools using a monitor package,
but this package contained a lot of data races that was fixed on #477
and the monitor retry count flag was no longer necessary, since this was
used to control the timeout counter.

This commit mark monitor-retry-count flag as hidden and deprecated, so
new users will not see this flag and users that is currently using this
flag on pipelines will see a warning saying to use just --analysis-timeout
flag.

Signed-off-by: Matheus Alcantara <matheus.alcantara@zup.com.br>
  • Loading branch information
matheusalcantarazup committed Dec 3, 2021
1 parent 59c327f commit a3b0f67
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
18 changes: 17 additions & 1 deletion cmd/app/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,23 @@ func (s *Start) CreateStartCommand() *cobra.Command {
)
}

return startCmd
return s.setDeprecatedFlags(startCmd)
}

func (s *Start) setDeprecatedFlags(cmd *cobra.Command) *cobra.Command {
flags := cmd.PersistentFlags()

if err := flags.MarkHidden("monitor-retry-count"); err != nil {
logger.LogPanic(fmt.Sprintf(messages.PanicMarkHiddenFlag, "monitor-retry-count"), err)
}

if err := flags.MarkDeprecated(
"monitor-retry-count", "monitor component no longer exists in Horusec. Use only --analysis-timeout.",
); err != nil {
logger.LogPanic(fmt.Sprintf(messages.PanicMarkDeprecatedFlag, "monitor-retry-count"), err)
}

return cmd
}

func (s *Start) runE(cmd *cobra.Command, _ []string) error {
Expand Down
10 changes: 2 additions & 8 deletions internal/controllers/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,23 +258,17 @@ func (a *Analyzer) startDetectVulnerabilities(langs []languages.Language) {
wg.Wait()
}()

timeout := a.config.TimeoutInSecondsAnalysis
timer := time.After(time.Duration(timeout) * time.Second)
retry := a.config.MonitorRetryInSeconds
tick := time.NewTicker(time.Duration(retry) * time.Second)
defer tick.Stop()
timeout := time.After(time.Duration(a.config.TimeoutInSecondsAnalysis) * time.Second)
for {
select {
case <-done:
a.loading.Stop()
return
case <-timer:
case <-timeout:
a.docker.DeleteContainersFromAPI()
a.config.IsTimeout = true
a.loading.Stop()
return
case <-tick.C:
timeout -= retry
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/helpers/messages/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ const (
MsgPanicGetFlagValue = "{HORUSEC_CLI} Error on getting flag value, check and try again: "
MsgPanicNotConnectDocker = "{HORUSEC_CLI} Error when try connect in docker."
MsgPanicGetConfigFilePath = "{HORUSEC-CLI} Error on get config file path."
PanicMarkHiddenFlag = "{HORUSEC-CLI} Internal error occurred to hidden %s flag: "
PanicMarkDeprecatedFlag = "{HORUSEC-CLI} Internal error occurred to mark %s flag as deprecated: "
)

0 comments on commit a3b0f67

Please sign in to comment.