Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix linter for init and autofix gofumpt #221

Merged
merged 5 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ linters:
- promlinter
- interfacer
- gosec
- gofumpt
- godox
- godot
- gochecknoinits
- gci
- forbidigo
- errcheck
Expand Down Expand Up @@ -58,18 +56,21 @@ linters:
- gocyclo
- dupl
linters-settings:
gofumpt:
lang-version: "1.17"
extra-rules: true
revive:
ignore-generated-header: true
severity: warning
gomnd:
ignored-numbers: # Why we have a big range of file permissions
- '0644'
- '0655'
- '0666'
- '0770'
- '0755'
- '0765'
- '0777'
- '0o644'
sravankorumilli marked this conversation as resolved.
Show resolved Hide resolved
- '0o655'
- '0o666'
- '0o770'
- '0o755'
- '0o765'
- '0o777'
ignored-functions:
- 'survey.MinLength'
- 'survey.MaxLength'
Expand Down
2 changes: 1 addition & 1 deletion api/handler/v1beta1/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (adapt *Adapter) ToJobProto(spec models.JobSpec) (*pb.JobSpecification, err
})
}

//prep external dependencies for proto
// prep external dependencies for proto
for _, httpDep := range spec.ExternalDependencies.HTTPDependencies {
conf.Dependencies = append(conf.Dependencies, &pb.JobDependency{
HttpDependency: &pb.HttpDependency{
Expand Down
2 changes: 1 addition & 1 deletion api/handler/v1beta1/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (sv *RuntimeServiceServer) BackupDryRun(ctx context.Context, req *pb.Backup
}
jobSpecs = append(jobSpecs, downstreamSpecs...)

//should add config
// should add config
backupRequest := models.BackupRequest{
ResourceName: req.ResourceName,
Project: namespaceSpec.ProjectSpec,
Expand Down
4 changes: 2 additions & 2 deletions api/handler/v1beta1/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func (sv *RuntimeServiceServer) ListReplays(ctx context.Context, req *pb.ListRep
}, nil
}

func (sv *RuntimeServiceServer) parseReplayRequest(ctx context.Context, projectName string, namespace string,
jobName string, startDate string, endDate string, forceFlag bool, allowedDownstreams []string) (models.ReplayRequest, error) {
func (sv *RuntimeServiceServer) parseReplayRequest(ctx context.Context, projectName, namespace string,
jobName, startDate, endDate string, forceFlag bool, allowedDownstreams []string) (models.ReplayRequest, error) {
namespaceSpec, err := sv.namespaceService.Get(ctx, projectName, namespace)
if err != nil {
return models.ReplayRequest{}, mapToGRPCErr(sv.l, err, "unable to get namespace")
Expand Down
5 changes: 0 additions & 5 deletions api/handler/v1beta1/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,13 @@ type JobEventService interface {
type ProtoAdapter interface {
FromJobProto(*pb.JobSpecification) (models.JobSpec, error)
ToJobProto(models.JobSpec) (*pb.JobSpecification, error)

FromProjectProto(*pb.ProjectSpecification) models.ProjectSpec
ToProjectProto(models.ProjectSpec) *pb.ProjectSpecification

FromNamespaceProto(specification *pb.NamespaceSpecification) models.NamespaceSpec
ToNamespaceProto(spec models.NamespaceSpec) *pb.NamespaceSpecification

ToInstanceProto(models.InstanceSpec) (*pb.InstanceSpec, error)

FromResourceProto(res *pb.ResourceSpecification, storeName string) (models.ResourceSpec, error)
ToResourceProto(res models.ResourceSpec) (*pb.ResourceSpecification, error)

ToReplayExecutionTreeNode(res *tree.TreeNode) (*pb.ReplayExecutionTreeNode, error)
ToReplayStatusTreeNode(res *tree.TreeNode) (*pb.ReplayStatusTreeNode, error)
}
Expand Down
6 changes: 4 additions & 2 deletions api/handler/v1beta1/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ func TestRuntimeServiceServer(t *testing.T) {
},
FileMap: map[string]string{
"query.sql": "select * from 1",
}}, nil)
},
}, nil)
defer instanceService.AssertExpectations(t)

runtimeServiceServer := v1.NewRuntimeServiceServer(
Expand Down Expand Up @@ -223,7 +224,8 @@ func TestRuntimeServiceServer(t *testing.T) {
},
FileMap: map[string]string{
"query.sql": "select * from 1",
}}, nil)
},
}, nil)
defer instanceService.AssertExpectations(t)

