Skip to content

Commit

Permalink
Merge pull request #28 from bitnami/gonit-go1.18
Browse files Browse the repository at this point in the history
Update to Go 1.18
  • Loading branch information
marcosbc authored May 19, 2022
2 parents 7386fe9 + 53f3baa commit 0080879
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 104 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.16.10' # The Go version to download (if necessary) and use.
go-version: '^1.18.2' # The Go version to download (if necessary) and use.
- name: Install Build Dependencies
run: make get-build-deps
- name: Download required modules
Expand Down
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TOOL_PATH ?= $(DIST_DIR)/$(TOOL_NAME)
all:
@$(MAKE) get-build-deps
@$(MAKE) download
@$(MAKE) -s validate-command-gocovmerge validate-command-golint
@$(MAKE) -s validate-command-gocovmerge validate-command-staticcheck
@$(MAKE) -s parallelizable-steps

parallelizable-steps: vet lint build test race-test cover
Expand All @@ -53,15 +53,14 @@ clean:

get-build-deps:
@echo "+ Downloading build dependencies"
@go get golang.org/x/tools/cmd/goimports
@go get golang.org/x/lint/golint
@go get github.com/wadey/gocovmerge

@go install golang.org/x/tools/cmd/goimports@latest
@go install honnef.co/go/tools/cmd/staticcheck@latest
@go install github.com/wadey/gocovmerge@latest

validate-command-%:
@which $(*F) > /dev/null || (echo "Tool $(*F) must be in your PATH" 2>&1 && exit 1)

vet: $(addprefix vet-, $(VET_PACKAGES))
vet: $(addprefix vet-, $(VET_PACKAGES))
@go vet .

vet-%:
Expand All @@ -70,23 +69,21 @@ vet-%:

lint: $(addprefix lint-, $(LINT_PACKAGES))
@echo "+ $@"
@$(MAKE) -s validate-command-golint
@golint .
@$(MAKE) -s validate-command-staticcheck
@staticcheck ./...
$(call fmtcheck, .)

lint-%:
@echo "+ $@"
@golint ./$(*F)
@staticcheck ./$(*F)
$(call fmtcheck, $(*F))


test: $(addprefix test-, $(PACKAGES))
@echo "+ Testing gonit tool"
@go test .

race-test: $(addprefix race-test-, $(PACKAGES))


cover-%: $(BUILD_DIR)/%.coverprofile
@echo "+ $@"
$(GO_COVER) -html=$^ -o=$(BUILD_DIR)/$(*F).html
Expand Down
1 change: 0 additions & 1 deletion cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func flattenErrors(errors []error) error {
}

type serviceCommand struct {
status string
cmd string
singleCheckCb func(string) error
multicheckCb func() []error
Expand Down
15 changes: 0 additions & 15 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime"
"syscall"

"github.com/VividCortex/godaemon"
"github.com/bitnami/gonit/log"
"github.com/bitnami/gonit/monitor"
"github.com/bitnami/gonit/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -47,19 +45,6 @@ func setupSignals(app *monitor.Monitor) {
}()
}

func printRuntimeDebugStats(l *log.Logger) {
stats := runtime.MemStats{}
runtime.ReadMemStats(&stats)
str := fmt.Sprintf("RUNTIME DEBUG:\n")
for title, value := range map[string]interface{}{
"Routines Running": runtime.NumGoroutine(),
"Memory": fmt.Sprintf("%dKB", stats.Alloc/1024),
} {
str += fmt.Sprintf("%-40s %15v\n", title, value)
}
l.MDebugf(str)
}

