-
Notifications
You must be signed in to change notification settings - Fork 248
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
Refactoring for better separation of concerns #110
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
80be22d
httpchecker: pass host header to http request
titpetric ba57107
cleanup: A larger rework/cleanup
titpetric 5ed18db
notifier slack: prevent swallowing errors
titpetric ba94c0e
chore: fixing formatting issues with gofmt
titpetric 8ad096d
Makefile: revert to go test, add go fmt ./...
titpetric 603b070
checkup: update checks, notifiers and storage with types
titpetric 687e65d
feature: add mail notifier and docs
titpetric 31bd327
Makefile: tune test verbosity to non-verbose
titpetric 19203b6
checkup: Fix type names in configs for consistency
titpetric fdb4608
sql storage: fix compile error, add build-sql target into makefile
titpetric f5a941e
documentation: update to reflect recent changes and additions
titpetric b17f4c1
chore: added go mod tidy as a build step to clean up go.mod/sum files
titpetric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
.PHONY: all build test docker | ||
.PHONY: all build build-sql test docker | ||
|
||
all: build test | ||
|
||
DOCKER_IMAGE := checkup | ||
|
||
build: | ||
go fmt ./... | ||
go mod tidy | ||
mkdir -p builds/ | ||
go build -o builds/ ./cmd/... | ||
|
||
build-sql: | ||
go fmt ./... | ||
go mod tidy | ||
go build -o builds/ -tags sql ./cmd/... | ||
|
||
test: | ||
go test -race -count=1 -v ./... | ||
go test -race -count=1 ./... | ||
|
||
docker: | ||
docker build --no-cache . -t $(DOCKER_IMAGE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,20 @@ Checkup was created by Matt Holt, author of the [Caddy web server](https://caddy | |
|
||
This tool is a work-in-progress. Please use liberally (with discretion) and report any bugs! | ||
|
||
## Recent changes | ||
|
||
Due to recent development, some breaking changes have been introduced: | ||
|
||
- providers: the json config field `provider` was renamed to `type` for consistency, | ||
- notifiers: the json config field `name` was renamed to `type` for consistency, | ||
- sql: by default the sqlite storage engine is disabled (needs build with `-tags sql` to enable), | ||
|
||
If you want to build the latest version, it's best to run: | ||
|
||
- `make build` - builds checkup without sql support, | ||
- `make build-sql` - builds checkup with pgsql/sqlite; | ||
|
||
The resulting binary will be placed into `builds/checkup`. | ||
|
||
## Intro | ||
|
||
|
@@ -76,9 +89,9 @@ You can configure Checkup entirely with a simple JSON document. You should confi | |
// storage configuration goes here | ||
}, | ||
|
||
"notifier": { | ||
"notifiers": [ | ||
// notifier configuration goes here | ||
} | ||
] | ||
} | ||
``` | ||
|
||
|
@@ -90,7 +103,7 @@ Here are the configuration structures you can use, which are explained fully [in | |
|
||
#### HTTP Checkers | ||
|
||
**[godoc: HTTPChecker](https://godoc.org/github.com/sourcegraph/checkup#HTTPChecker)** | ||
**[godoc: HTTPChecker](https://godoc.org/github.com/sourcegraph/checkup/check/http)** | ||
|
||
```js | ||
{ | ||
|
@@ -104,7 +117,7 @@ Here are the configuration structures you can use, which are explained fully [in | |
|
||
#### TCP Checkers | ||
|
||
**[godoc: TCPChecker](https://godoc.org/github.com/sourcegraph/checkup#TCPChecker)** | ||
**[godoc: TCPChecker](https://godoc.org/github.com/sourcegraph/checkup/check/tcp)** | ||
|
||
```js | ||
{ | ||
|
@@ -116,7 +129,7 @@ Here are the configuration structures you can use, which are explained fully [in | |
|
||
#### DNS Checkers | ||
|
||
**[godoc: DNSChecker](https://godoc.org/github.com/sourcegraph/checkup#DNSChecker)** | ||
**[godoc: DNSChecker](https://godoc.org/github.com/sourcegraph/checkup/check/dns)** | ||
|
||
```js | ||
{ | ||
|
@@ -129,7 +142,7 @@ Here are the configuration structures you can use, which are explained fully [in | |
|
||
#### TLS Checkers | ||
|
||
**[godoc: TLSChecker](https://godoc.org/github.com/sourcegraph/checkup#TLSChecker)** | ||
**[godoc: TLSChecker](https://godoc.org/github.com/sourcegraph/checkup/check/tls)** | ||
|
||
```js | ||
{ | ||
|
@@ -142,11 +155,11 @@ Here are the configuration structures you can use, which are explained fully [in | |
|
||
#### Amazon S3 Storage | ||
|
||
**[godoc: S3](https://godoc.org/github.com/sourcegraph/checkup#S3)** | ||
**[godoc: S3](https://godoc.org/github.com/sourcegraph/checkup/check/s3)** | ||
|
||
```js | ||
{ | ||
"provider": "s3", | ||
"type": "s3", | ||
"access_key_id": "<yours>", | ||
"secret_access_key": "<yours>", | ||
"bucket": "<yours>", | ||
|
@@ -159,11 +172,11 @@ S3 is the default storage provider assumed by the status page, so the only chang | |
|
||
#### File System Storage | ||
|
||
**[godoc: FS](https://godoc.org/github.com/sourcegraph/checkup#FS)** | ||
**[godoc: FS](https://godoc.org/github.com/sourcegraph/checkup/storage/fs)** | ||
|
||
```js | ||
{ | ||
"provider": "fs", | ||
"type": "fs", | ||
"dir": "/path/to/your/check_files", | ||
"url": "http://127.0.0.1:2015/check_files" | ||
} | ||
|
@@ -180,11 +193,11 @@ Then fill out [config.js](https://github.com/sourcegraph/checkup/blob/master/sta | |
|
||
#### GitHub Storage | ||
|
||
**[godoc: GitHub](https://godoc.org/github.com/sourcegraph/checkup#GitHub)** | ||
**[godoc: GitHub](https://godoc.org/github.com/sourcegraph/checkup/storage/github)** | ||
|
||
```js | ||
{ | ||
"provider": "github", | ||
"type": "github", | ||
"access_token": "some_api_access_token_with_repo_scope", | ||
"repository_owner": "owner", | ||
"repository_name": "repo", | ||
|
@@ -209,22 +222,22 @@ Where "dir" is a subdirectory within the repo to push all the check files. Setup | |
|
||
#### SQL Storage (sqlite3/PostgreSQL) | ||
|
||
**[godoc: SQL](https://godoc.org/github.com/sourcegraph/checkup#SQL)** | ||
**[godoc: SQL](https://godoc.org/github.com/sourcegraph/checkup/storage/sql)** | ||
|
||
Postgres or sqlite3 databases can be used as storage backends. | ||
|
||
sqlite database file configuration: | ||
```js | ||
{ | ||
"provider": "sql", | ||
"type": "sql", | ||
"sqlite_db_file": "/path/to/your/sqlite.db" | ||
} | ||
``` | ||
|
||
postgresql database file configuration: | ||
```js | ||
{ | ||
"provider": "sql", | ||
"type": "sql", | ||
"postgresql": { | ||
"user": "postgres", | ||
"dbname": "dbname", | ||
|
@@ -251,7 +264,7 @@ Currently the status page does not support SQL storage. | |
Enable notifications in Slack with this Notifier configuration: | ||
```js | ||
{ | ||
"name": "slack", | ||
"type": "slack", | ||
"username": "username", | ||
"channel": "#channel-name", | ||
"webhook": "webhook-url" | ||
|
@@ -260,6 +273,26 @@ Enable notifications in Slack with this Notifier configuration: | |
|
||
Follow these instructions to [create a webhook](https://get.slack.help/hc/en-us/articles/115005265063-Incoming-WebHooks-for-Slack). | ||
|
||
#### Mail notifier | ||
|
||
Enable E-mail notifications with this Notifier configuration: | ||
```js | ||
{ | ||
"type": "mail", | ||
"from": "[email protected]", | ||
"to": [ "[email protected]", "[email protected]" ], | ||
"subject": "Custom subject line", | ||
"smtp": { | ||
"server": "smtp.example.com", | ||
"port": 25, | ||
"username": "username", | ||
"password": "password" | ||
} | ||
} | ||
``` | ||
|
||
The settings for `subject`, `smtp.port` (default to 25), `smtp.username` and `smtp.password` are optional. | ||
|
||
## Setting up storage on S3 | ||
|
||
The easiest way to do this is to give an IAM user these two privileges (keep the credentials secret): | ||
|
@@ -453,34 +486,18 @@ You can implement your own Checker and Storage types. If it's general enough, fe | |
|
||
### Building Locally | ||
|
||
Requires Go v1.10 or newer. | ||
Requires Go v1.13 or newer. | ||
|
||
```bash | ||
git clone [email protected]:sourcegraph/checkup.git | ||
cd checkup/cmd/checkup/ | ||
|
||
# Install dependencies | ||
go get -v -d | ||
|
||
# Build binary | ||
go build -v -ldflags '-s' -o ../../checkup | ||
|
||
# Run tests | ||
go test -race ../../ | ||
cd checkup | ||
make | ||
``` | ||
|
||
### Building with Docker | ||
Building the SQL enabled version is done with `make build-sql`. | ||
|
||
Linux binary: | ||
|
||
```bash | ||
git clone [email protected]:sourcegraph/checkup.git | ||
cd checkup | ||
docker pull golang:latest | ||
docker run --net=host --rm \ | ||
-v `pwd`:/project \ | ||
-w /project golang bash \ | ||
-c "cd cmd/checkup; go get -v -d; go build -v -ldflags '-s' -o ../../checkup" | ||
``` | ||
### Building a Docker image | ||
|
||
This will create a checkup binary in the root project folder. | ||
If you would like to run checkup in a docker container, building it is done by running `make docker`. | ||
It will build the version without sql support. An SQL supported docker image is currently not provided, | ||
but there's a plan to do that in the future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package checkup | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/sourcegraph/checkup/check/dns" | ||
"github.com/sourcegraph/checkup/check/exec" | ||
"github.com/sourcegraph/checkup/check/http" | ||
"github.com/sourcegraph/checkup/check/tcp" | ||
"github.com/sourcegraph/checkup/check/tls" | ||
) | ||
|
||
func checkerDecode(typeName string, config json.RawMessage) (Checker, error) { | ||
switch typeName { | ||
case dns.Type: | ||
return dns.New(config) | ||
case exec.Type: | ||
return exec.New(config) | ||
case http.Type: | ||
return http.New(config) | ||
case tcp.Type: | ||
return tcp.New(config) | ||
case tls.Type: | ||
return tls.New(config) | ||
default: | ||
return nil, fmt.Errorf(errUnknownCheckerType, typeName) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's any way to call this out more aggressively, that would be great! Perhaps a CHANGELOG? My crons stopped running overnight due to (1) me using r.j3ss.co/checkup:latest, which tracks HEAD and (2) these changes. Specifically, the
provider
->type
change forstorage
caught me. For anyone relying on HEAD for their production checks, this is likely to bite them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very sorry about that. It was a risk I was aware of when I was cleaning up the code for this, and I just hoped people aren't blindly doing nightly/HEAD builds, and tried to make it as obvious as possible that there was a breaking change introduced by prominently updating the README at the very top.
Aside from adding a CHANGELOG file,
And finally, we could automate the release process in line with what we choose above (#96). There are also a number of issues that could be solved by having a rolling release model:
The current releases are woefully out of date. I'm voting to remove them, keep the development on master, branch to v0 before the breaking changes (f4747239), and branch into v1 later when we feel the release is pretty stable and non-breaking.
@beyang thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@parkr sorry this bit you. We don't have a good sense of who's using this at the moment, so yes, we should probably adopt a versioning system as @titpetric proposes. @titpetric the model you propose sounds good to me. I'd propose this model:
master
is the development branchv1.0.0
(the last commit before @titpetric's recent changes) andv2.0.0
(the latestmaster
commit). I've also pushed a1.0
branch in case we want to cut any new patches off the older version@titpetric feel free to push up a
CHANGELOG
file as well. Also not we did publish release notes for early versions of Checkup: https://github.com/sourcegraph/checkup/releases.