Skip to content

Commit

Permalink
feat(checkhealth): create new command to check overall status
Browse files Browse the repository at this point in the history
  • Loading branch information
Wabri committed Jun 14, 2024
1 parent fb4267b commit aae419c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 5 deletions.
24 changes: 19 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
CURRENT_DIR := $(shell pwd)

clean:
@echo "\n----- Start CLEAN -----\n"
@echo "# Remove all the daje metadata and builds..."
rm -r $(CURRENT_DIR)/bin &>/dev/null
@echo "\n----- End CLEAN -----"

# The version in this build has the form `<tag>|<commit_sha>`
build:
@echo "PROD: Building daje..."
build: clean
@echo "\n----- Start BUILD -----\n"
@echo "# Building daje for production environment..."
go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD)" -o ./bin/daje .
@echo "\n----- End BUILD -----"

# For debugging reason the version in this build has the form `<current_branch>+<commit_sha>+<number_of_changes_not_committed>`
build-test-dev:
@echo "TEST-DEV: Building daje for testing pourpose..."
rm -rf $(CURRENT_DIR)/testdata
build-test-dev: clean
@echo "\n----- Start BUILD-TEST-DEV -----\n"
@echo "# Building daje for development environment..."
go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.DajeConfigBaseDir=$(CURRENT_DIR)/testdata -X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git branch --show-current)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l)" -o ./bin/daje .
@echo "\n----- End BUILD-TEST-DEV -----"

checkhealth: build-test-dev
@echo "\n----- Start CHECKHEALTH -----\n"
@echo "# run checkhealth command..."
./bin/daje checkhealth
@echo "\n----- End CHECKHEALTH -----"
4 changes: 4 additions & 0 deletions constants/contants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package constants

import "path"

var DajeConfigBaseDir = "~/.config/"
var DajeDotfileName = "daje.conf"
var DajeDotfilePath = path.Join(DajeConfigBaseDir, DajeDotfileName)

var Version = ""
6 changes: 6 additions & 0 deletions internal/tuning/tuning.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tuning

// TODO: when the first tuning options will be available we need something to prove that the system is tuned accordingly to the configuration
func IsSystemTuned() bool {
return true
}
31 changes: 31 additions & 0 deletions pkg/cmd/checkhealth/checkhealth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package checkhealth

import (
"fmt"

"github.com/spf13/cobra"

Check failure on line 6 in pkg/cmd/checkhealth/checkhealth.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/spf13/cobra' is not allowed from list 'Main' (depguard)

"github.com/Schrodinger-Hat/Daje/constants"

Check failure on line 8 in pkg/cmd/checkhealth/checkhealth.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/Schrodinger-Hat/Daje/constants' is not allowed from list 'Main' (depguard)
"github.com/Schrodinger-Hat/Daje/internal/tuning"

Check failure on line 9 in pkg/cmd/checkhealth/checkhealth.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/Schrodinger-Hat/Daje/internal/tuning' is not allowed from list 'Main' (depguard)
)

func NewCmdCheckhealth() *cobra.Command {
cmd := &cobra.Command{
Use: "checkhealth [flags]",
Short: "Check Daje health",
RunE: func(cmd *cobra.Command, args []string) error {
return submitAction()
},
}

return cmd
}

func submitAction() error {

Check failure on line 24 in pkg/cmd/checkhealth/checkhealth.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)

fmt.Println("Version: ", constants.Version)
fmt.Println("Configuration path: ", constants.DajeDotfilePath)
fmt.Println("Tuning: ", tuning.IsSystemTuned())

return nil
}
2 changes: 2 additions & 0 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package root
import (
"github.com/spf13/cobra"

Check failure on line 4 in pkg/cmd/root/root.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/spf13/cobra' is not allowed from list 'Main' (depguard)

"github.com/Schrodinger-Hat/Daje/pkg/cmd/checkhealth"

Check failure on line 6 in pkg/cmd/root/root.go

View workflow job for this annotation

GitHub Actions / lint

import 'github.com/Schrodinger-Hat/Daje/pkg/cmd/checkhealth' is not allowed from list 'Main' (depguard)
initCmd "github.com/Schrodinger-Hat/Daje/pkg/cmd/init"
)

Expand All @@ -18,6 +19,7 @@ $ daje init
}

cmd.AddCommand(initCmd.NewCmdInit())
cmd.AddCommand(checkhealth.NewCmdCheckhealth())

return cmd
}

0 comments on commit aae419c

Please sign in to comment.