Skip to content

Commit

Permalink
feat: Release 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
javier.juarez authored and javier.juarez committed Feb 9, 2023
1 parent e63c9e0 commit d9673f0
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 13 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]


## [0.2.0] - 2023-02-09
### Added
* Logging support using [logrus](https://github.com/sirupsen/logrus)

### Changed
* Minor changes to adjust the version generation

### Removed

### Fixed
* The exit from all the commands should be controlled


## [0.1.0] - 2023-02-08
### Added
* Docker support
Expand All @@ -32,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed


[Unreleased]: https://github.com/jjuarez/simple-prober/compare/0.1.0...HEAD
[Unreleased]: https://github.com/jjuarez/simple-prober/compare/0.2.0...HEAD
[0.2.0]: https://github.com/jjuarez/simple-prober/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/jjuarez/simple-prober/compare/0.0.0...0.1.0
[0.0.0]: https://github.com/jjuarez/simple-prober/tree/0.0.0
7 changes: 7 additions & 0 deletions ci/deployment/k8s/chart/simple-prober/values-production.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: simple-prober
cron:
scheduledExpression: "0 * * * *"

image:
tag: latest
2 changes: 1 addition & 1 deletion ci/deployment/k8s/chart/simple-prober/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: simple-prober
istio: false
cron:
scheduledExpression: "0 * * * *"
scheduledExpression: "* * * * *"
failedJobsHistoryLimit: 3
concurrencyPolicy: Replace

Expand Down
25 changes: 22 additions & 3 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ package cmd

import (
"fmt"
"log"
"time"

"github.com/jjuarez/simple-prober/internal/codes"
"github.com/jjuarez/simple-prober/internal/config"
"github.com/jjuarez/simple-prober/internal/logger"
"github.com/jjuarez/simple-prober/internal/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

const (
defaultConfigFileName string = "./config/endpoints.yaml"
defaultTimeout int = 5
defaultLogLevel string = "info"
)

var (
configFileName string
timeout time.Duration
logLevel string
)

// checkCmd represents the check command
Expand All @@ -29,16 +32,25 @@ var checkCmd = &cobra.Command{
Long: `This command will check for all the endpoints located in the configuration file, here's an usage example:
simple-prober check --config config/endpoints.yaml`,
Run: func(cmd *cobra.Command, args []string) {
// Logger setup
if err := logger.Setup(logLevel); err != nil {
utils.ExitCommand(codes.ConfigurationError, err)
}
log.Debug(fmt.Sprintf("Logger setup as: %q", logLevel))

// Configuration load
eList, err := config.Load(configFileName)
if err != nil {
utils.ExitCommand(codes.ReadError, err)
}

// Connection tests
for _, e := range *eList {
r, err := e.TestConnection(timeout)
if err != nil {
log.Println(err)
log.Error(err)
}
fmt.Printf("%v, %v\n", e, r)
log.Info(fmt.Sprintf("%v, %v\n", e, r))
}
},
}
Expand All @@ -47,7 +59,14 @@ func init() {
var parameterTimeout int

rootCmd.AddCommand(checkCmd)

// The log level
rootCmd.PersistentFlags().StringVar(&logLevel, "loglevel", defaultLogLevel, "The log level")

// The confiuration file name
rootCmd.PersistentFlags().StringVar(&configFileName, "config", defaultConfigFileName, "Config file (default is: config/endpoints.yaml)")

// The connection timeout
rootCmd.PersistentFlags().IntVar(&parameterTimeout, "timeout", defaultTimeout, "Connection timeout")
timeout = time.Duration(parameterTimeout) * time.Second
}
7 changes: 3 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
package cmd

import (
"os"

"github.com/jjuarez/simple-prober/internal/codes"
"github.com/jjuarez/simple-prober/internal/utils"
"github.com/spf13/cobra"
)

Expand All @@ -27,10 +27,9 @@ var rootCmd = &cobra.Command{
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
utils.ExitCommand(codes.UnknownError, err)
}
}

func init() {
// Init of the commands.
}
3 changes: 3 additions & 0 deletions config/endpoints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
- name: Google
kind: Web
address: www.google.com:80
- name: Fail
kind: Web
address: www.example.com:8445
...
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require github.com/spf13/cobra v1.6.1

require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 6 additions & 0 deletions internal/codes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ package codes
type Code int

const (
// UnknownError ...
UnknownError Code = 1000

// ReadError ...
ReadError Code = 1001
// UnmarshalError ...
UnmarshalError Code = 1002

// ConfigurationError ...
ConfigurationError Code = 1003
)
1 change: 0 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
yaml "gopkg.in/yaml.v3"
)

// LoadFile This function load the content of the configuration file.
func loadFile(configFileName string) ([]byte, error) {
var err error
var fileContent []byte
Expand Down
21 changes: 21 additions & 0 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Package logger The logger support for the CLI app.
package logger

import (
"os"

log "github.com/sirupsen/logrus"
)

// Setup This function configures the logger.
func Setup(logLevel string) error {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)

level, err := log.ParseLevel(logLevel)
if err != nil {
return err
}
log.SetLevel(level)
return nil
}
2 changes: 1 addition & 1 deletion internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func New(name string, kind string, address string) *Endpoint {

// String Implements the Stingable interface for Endpoint.
func (e Endpoint) String() string {
return fmt.Sprintf("%T: { name:%s, kind:%s, address:%s }", e, e.Name, e.Kind, e.Address)
return fmt.Sprintf("%T(name:%s, kind:%s, address:%s)", e, e.Name, e.Kind, e.Address)
}

// Println Implements the Printable interface for Endpoint.
Expand Down
4 changes: 2 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
package utils

import (
"log"
"os"

"github.com/jjuarez/simple-prober/internal/codes"
log "github.com/sirupsen/logrus"
)

// ExitCommand This function implements a simple way to exit from the commands.
func ExitCommand(exitCode codes.Code, err error) {
if err != nil {
log.Println(err)
log.Error(err)
}
os.Exit(int(exitCode))
}

0 comments on commit d9673f0

Please sign in to comment.