-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from timfanda35/features/agnhost/clone
Features/agnhost/clone
- Loading branch information
Showing
10 changed files
with
654 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# 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/ | ||
target/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# GoLand | ||
.idea | ||
|
||
# macOS | ||
.DS_Store | ||
|
||
# git | ||
.git/ | ||
.github/ |
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,59 @@ | ||
name: Docker | ||
|
||
on: | ||
push: | ||
# Publish `main` as Docker `latest` image. | ||
branches: | ||
- main | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
# Run tests for any PRs. | ||
pull_request: | ||
|
||
env: | ||
IMAGE_NAME: grpc-health-checking | ||
|
||
jobs: | ||
# Push image to GitHub Packages. | ||
# See also https://docs.docker.com/docker-hub/builds/ | ||
push: | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME | ||
|
||
- name: Log into registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
|
||
- name: Push image | ||
run: | | ||
IMAGE_ID=ghcr.io/${{ github.repository }} | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Strip "v" prefix from tag name | ||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
# Use Docker `latest` tag convention | ||
[ "$VERSION" == "main" ] && VERSION=latest | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Builder | ||
FROM golang:1.21 as builder | ||
|
||
WORKDIR /src | ||
COPY . /src | ||
|
||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /bin/grpc-health-checking main.go | ||
|
||
# App | ||
FROM scratch | ||
|
||
COPY --from=builder /bin/grpc-health-checking /bin/grpc-health-checking | ||
|
||
EXPOSE 8000 | ||
EXPOSE 8080 | ||
|
||
ENTRYPOINT ["/bin/grpc-health-checking"] |
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,15 @@ | ||
GOPATH = $(shell go env GOPATH) | ||
|
||
.PHONY: compile | ||
compile: compile-server | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf target | ||
|
||
target: | ||
mkdir target | ||
|
||
.PHONY: compile-server | ||
compile-server: target | ||
go build -o target/grpc-health-checking ./main.go |
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,2 +1,156 @@ | ||
# grpchealthchecking | ||
# GRPC Health Checking | ||
|
||
A GRPC Health Checking Test Application | ||
|
||
Based on https://github.com/kubernetes/kubernetes/blob/master/test/images/agnhost/grpc-health-checking/grpc-health-checking.go | ||
|
||
## Usage | ||
|
||
Compile | ||
|
||
```bash | ||
make compile | ||
``` | ||
|
||
Execute | ||
|
||
```bash | ||
./target/grpc-health-checking | ||
``` | ||
|
||
It shows logs: | ||
|
||
``` | ||
I1029 15:02:02.769553 85361 log.go:245] Http server starting to listen on :8080 | ||
I1029 15:02:02.770155 85361 log.go:245] gRPC server starting to listen on :8000 | ||
``` | ||
|
||
You can use `-h` to see the help: | ||
|
||
``` | ||
Usage: | ||
grpc-health-checking [flags] | ||
Flags: | ||
--delay-unhealthy-sec int Number of seconds to delay before start reporting NOT_SERVING, negative value indicates never. (default -1) | ||
-h, --help help for grpc-health-checking | ||
--http-port int Port number for the /make-serving, /make-not-serving and /healthcheck. (default 8080) | ||
--log-flush-frequency duration Maximum number of seconds between log flushes (default 5s) | ||
--port int Port number. (default 8000) | ||
--service string Service name to register the health check for. | ||
-v, --v Level number for the log level verbosity | ||
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging (only works for the default text log format) | ||
``` | ||
|
||
## Access the endpoints | ||
|
||
Set the HOST environment variable for convenience | ||
|
||
```bash | ||
HOST=localhost | ||
``` | ||
We can use the `curl` to access HTTP Endpoint. | ||
|
||
We can use the [grpcurl](https://github.com/fullstorydev/grpcurl) to access GRPC Endpoint. | ||
|
||
### HTTP Endpoint: `/healthcheck` | ||
|
||
Access HTTP Health Check | ||
|
||
```bash | ||
curl $HOST:8080/healthcheck | ||
``` | ||
|
||
Output should be like: | ||
|
||
``` | ||
2m55.563755666s | ||
``` | ||
|
||
### HTTP Endpoint: `/make-serving` | ||
|
||
Make GRPC Health Check serving | ||
|
||
```bash | ||
curl $HOST:8080/make-serving | ||
``` | ||
|
||
### HTTP Endpoint: `/make-not-serving` | ||
|
||
Make GRPC Health Check not serving | ||
|
||
```bash | ||
curl $HOST:8080/make-not-serving | ||
``` | ||
|
||
### GRPC Endpoint: `Services List` | ||
|
||
List GRPC Services with reflection. | ||
|
||
```bash | ||
grpcurl -plaintext $HOST:8000 list | ||
``` | ||
|
||
Output should be: | ||
|
||
``` | ||
grpc.health.v1.Health | ||
grpc.reflection.v1.ServerReflection | ||
grpc.reflection.v1alpha.ServerReflection | ||
``` | ||
|
||
### GRPC Endpoint: `GRPC Health Check` | ||
|
||
Check GRPC Service Healthy status. | ||
|
||
```bash | ||
grpcurl -plaintext $HOST:8000 grpc.health.v1.Health/Check | ||
``` | ||
|
||
If serving: | ||
|
||
``` | ||
{ | ||
"status": "SERVING" | ||
} | ||
``` | ||
|
||
Otherwise: | ||
|
||
``` | ||
{ | ||
"status": "NOT_SERVING" | ||
} | ||
``` | ||
|
||
## Containerize | ||
|
||
Build image | ||
|
||
```bash | ||
docker build -t grpc-health-checking . | ||
``` | ||
|
||
Run image with default expose ports | ||
|
||
```bash | ||
docker run -it \ | ||
-p 8000:8000 \ | ||
-p 8080:8080 \ | ||
grpc-health-checking | ||
``` | ||
|
||
Run image with customize ports | ||
|
||
```bash | ||
docker run -it \ | ||
-p 18000:18000 \ | ||
-p 18080:18080 \ | ||
grpc-health-checking --port 18000 --http-port 18080 | ||
``` | ||
|
||
You can also use the pre-build amd64 container image | ||
|
||
``` | ||
ghcr.io/timfanda35/grpc-health-checking | ||
``` |
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,43 @@ | ||
module grpchealthchecking | ||
|
||
go 1.21.1 | ||
|
||
require ( | ||
github.com/spf13/cobra v1.7.0 | ||
google.golang.org/grpc v1.59.0 | ||
k8s.io/component-base v0.28.3 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/blang/semver/v4 v4.0.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/go-logr/logr v1.2.4 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/go-cmp v0.5.9 // indirect | ||
github.com/google/gofuzz v1.2.0 // indirect | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/kr/text v0.2.0 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/prometheus/client_golang v1.16.0 // indirect | ||
github.com/prometheus/client_model v0.4.0 // indirect | ||
github.com/prometheus/common v0.44.0 // indirect | ||
github.com/prometheus/procfs v0.10.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
k8s.io/apimachinery v0.28.3 // indirect | ||
k8s.io/klog/v2 v2.100.1 // indirect | ||
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect | ||
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect | ||
) |
Oops, something went wrong.