Skip to content

Commit

Permalink
[FEAT] adding health and ready endpoints
Browse files Browse the repository at this point in the history
[FEAT] adding health and ready endpoints
  • Loading branch information
nicolastakashi authored Oct 19, 2021
2 parents a799bc9 + 497e3ed commit 22a9131
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ Flags:
-h, --help help for sync
--http.port string listem port for http endpoints (default ":9754")
--kubeconfig string (optional) absolute path to the kubeconfig file
--log.level string listem port for http endpoints (default "info")
--log.level string log level (default "info")
--namespace string namespace that will store the dashboard config map (default "default")
--repository.auth.password string password to perform authentication
--repository.auth.username string username to perform authentication
--repository.branch string path to clone the git repository (default "main")
--repository.path string path to clone the git repository
--repository.branch string git repository branch (default "main")
--repository.url string git repository url
--sync-timer duration interval to sync and sync dashboards (default 5m0s)
--sync-timer duration interval to sync and sync dashboards (default 5m)

```

Expand All @@ -33,7 +32,7 @@ Contributions are very welcome! See our [CONTRIBUTING.md](CONTRIBUTING.md) for m

## Docker images

Docker images are available on [Docker Hub](https://hub.docker.com/repository/docker/ntakashi/gitana).
Docker images are available on [Docker Hub](https://hub.docker.com/r/ntakashi/gitana).

## Building from source

Expand Down
34 changes: 34 additions & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cmd

import (
"context"
"encoding/json"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -49,6 +50,7 @@ var syncCmd = &cobra.Command{
logrus.Info("Welcome to gitana...")

if err := pcmd.Validate(); err != nil {
logrus.Error(err)
os.Exit(1)
}

Expand Down Expand Up @@ -108,6 +110,38 @@ func createHttpServer(port string) *http.Server {
mux := http.NewServeMux()

mux.Handle("/metrics", promhttp.Handler())
mux.HandleFunc("/-/health", func(rw http.ResponseWriter, _ *http.Request) {
rw.WriteHeader(http.StatusOK)
rw.Header().Set("Content-Type", "application/json")

resp := map[string]string{
"message": "Healthy",
}

jsonResp, err := json.Marshal(resp)

if err != nil {
log.Fatalf("Error happened in JSON marshal. Err: %s", err)
}

rw.Write(jsonResp)
})
mux.HandleFunc("/-/ready", func(rw http.ResponseWriter, _ *http.Request) {
rw.WriteHeader(http.StatusOK)
rw.Header().Set("Content-Type", "application/json")

resp := map[string]string{
"message": "Ready",
}

jsonResp, err := json.Marshal(resp)

if err != nil {
log.Fatalf("Error happened in JSON marshal. Err: %s", err)
}

rw.Write(jsonResp)
})

srv := &http.Server{
Addr: port,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/xanzy/ssh-agent v0.3.1 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/net v0.0.0-20210929161516-d455829e376d // indirect
Expand Down

0 comments on commit 22a9131

Please sign in to comment.