Skip to content

Commit

Permalink
chore: lower loglevel of a few messages for a cleaner log
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippHeuer committed Nov 24, 2024
1 parent 18a5bc3 commit 6d228fb
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/cidverse/go-rules v0.0.0-20231112122021-075e5e6f8abc
github.com/cidverse/go-vcs v0.0.0-20241123123700-fb65a5c04ebd
github.com/cidverse/normalizeci v1.1.1-0.20240908141115-5bdf33fc46f7
github.com/cidverse/repoanalyzer v0.1.1-0.20240908105803-398dee64015f
github.com/cidverse/repoanalyzer v0.1.1-0.20241123141326-6ec8c45aa8a1
github.com/go-resty/resty/v2 v2.16.2
github.com/google/uuid v1.6.0
github.com/hashicorp/go-version v1.7.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/cidverse/go-vcs v0.0.0-20241123123700-fb65a5c04ebd h1:QwKLgely2pWfIsV
github.com/cidverse/go-vcs v0.0.0-20241123123700-fb65a5c04ebd/go.mod h1:TizJRTDYBAugrGTqJ+ui8g8XOghxuJpKW3Y5/JXZkq8=
github.com/cidverse/normalizeci v1.1.1-0.20240908141115-5bdf33fc46f7 h1:R4MHxm375DRDfdPxSCq9MS5PaKONj/fOqQiu+k6s9QQ=
github.com/cidverse/normalizeci v1.1.1-0.20240908141115-5bdf33fc46f7/go.mod h1:p8GjbBHa9vQ9JF0I14b33JNcbrRhLOtzLbZMmuDEVAw=
github.com/cidverse/repoanalyzer v0.1.1-0.20240908105803-398dee64015f h1:1KoORYMFAC0/lkmCvhbwLU0csfSfCu+zgpJl1n5lUKY=
github.com/cidverse/repoanalyzer v0.1.1-0.20240908105803-398dee64015f/go.mod h1:7UudNgfkiXc+lXV7xhyUAd2hsmG4DrFyX/31hnWRpaE=
github.com/cidverse/repoanalyzer v0.1.1-0.20241123141326-6ec8c45aa8a1 h1:2KS5Z+NYxGCNc97wTuhp0hj+P5SAxxQMJ7EiKfqzjmM=
github.com/cidverse/repoanalyzer v0.1.1-0.20241123141326-6ec8c45aa8a1/go.mod h1:aENXKFNhY9iYvVkjT+Y9qIKjLsgJeZ5P+30MEUMTBlA=
github.com/cloudflare/circl v1.5.0 h1:hxIWksrX6XN5a1L2TI/h53AGPhNHoUBo+TD1ms9+pys=
github.com/cloudflare/circl v1.5.0/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
Expand Down
14 changes: 7 additions & 7 deletions pkg/common/api/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,25 @@ func RegisterBuiltinAction(action ActionStep) {

// GetActionContext gets the action context, this operation is expensive and should only be called once per execution
func GetActionContext(modules []*analyzerapi.ProjectModule, projectDir string, env map[string]string, access *catalog.ActionAccess) ActionExecutionContext {
finalEnv := make(map[string]string)
fullEnv := lo.Assign(env, api.GetMachineEnvironment())
actionEnv := make(map[string]string)

// user
currentUser, _ := user.Current()

// evaluate access
// only pass allowed env variables
fullEnv := lo.Assign(env, api.GetMachineEnvironment())
for k, v := range fullEnv {
if strings.HasPrefix(k, "NCI_") {
finalEnv[k] = v
actionEnv[k] = v
continue
}

if access != nil && len(access.Env) > 0 {
for _, envAccess := range access.Env {
if envAccess.Pattern == true && regexp.MustCompile(envAccess.Value).MatchString(k) {
finalEnv[k] = v
actionEnv[k] = v
} else if envAccess.Value == k {
finalEnv[k] = v
actionEnv[k] = v
}
}
}
Expand All @@ -118,7 +118,7 @@ func GetActionContext(modules []*analyzerapi.ProjectModule, projectDir string, e
WorkDir: filesystem.WorkingDirOrPanic(),
Config: "",
Args: nil,
Env: finalEnv,
Env: actionEnv,
Parallelization: DefaultParallelization,
CurrentUser: *currentUser,
Modules: modules,
Expand Down
5 changes: 2 additions & 3 deletions pkg/common/workflowrun/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ func IsActionExecutable(a *catalog.Action, env map[string]string) bool {
// FirstWorkflowMatchingRules returns the first workflow that matches at least one rule
func FirstWorkflowMatchingRules(workflows []catalog.Workflow, env map[string]string) *catalog.Workflow {
// select workflow
log.Info().Msg("evaluating all workflows")
for _, wf := range workflows {
log.Debug().Str("workflow", wf.Name).Msg("evaluating workflow rules")
log.Debug().Str("workflow", wf.Name).Int("rules", len(wf.Rules)).Msg("evaluating workflow rules")

if len(wf.Rules) > 0 {
for _, rule := range wf.Rules {
Expand Down Expand Up @@ -174,7 +173,7 @@ func runWorkflowAction(catalogAction *catalog.Action, action *catalog.WorkflowAc
if ctx.CurrentModule != nil {
currentModule = ctx.CurrentModule.Slug
}
log.Info().Str("action", action.ID).Str("module", currentModule).Str("module-dir", ctx.CurrentModule.Directory).Msg("action start")
log.Info().Str("action", action.ID).Str("module", currentModule).Msg("action start")

// state: retrieve/init
localState := state.GetStateFromDirectory(ctx.Paths.Artifact)
Expand Down
20 changes: 11 additions & 9 deletions pkg/core/actionexecutor/containeraction/containerexecutor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package containeraction
import (
"context"
"encoding/json"
"errors"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -106,16 +107,16 @@ func (e Executor) Execute(ctx *commonapi.ActionExecutionContext, localState *sta
}
}()

// shutdown listener (on function end)
// shutdown listener
defer func(apiEngine *echo.Echo, ctx context.Context) {
err := apiEngine.Shutdown(ctx)
err = apiEngine.Shutdown(ctx)
if err != nil {
log.Fatal().Err(err).Msg("failed to shutdown rest api")
}
}(apiEngine, context.Background())

// wait a short moment for the unix socket to be created / the api endpoint to be ready
time.Sleep(100 * time.Millisecond)
time.Sleep(100 * time.Millisecond) // TODO: find a better way to wait for the api to be ready

// configure container
containerExec := containerruntime.Container{
Expand Down Expand Up @@ -184,12 +185,13 @@ func (e Executor) Execute(ctx *commonapi.ActionExecutionContext, localState *sta
}
log.Debug().Str("action", catalogAction.Name).Msg("container command for action: " + containerCmd)
cmdErr := command.RunOptionalCommand(containerCmd, nil, "")
exitErr, isExitError := cmdErr.(*exec.ExitError)
if isExitError {
log.Error().Int("exit_code", exitErr.ExitCode()).Str("message", exitErr.Error()).Msg("command failed")
return cmdErr
} else if cmdErr != nil {
log.Error().Int("exit_code", 1).Str("message", exitErr.Error()).Msg("command failed")
if cmdErr != nil {
var exitErr *exec.ExitError
exitCode := 1
if errors.As(cmdErr, &exitErr) {
exitCode = exitErr.ExitCode()
}
log.Error().Int("exit_code", exitCode).Str("message", cmdErr.Error()).Msg("command failed")
return cmdErr
}

Expand Down
9 changes: 0 additions & 9 deletions pkg/core/cliutil/cli-util.go

This file was deleted.

6 changes: 4 additions & 2 deletions pkg/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ var Current = CIDConfig{}

func LoadConfig(projectDirectory string) *CIDConfig {
cfg := CIDConfig{}
// internal config

// defaults
unmarshalNoError("files/cid-main.yaml", yaml.Unmarshal([]byte(getEmbeddedConfig("files/cid-main.yaml")), &cfg))
unmarshalNoError("files/cid-tools.yaml", yaml.Unmarshal([]byte(getEmbeddedConfig("files/cid-tools.yaml")), &cfg))

// default os cache dir
catalogSources := catalog.LoadSources()
cfg.CatalogSources = catalogSources
data := catalog.LoadCatalogs(catalogSources)
log.Info().Int("images", len(data.ContainerImages)).Int("actions", len(data.Actions)).Int("workflows", len(data.Workflows)).Msg("loaded catalogs")
log.Debug().Int("catalogs", len(cfg.CatalogSources)).Int("images", len(data.ContainerImages)).Int("actions", len(data.Actions)).Int("workflows", len(data.Workflows)).Msg("loaded catalog from registries")

cfg.Registry.ContainerImages = append(cfg.Registry.ContainerImages, data.ContainerImages...)
cfg.Registry.Actions = append(cfg.Registry.Actions, data.Actions...)
cfg.Registry.Workflows = append(cfg.Registry.Workflows, data.Workflows...)
Expand Down
16 changes: 9 additions & 7 deletions pkg/core/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"github.com/rs/zerolog/log"
)

const ModuleName = "MODULE_NAME"
const ModuleSlug = "MODULE_SLUG"
const ModuleType = "MODULE_TYPE"
const ModuleBuildSystem = "MODULE_BUILD_SYSTEM"
const ModuleBuildSystemSyntax = "MODULE_BUILD_SYSTEM_SYNTAX"
const ModuleSpecificationType = "MODULE_SPECIFICATION_TYPE"
const ModuleFiles = "MODULE_FILES"
const (
ModuleName = "MODULE_NAME"
ModuleSlug = "MODULE_SLUG"
ModuleType = "MODULE_TYPE"
ModuleBuildSystem = "MODULE_BUILD_SYSTEM"
ModuleBuildSystemSyntax = "MODULE_BUILD_SYSTEM_SYNTAX"
ModuleSpecificationType = "MODULE_SPECIFICATION_TYPE"
ModuleFiles = "MODULE_FILES"
)

// AnyRuleMatches will return true if at least one rule matches, if no rules are provided this always returns true
func AnyRuleMatches(rules []catalog.WorkflowRule, evalContext map[string]interface{}) bool {
Expand Down

0 comments on commit 6d228fb

Please sign in to comment.