runtimeServiceServer := v1.NewRuntimeServiceServer(
Expand Down
2 changes: 1 addition & 1 deletion cmd/admin_build_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func getInstanceBuildRequest(l log.Logger, jobName, inputDirectory, host, projec
}

// make sure output dir exists
if err := os.MkdirAll(inputDirectory, 0777); err != nil {
if err := os.MkdirAll(inputDirectory, 0o777); err != nil {
return fmt.Errorf("failed to create directory at %s: %w", inputDirectory, err)
}
writeToFileFn := utils.WriteStringToFileIndexed()
Expand Down
2 changes: 1 addition & 1 deletion cmd/backup_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func backupCreateCommand(l log.Logger, datastoreRepo models.DatastoreRepo, conf
return err
}
if dryRun {
//if only dry run, exit now
// if only dry run, exit now
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/backup_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func printBackupDetailResponse(l log.Logger, backupDetailResponse *pb.GetBackupR
table.SetBorder(false)

ttl := backupDetailResponse.Spec.Config[models.ConfigTTL]
var expiry = backupDetailResponse.Spec.CreatedAt.AsTime()
expiry := backupDetailResponse.Spec.CreatedAt.AsTime()
if ttl != "" {
ttlDuration, err := time.ParseDuration(ttl)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ type JobSpecRepository interface {
// default output of logging should go to stdout
// interactive output like progress bars should go to stderr
// unless the stdout/err is a tty, colors/progressbar should be disabled
func New(plainLog log.Logger, jsonLog log.Logger, conf config.Optimus, pluginRepo models.PluginRepository, dsRepo models.DatastoreRepo) *cli.Command {
func New(plainLog, jsonLog log.Logger, conf config.Optimus, pluginRepo models.PluginRepository, dsRepo models.DatastoreRepo) *cli.Command {
disableColoredOut = !isTerminal(os.Stdout)

var cmd = &cli.Command{
cmd := &cli.Command{
Use: "optimus <command> <subcommand> [flags]",
Long: heredoc.Doc(`
Optimus is an easy-to-use, reliable, and performant workflow orchestrator for
Expand Down Expand Up @@ -111,7 +111,7 @@ func New(plainLog log.Logger, jsonLog log.Logger, conf config.Optimus, pluginRep
cmdx.SetHelp(cmd)
cmd.PersistentFlags().BoolVar(&disableColoredOut, "no-color", disableColoredOut, "Disable colored output")

//init local specs
// init local specs
var jobSpecRepo JobSpecRepository
jobSpecFs := afero.NewBasePathFs(afero.NewOsFs(), conf.Namespace.Job.Path)
if conf.Namespace.Job.Path != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func configInitCommand(l log.Logger, dsRepo models.DatastoreRepo) *cli.Command {
if err != nil {
return err
}
if err := ioutil.WriteFile(fmt.Sprintf("%s.%s", config.FileName, config.FileExtension), confMarshaled, 0655); err != nil {
if err := ioutil.WriteFile(fmt.Sprintf("%s.%s", config.FileName, config.FileExtension), confMarshaled, 0o655); err != nil {
return err
}
l.Info(coloredSuccess("Configuration initialised successfully"))
Expand Down
4 changes: 2 additions & 2 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func deployCommand(l log.Logger, conf config.Optimus, jobSpecRepo JobSpecReposit
}

// postDeploymentRequest send a deployment request to service
func postDeploymentRequest(l log.Logger, projectName string, namespaceName string, jobSpecRepo JobSpecRepository,
func postDeploymentRequest(l log.Logger, projectName, namespaceName string, jobSpecRepo JobSpecRepository,
conf config.Optimus, pluginRepo models.PluginRepository, datastoreRepo models.DatastoreRepo, datastoreSpecFs map[string]afero.Fs,
ignoreJobDeployment, ignoreResources bool, verbose bool) (err error) {
ignoreJobDeployment, ignoreResources, verbose bool) (err error) {
dialTimeoutCtx, dialCancel := context.WithTimeout(context.Background(), OptimusDialTimeout)
defer dialCancel()

Expand Down
4 changes: 2 additions & 2 deletions cmd/job_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func createJobSurvey(jobSpecRepo JobSpecRepository, pluginRepo models.PluginRepo
return local.Job{}, errors.New("no supported task plugin found")
}

var qs = []*survey.Question{
qs := []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{
Expand Down Expand Up @@ -357,7 +357,7 @@ func getWindowParameters(winName string) local.JobTaskWindow {
}
}

//default
// default
return local.JobTaskWindow{
Size: "24h",
Offset: "0",
Expand Down
2 changes: 1 addition & 1 deletion cmd/job_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func createHookSurvey(jobSpec models.JobSpec, pluginRepo models.PluginRepository
return emptyJobSpec, errors.New("no supported hook plugin found")
}

var qs = []*survey.Question{
qs := []*survey.Question{
{
Name: "hook",
Prompt: &survey.Select{
Expand Down
2 changes: 1 addition & 1 deletion cmd/job_render.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func jobRenderTemplateCommand(l log.Logger, jobSpecRepo JobSpecRepository) *cli.

// create temporary directory
renderedPath := filepath.Join(".", "render", jobSpec.Name)
_ = os.MkdirAll(renderedPath, 0770)
_ = os.MkdirAll(renderedPath, 0o770)
l.Info(fmt.Sprintf("Rendering assets in %s", renderedPath))

now := time.Now()
Expand Down
2 changes: 1 addition & 1 deletion cmd/job_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func jobValidateCommand(l log.Logger, pluginRepo models.PluginRepository, jobSpe
return cmd
}

func validateJobSpecificationRequest(l log.Logger, projectName string, namespace string,
func validateJobSpecificationRequest(l log.Logger, projectName, namespace string,
pluginRepo models.PluginRepository, jobSpecs []models.JobSpec, host string, verbose bool) (err error) {
adapt := v1handler.NewAdapter(pluginRepo, models.DatastoreRegistry)

Expand Down
2 changes: 1 addition & 1 deletion cmd/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func taskRunBlockComparator(a, b interface{}) int {
return strings.Compare(aAsserted.name, bAsserted.name)
}

//formatRunsPerJobInstance returns a hashmap with Job -> Runs[] mapping
// formatRunsPerJobInstance returns a hashmap with Job -> Runs[] mapping
func formatRunsPerJobInstance(instance *pb.ReplayExecutionTreeNode, taskReruns map[string]taskRunBlock, height int) {
if _, ok := taskReruns[instance.JobName]; !ok {
taskReruns[instance.JobName] = taskRunBlock{
Expand Down
10 changes: 5 additions & 5 deletions cmd/replay_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Date ranges are inclusive.
return err
}
if dryRun {
//if only dry run, exit now
// if only dry run, exit now
return nil
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func printReplayDryRunResponse(l log.Logger, replayRequest *pb.ReplayDryRunReque
taskRerunsMap := make(map[string]taskRunBlock)
formatRunsPerJobInstance(replayDryRunResponse.ExecutionTree, taskRerunsMap, 0)

//sort run block
// sort run block
taskRerunsSorted := set.NewTreeSetWith(taskRunBlockComparator)
for _, block := range taskRerunsMap {
taskRerunsSorted.Add(block)
Expand All @@ -178,19 +178,19 @@ func printReplayDryRunResponse(l log.Logger, replayRequest *pb.ReplayDryRunReque
}
table.Render()

//print tree
// print tree
l.Info(coloredNotice("\n> Dependency tree"))
l.Info(fmt.Sprintf("%s", printExecutionTree(replayDryRunResponse.ExecutionTree, treeprint.New())))

//ignored jobs
// ignored jobs
if len(replayDryRunResponse.IgnoredJobs) > 0 {
l.Info("> Ignored jobs")
ignoredJobsCount := 0
for _, job := range replayDryRunResponse.IgnoredJobs {
ignoredJobsCount++
l.Info(fmt.Sprintf("%d. %s", ignoredJobsCount, job))
}
//separator
// separator
l.Info("")
}
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/replay_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ func printReplayListResponse(l log.Logger, replayListResponse *pb.ListReplaysRes
})

for _, replaySpec := range replayListResponse.ReplayList {
table.Append([]string{replaySpec.Id, replaySpec.JobName, replaySpec.StartDate.AsTime().Format(models.JobDatetimeLayout),
table.Append([]string{
replaySpec.Id, replaySpec.JobName, replaySpec.StartDate.AsTime().Format(models.JobDatetimeLayout),
replaySpec.EndDate.AsTime().Format(models.JobDatetimeLayout), replaySpec.Config[models.ConfigIgnoreDownstream],
replaySpec.CreatedAt.AsTime().Format(time.RFC3339), replaySpec.State})
replaySpec.CreatedAt.AsTime().Format(time.RFC3339), replaySpec.State,
})
}

table.Render()
Expand Down
4 changes: 1 addition & 3 deletions cmd/replay_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import (
)

func replayStatusCommand(l log.Logger, conf config.Optimus) *cli.Command {
var (
projectName string
)
var projectName string

reCmd := &cli.Command{
Use: "status",
Expand Down
8 changes: 3 additions & 5 deletions cmd/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import (
cli "github.com/spf13/cobra"
)

var (
validateResourceName = utils.ValidatorFactory.NewFromRegex(`^[a-zA-Z0-9][a-zA-Z0-9_\-\.]+$`,
`invalid name (can only contain characters A-Z (in either case), 0-9, "-", "_" or "." and must start with an alphanumeric character)`)
)
var validateResourceName = utils.ValidatorFactory.NewFromRegex(`^[a-zA-Z0-9][a-zA-Z0-9_\-\.]+$`,
`invalid name (can only contain characters A-Z (in either case), 0-9, "-", "_" or "." and must start with an alphanumeric character)`)

func resourceCommand(l log.Logger, datastoreSpecsFs map[string]afero.Fs, datastoreRepo models.DatastoreRepo) *cli.Command {
cmd := &cli.Command{
Expand Down Expand Up @@ -87,7 +85,7 @@ func createResourceSubCommand(l log.Logger, datastoreSpecFs map[string]afero.Fs,
resourceDirectory := filepath.Join(rwd, newDirName)
resourceNameDefault := strings.ReplaceAll(strings.ReplaceAll(resourceDirectory, "/", "."), "\\", ".")

var qs = []*survey.Question{
qs := []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{
Expand Down
6 changes: 2 additions & 4 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ import (
"gorm.io/gorm"
)

var (
// termChan listen for sigterm
termChan = make(chan os.Signal, 1)
)
// termChan listen for sigterm
var termChan = make(chan os.Signal, 1)

const (
shutdownWait = 30 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func versionCommand(l log.Logger, host string, pluginRepo models.PluginRepositor
}

// getVersionRequest send a version request to service
func getVersionRequest(clientVer string, host string) (ver string, err error) {
func getVersionRequest(clientVer, host string) (ver string, err error) {
dialTimeoutCtx, dialCancel := context.WithTimeout(context.Background(), OptimusDialTimeout)
defer dialCancel()

Expand Down
10 changes: 5 additions & 5 deletions core/gossip/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const (
connectionTimeout = 10 * time.Second

applyTimeout = 10 * time.Second
//leaderWaitDelay = 100 * time.Millisecond
//appliedWaitDelay = 100 * time.Millisecond
//raftLogCacheSize = 512
// leaderWaitDelay = 100 * time.Millisecond
// appliedWaitDelay = 100 * time.Millisecond
// raftLogCacheSize = 512
)

type Server struct {
Expand Down Expand Up @@ -180,7 +180,7 @@ func newSerfConfig(serfAddr, raftAddress, nodeID string, eventCh chan serf.Event
// raft manages the leadership/follower state in cluster
// minimum 3 nodes are required to work properly to have 1 node
// fail-over resistant
func (s *Server) initRaft(_ context.Context, devMode bool, bootstrapCluster bool, schedulerConf config.SchedulerConfig, fsm raft.FSM) error {
func (s *Server) initRaft(_ context.Context, devMode, bootstrapCluster bool, schedulerConf config.SchedulerConfig, fsm raft.FSM) error {
c := raft.DefaultConfig()
c.LocalID = raft.ServerID(schedulerConf.NodeID)

Expand Down Expand Up @@ -232,7 +232,7 @@ func (s *Server) initRaftStore(devMode bool, baseDir string) (raft.LogStore, raf
}

// prepare directory for data
if err := os.MkdirAll(baseDir, 0777); err != nil {
if err := os.MkdirAll(baseDir, 0o777); err != nil {
return nil, nil, nil, err
}

Expand Down
6 changes: 2 additions & 4 deletions core/tree/multi_root_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import (
"fmt"
)

var (
// ErrCyclicDependencyEncountered is triggered a tree has a cyclic dependency
ErrCyclicDependencyEncountered = errors.New("a cycle dependency encountered in the tree")
)
// ErrCyclicDependencyEncountered is triggered a tree has a cyclic dependency
var ErrCyclicDependencyEncountered = errors.New("a cycle dependency encountered in the tree")

// MultiRootTree - represents a data type which has multiple independent root nodes
// all root nodes have their independent tree based on depdencies of TreeNode.
Expand Down
Loading