// RunMonitor executes the monitor code in an infinite loop with
// the provided configuration
func RunMonitor(c monitor.Config) {
Expand Down
1 change: 1 addition & 0 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var statusCmd = &cobra.Command{
fmt.Fprintf(os.Stderr, "Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (%s)\n", daemonPidFile())
os.Exit(1)

//lint:ignore SA4023 The process is not expected to be running when performing static code check
} else if cm := getChecksManager(); cm != nil {
str := cm.StatusText(args...)
if str != "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var summaryCmd = &cobra.Command{
if !isDaemonRunning() {
fmt.Fprintf(os.Stderr, "Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (%s)\n", daemonPidFile())
os.Exit(1)
//lint:ignore SA4023 The process is not expected to be running when performing static code check
} else if cm := getChecksManager(); cm != nil {
str := cm.SummaryText(args...)
if str != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var versionCmd = &cobra.Command{
if commit != "" {
msg += fmt.Sprintf("Git Commit: %s\n", commit)
}
fmt.Printf(msg)
fmt.Printf("%s\n", msg)
os.Exit(0)
},
}
Expand Down
6 changes: 3 additions & 3 deletions database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
)

func setDbData(db Storer, data map[string]interface{}) []string {
func setDBData(db Storer, data map[string]interface{}) []string {
keys := []string{}
for k, v := range data {
db.Set(k, v)
Expand Down Expand Up @@ -56,7 +56,7 @@ func TestNewFileDatabaseNoFile(t *testing.T) {

assert.False(t, fileExists(dbFile), "File %s should not exists", dbFile)

assert.Equal(t, setDbData(db, sampleData), db.Keys())
assert.Equal(t, setDBData(db, sampleData), db.Keys())

db.Serialize()

Expand All @@ -69,7 +69,7 @@ func TestNewFileDatabaseWithFile(t *testing.T) {
db, err := NewFileDatabase(dbFile)
require.NoError(t, err)

assert.Equal(t, setDbData(db, sampleData), db.Keys())
assert.Equal(t, setDBData(db, sampleData), db.Keys())

db.Serialize()

Expand Down
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
module github.com/bitnami/gonit

go 1.13
go 1.18

require (
github.com/VividCortex/godaemon v1.0.0
github.com/julienschmidt/httprouter v1.3.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359
golang.org/x/tools v0.1.7 // indirect
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
13 changes: 0 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,11 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad h1:W0LEBv82YCGEtcmPA3uNZBI33/qF//HAAs3MawDjRa0=
github.com/wadey/gocovmerge v0.0.0-20160331181800-b5bfa59ec0ad/go.mod h1:Hy8o65+MXnS6EwGElrSRjUzQDLXreJlzYLlWiHtt8hM=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
Expand Down Expand Up @@ -278,7 +275,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
Expand All @@ -290,7 +286,6 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -328,7 +323,6 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -393,9 +387,7 @@ golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik=
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -406,7 +398,6 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -460,14 +451,10 @@ golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.7 h1:6j8CgantCy3yc8JGBqkDLMKWqZ0RDU2g1HVgacojGWQ=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
Expand Down
3 changes: 1 addition & 2 deletions gonit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func (g *GonitDaemon) TearDown() {

type ConfigSuite struct {
suite.Suite
sb *tu.Sandbox
defaultValues map[string]string
sb *tu.Sandbox
}

func (suite *ConfigSuite) AssertPanicsMatch(fn func(), re *regexp.Regexp) bool {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/bitnami/gonit/cmd"
)

var version = "0.2.4"
var version = "0.2.6"
var buildDate = ""
var commit = ""

Expand Down
26 changes: 9 additions & 17 deletions monitor/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ type check struct {
// If not, it won't be automatically started in case of unhandled stops
monitored syncBool
logger Logger
lastCheck time.Time
}

// GetTimeout returns the check Timeout
Expand Down Expand Up @@ -298,7 +297,7 @@ func newCheck(id string, kind string) interface {
func newCheckFromData(data string) (interface {
Checkable
}, error) {
checkPattern := "(\n|^)check\\s+([^\\s]+)\\s+([^\\s]+)((.|\n)*)"
checkPattern := `(\n|^)check\s+([^\s]+)\s+([^\s]+)((.|\n)*)`
re := regexp.MustCompile(checkPattern)
if match := re.FindStringSubmatch(data); match != nil {
kind := match[2]
Expand Down Expand Up @@ -341,13 +340,6 @@ func (c *Command) Exec() {
c.logger.Debug(cmd.Run())
}

func formatColumns(len int, args ...interface{}) string {
res := ""
for _, str := range args {
res += fmt.Sprintf(fmt.Sprintf("%%-%ds", len), fmt.Sprintln(str))
}
return res
}
func (c *ProcessCheck) getStatusString() (str string) {
if c.IsMonitored() {
if c.IsRunning() {
Expand Down Expand Up @@ -570,7 +562,7 @@ func (c *ProcessCheck) Uptime() time.Duration {
if c.startedAt.Get().Equal(time.Time{}) {
return time.Duration(0)
}
return time.Now().Sub(c.startedAt.Get())
return time.Since(c.startedAt.Get())
}

func unquote(str string) string {
Expand All @@ -580,7 +572,7 @@ func unquote(str string) string {
// We should make this generic for all Checks
func parseWithTimeout(data string) (time.Duration, error) {

withTimeoutRe := regexp.MustCompile("with\\s+timeout\\s+([^\\s]+)\\s+(millisecond|second|minute|hour|day)s?")
withTimeoutRe := regexp.MustCompile(`with\s+timeout\s+([^\s]+)\s+(millisecond|second|minute|hour|day)s?`)
t := withTimeoutRe.FindStringSubmatch(data)
if t == nil {
return 0, nil
Expand Down Expand Up @@ -614,13 +606,13 @@ func parseWithTimeout(data string) (time.Duration, error) {
// and loads the specified settings
func (c *ProcessCheck) Parse(data string) {

withRe := regexp.MustCompile("with\\s+([^\\s]+)\\s+([^\\s]+)")
groupRe := regexp.MustCompile("group\\s+([^\\s]+)")
startRe := regexp.MustCompile("start\\s+program\\s+=\\s+(\"[^\"]+\"|[^\\s]+)([^\n]*)")
stopRe := regexp.MustCompile("stop\\s+program\\s+=\\s+(\"[^\"]+\"|[^\\s]+)([^\n]*)")
ifRe := regexp.MustCompile("if\\s+([^\n]+)")
withRe := regexp.MustCompile(`with\s+([^\s]+)\s+([^\s]+)`)
groupRe := regexp.MustCompile(`group\s+([^\\s]+)`)
startRe := regexp.MustCompile(`start\s+program\s+=\s+(\"[^\"]+\"|[^\s]+)([^\n]*)`)
stopRe := regexp.MustCompile(`stop\s+program\s+=\s+(\"[^\"]+\"|[^\s]+)([^\n]*)`)
ifRe := regexp.MustCompile(`if\s+([^\n]+)`)
processOptRe := regexp.MustCompile(
fmt.Sprintf("^[\\s\n]*(%s|%s|%s|%s|%s)",
fmt.Sprintf(`^[\s\n]*(%s|%s|%s|%s|%s)`,
groupRe.String(),
startRe.String(),
stopRe.String(),
Expand Down
12 changes: 0 additions & 12 deletions monitor/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ func (ds *dummyService) getTimesStarted() int {
return ds.timesStarted
}

func (ds *dummyService) setTimesStarted(t int) {
defer ds.Unlock()
ds.Lock()
ds.timesStarted = t
}

func newDummyService(id string) *dummyService {
s := dummyService{ProcessCheck: ProcessCheck{check: &check{ID: id}}}
s.startTime = 5 * time.Millisecond
Expand Down Expand Up @@ -99,12 +93,6 @@ type dummyCheck struct {
waitTime time.Duration
}

func (dc *dummyCheck) getWaitTime() time.Duration {
defer dc.RUnlock()
dc.RLock()
return dc.waitTime
}

func (dc *dummyCheck) setWaitTime(d time.Duration) {
defer dc.Unlock()
dc.Lock()
Expand Down
6 changes: 3 additions & 3 deletions monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (m *Monitor) Uptime() time.Duration {
if m.StartTime.Equal(time.Time{}) {
return time.Duration(0)
}
return time.Now().Sub(m.StartTime)
return time.Since(m.StartTime)
}

// UpdateDatabase updates the file database with the in-memory state
Expand Down Expand Up @@ -257,7 +257,7 @@ func (m *Monitor) Reload() error {
validator := newValidator()
validator.Logger = m.logger
new(configParser).ParseConfigFile(m.ControlFile, validator, m.logger)
if validator.Success == true {
if validator.Success {
m.logger.Printf("Configuration validates, loading it....")
m.checks = nil
for _, c := range validator.Checks {
Expand All @@ -277,7 +277,7 @@ func (m *Monitor) Reload() error {
func (m *Monitor) RuntimeDebugStats() string {
stats := runtime.MemStats{}
runtime.ReadMemStats(&stats)
str := fmt.Sprintf("RUNTIME DEBUG:\n")
str := "RUNTIME DEBUG:\n"
for title, value := range map[string]interface{}{
"Routines Running": runtime.NumGoroutine(),
"Memory": fmt.Sprintf("%dKB", stats.Alloc/1024),
Expand Down
Loading

0 comments on commit 0080879

Please sign in to comment.