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

[v1.7.0] - Release/update dependencies include custom kind update docs #18

Merged
merged 8 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: 'bug'
assignees: '@gritzkoo'

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---

<!-- Put everything you whant here -->
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
26 changes: 26 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Golang Health Checker PR

Thanks for helping upgrade this package!

## What king of changes this PR produces?

- [ ] Bug fix
- [ ] go.mod dependency updates
- [ ] Refactoring
- [ ] CI related changes
- [ ] New Feature
- [ ] Documentation updates
- [ ] Others, please describe: ...

//

## Describe what problems this PR is doing!

//

## This PR produce a `BREAKING CHAGES` ?

- [ ] Yes (please comment below the changes!)
- [ ] No

//
19 changes: 19 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v3
- name: setup golang
uses: actions/setup-go@v1
with:
go-version: "1.20"
- name: build package
env:
CGO_ENABLED: 0
GOOS: linux
run: |
go mod tidy
go build -a -installsuffix cgo -o entrypoint
16 changes: 12 additions & 4 deletions .github/workflows/main.yaml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: test
on: [push, pull_request]
on: [push]
jobs:

test:
runs-on: ubuntu-latest
strategy:
matrix:
redis-version: [6]
go: ["1.17", "1.18"]
go: ["1.20"]
steps:
- uses: actions/checkout@v2
- name: Sets up a Memcached server
Expand All @@ -19,7 +18,10 @@ jobs:
- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
- run: go test -v -coverprofile=profile.cov ./...
- name: install deps
run: go mod tidy
- name: run test
run: go test -v -coverprofile=profile.cov ./...

- name: Send coverage to coverall.io
uses: shogo82148/actions-goveralls@v1
Expand Down Expand Up @@ -47,5 +49,11 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: rymndhng/release-on-push-action@master
id: release_package
with:
bump_version_scheme: patch
- name: update go.pkg.dev with new version
env:
VERSION: ${{steps.release_package.outputs.version}}
run: curl https://sum.golang.org/lookup/github.com/${GITHUB_REPOSITORY}@${VERSION}

20 changes: 5 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
vendor/
coverage.out
profile.cov
./healthchecker
.vscode
main.go
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test:
go test -coverprofile=profile.cov ./...
coverage: test
go tool cover -html=profile.cov
build:
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o healthchecker pkg/**/*.go
view-docs:
godoc -http=:8331
run:
go run main.go
install-godoc:
go install golang.org/x/tools/cmd/godoc@latest
109 changes: 71 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# golang-health-checker

