Skip to content

Commit

Permalink
Merge pull request #314 from mercedes-benz/improve_error_message
Browse files Browse the repository at this point in the history
Improve error messages in garm log
  • Loading branch information
gabriel-samfira authored Nov 26, 2024
2 parents 06dfc27 + 6167d8c commit 8e13588
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ linters-settings:

goimports:
local-prefixes: github.com/cloudbase/garm

gosec:
excludes:
- G115
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ create-release-files:
release: build-static create-release-files ## Create a release

##@ Lint / Verify
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint

## Tool Versions
GOLANGCI_LINT_VERSION ?= v1.61.0

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. If wrong version is installed, it will be overwritten.
$(GOLANGCI_LINT): $(LOCALBIN)
test -s $(LOCALBIN)/golangci-lint && $(LOCALBIN)/golangci-lint --version | grep -q $(GOLANGCI_LINT_VERSION) || \
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

.PHONY: lint
lint: golangci-lint $(GOLANGCI_LINT) ## Run linting.
$(GOLANGCI_LINT) run -v --build-tags=testing,integration $(GOLANGCI_LINT_EXTRA_ARGS)
Expand Down
6 changes: 4 additions & 2 deletions database/sql/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func (s *sqlDatabase) paramsJobToWorkflowJob(ctx context.Context, job params.Job
if job.RunnerName != "" {
instance, err := s.getInstanceByName(s.ctx, job.RunnerName)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to get instance by name")
// This usually is very normal as not all jobs run on our runners.
slog.DebugContext(ctx, "failed to get instance by name", "instance_name", job.RunnerName)
} else {
workflofJob.InstanceID = &instance.ID
}
Expand Down Expand Up @@ -244,7 +245,8 @@ func (s *sqlDatabase) CreateOrUpdateJob(ctx context.Context, job params.Job) (pa
if err == nil {
workflowJob.InstanceID = &instance.ID
} else {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to get instance by name")
// This usually is very normal as not all jobs run on our runners.
slog.DebugContext(ctx, "failed to get instance by name", "instance_name", job.RunnerName)
}
}

Expand Down
2 changes: 1 addition & 1 deletion database/sql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func (s *sqlDatabase) updatePool(tx *gorm.DB, pool Pool, param params.UpdatePool
}

tags := []Tag{}
if param.Tags != nil && len(param.Tags) > 0 {
if len(param.Tags) > 0 {
for _, val := range param.Tags {
t, err := s.getOrCreateTag(tx, val)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions runner/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ func (r *basePoolManager) HandleWorkflowJob(job params.WorkflowJob) error {
return errors.Wrap(err, "validating owner")
}

// we see events where the lables seem to be missing. We should ignore these
// as we can't know if we should handle them or not.
if len(job.WorkflowJob.Labels) == 0 {
slog.WarnContext(r.ctx, "job has no labels", "workflow_job", job.WorkflowJob.Name)
return nil
}

var jobParams params.Job
var err error
var triggeredBy int64
Expand Down

0 comments on commit 8e13588

Please sign in to comment.