![test](https://github.com/gritzkoo/golang-health-checker/workflows/test/badge.svg?branch=master)
[![Build Status](https://travis-ci.org/gritzkoo/golang-health-checker.svg?branch=master)](https://travis-ci.org/gritzkoo/golang-health-checker)
[![build](https://github.com/gritzkoo/golang-health-checker/actions/workflows/build.yaml/badge.svg)](https://github.com/gritzkoo/golang-health-checker/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/gritzkoo/golang-health-checker/badge.svg?branch=master)](https://coveralls.io/github/gritzkoo/golang-health-checker?branch=master)
![views](https://raw.githubusercontent.com/gritzkoo/golang-health-checker/traffic/traffic-golang-health-checker/views.svg)
![views per week](https://raw.githubusercontent.com/gritzkoo/golang-health-checker/traffic/traffic-golang-health-checker/views_per_week.svg)
Expand All @@ -20,15 +20,19 @@ A simple package to allow you to track your application healthy providing two wa

*__Detailed__*: will return a detailed status for any integration configuration informed on the integrations, just like in the examples below

___
>This package has a `lightweight` version with no extra dependencies. If you are looking to something more simple, please check [golnag-health-checker-lw on github](https://github.com/gritzkoo/golang-health-checker-lw "golang health checker lightweight") or [golang-health-checke-lw at go.pkg.dev](https://pkg.go.dev/github.com/gritzkoo/golang-health-checker-lw "golang health checker lightweight at go.pkg.dev")
___

## How to install

If you are just starting a Go projetct you must start a go.mod file like below
If you are just starting a Go project you must start a go.mod file like below

```sh
go mod init github.com/my/repo
```

Or else, you already has a started project, just run the command below
Or else, if you already have a started project, just run the command below

```sh
go get github.com/gritzkoo/golang-health-checker
Expand All @@ -38,13 +42,14 @@ go get github.com/gritzkoo/golang-health-checker

In this example, we will use the Echo web server to show how to import and use *Simple* and *Detailed* calls.

If you want check the full options in configurations, look this [IntegrationConfig struct](https://github.com/gritzkoo/golang-health-checker/blob/master/pkg/healthcheck/structs.go#L45-L54)
If you want to check the full options in configurations, look at this [IntegrationConfig struct](https://github.com/gritzkoo/golang-health-checker/blob/master/pkg/healthcheck/structs.go#L45-L54)

### Available integrations

- [x] Redis
- [x] Memcached
- [x] Web integration (https)
- [x] Customized test functions

```go
package main
Expand Down Expand Up @@ -105,6 +110,16 @@ func main() {
Value: "application/json",
},
},
}, {
Type: healthcheck.Custom, // this prop will determine the kind of check, the list of types available in structs.go
Name: "Testing my customized function", // the name of you integration to display in response
Host: "Some info to help debug",
Handle: func() error {
// do wherever test you need using the code of your
// aplication and return an error or nil
// good examples of use is test DB connections, AWS services like SQS SNS S3 DYNAMODB, ETC
return nil
},
},
},
}
Expand Down Expand Up @@ -142,11 +157,18 @@ And detailed call will return a JSON as below
"url": "https://github.com/status",
"errors": "unsuported type of:unknown"
},
{
"name": "Testing my customized function",
"kind": "Customized test function",
"status": true,
"response_time": 0,
"url": "Some info to help debug"
},
{
"name": "Memcached server",
"kind": "Memcached DB",
"status": true,
"response_time": 0.000419116,
"response_time": 4,
"url": "localhost:11211"
},
{
Expand All @@ -169,41 +191,52 @@ And detailed call will return a JSON as below

## Kubernetes liveness and readiness probing

And then, you could call this endpoints manually to see your application health, but, if you are using modern kubernetes deployment, you can config your chart to check your application with the setup below:
And then, you could call these endpoints manually to see your application health, but, if you are using modern kubernetes deployment, you can config your chart to check your application with the setup below:

```yaml
apiVersion: v1
kind: Pod
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
test: liveness
name: liveness-http
name: my-golang-app
spec:
containers:
- name: liveness
image: 'go' #your application image
args:
- /server
livenessProbe:
httpGet:
path: /health-check/liveness
port: 80
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
- name: readiness
image: 'go' #your application image
args:
- /server
readinessProbe:
httpGet:
path: /health-check/readiness
port: 80
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
selector:
matchLabels:
app: my-golang-app
template:
metadata:
labels:
app: my-golang-app
spec:
containers:
- name: my-golang-app
image: your-app-image:tag
resources:
request:
cpu: 10m
memory: 5Mi
limits:
cpu: 50m
memory: 50Mi
livenessProbe:
httpGet:
path: /health-check/liveness
port: 8888
scheme: http
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 2
successThreshold: 1
readinessProbe:
httpGet:
path: /health-check/liveness
port: 8888
scheme: http
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 2
successThreshold: 1
ports:
- containerPort: 8888
```
9 changes: 6 additions & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ services:
test:
&default
container_name: golang_app
image: golang:1.18-alpine
image: golang:1.20-alpine
working_dir: /app
command: sh -c "go test -v ./..."
environment:
- CGO_ENABLED=0
- GOOS=linux
CGO_ENABLED: 0
GOOS: linux
REDIS_HOST: redis
MEMCACHE_HOST: memcache

volumes:
- .:/app
- godir:/go
Expand Down
Loading