File tree Expand file tree Collapse file tree 5 files changed +88
-6
lines changed Expand file tree Collapse file tree 5 files changed +88
-6
lines changed Original file line number Diff line number Diff line change @@ -53,14 +53,17 @@ spec:
53
53
- name : metrics
54
54
containerPort : {{ .Values.configuration.metrics.port }}
55
55
protocol : TCP
56
+ - name : probes
57
+ containerPort : {{ .Values.configuration.probes_port }}
58
+ protocol : TCP
56
59
livenessProbe :
57
60
httpGet :
58
61
path : /
59
- port : http
62
+ port : probes
60
63
readinessProbe :
61
64
httpGet :
62
65
path : /
63
- port : http
66
+ port : probes
64
67
resources :
65
68
{{- toYaml .Values.resources | nindent 12 }}
66
69
{{- with .Values.nodeSelector }}
Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ configuration:
25
25
# Whether to print http logs to stdout
26
26
http_logs : true
27
27
28
+ # The port the health/readiness probes listen on
29
+ probes_port : 9744
30
+
28
31
# Whether to expose prompage metrics
29
32
metrics :
30
33
enabled : false
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
10
10
"syscall"
11
11
12
12
"github.com/henrywhitaker3/prompage/internal/app"
13
+ "github.com/henrywhitaker3/prompage/internal/health"
13
14
"github.com/henrywhitaker3/prompage/internal/http"
14
15
"github.com/henrywhitaker3/prompage/internal/metrics"
15
16
"github.com/spf13/cobra"
@@ -34,6 +35,7 @@ func NewServeCommand(app *app.App) *cobra.Command {
34
35
http := http .NewHttp (app , cache )
35
36
metrics := metrics .NewServer (app .Config .Metrics .Port )
36
37
metrics .Init ()
38
+ probes := health .NewHealth (app .Config .ProbesPort )
37
39
38
40
go cache .Work (ctx )
39
41
go func () {
@@ -54,9 +56,18 @@ func NewServeCommand(app *app.App) *cobra.Command {
54
56
}
55
57
}()
56
58
}
59
+ go func () {
60
+ if err := probes .Start (); err != nil {
61
+ if ! errors .Is (err , stdhttp .ErrServerClosed ) {
62
+ fmt .Println (fmt .Errorf ("probes server failed: %v" , err ))
63
+ cancel ()
64
+ }
65
+ }
66
+ }()
57
67
58
68
<- ctx .Done ()
59
69
metrics .Stop (context .Background ())
70
+ probes .Stop (context .Background ())
60
71
return http .Stop (context .Background ())
61
72
},
62
73
}
Original file line number Diff line number Diff line change @@ -56,10 +56,11 @@ type Datasource struct {
56
56
}
57
57
58
58
type Config struct {
59
- Port int `yaml:"port"`
60
- HttpLogs * bool `yaml:"http_logs"`
61
- Metrics Metrics `yaml:"metrics"`
62
- Services []Service `yaml:"services"`
59
+ Port int `yaml:"port"`
60
+ ProbesPort int `yaml:"probes_port"`
61
+ HttpLogs * bool `yaml:"http_logs"`
62
+ Metrics Metrics `yaml:"metrics"`
63
+ Services []Service `yaml:"services"`
63
64
64
65
Datasources []Datasource `yaml:"datasources"`
65
66
@@ -101,6 +102,9 @@ func setDefaults(conf *Config) {
101
102
if conf .Metrics .Port == 0 {
102
103
conf .Metrics .Port = 9743
103
104
}
105
+ if conf .ProbesPort == 0 {
106
+ conf .ProbesPort = 9744
107
+ }
104
108
if conf .HttpLogs == nil {
105
109
en := true
106
110
conf .HttpLogs = & en
Original file line number Diff line number Diff line change
1
+ package health
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "net/http"
7
+
8
+ "github.com/labstack/echo/v4"
9
+ )
10
+
11
+ type Health struct {
12
+ e * echo.Echo
13
+ port int
14
+
15
+ ready bool
16
+ healthy bool
17
+ }
18
+
19
+ // TODO: add an actual health/readiness check so these aren't meaningless
20
+
21
+ func NewHealth (port int ) * Health {
22
+ e := echo .New ()
23
+ e .HideBanner = true
24
+ h := & Health {
25
+ e : e ,
26
+ healthy : true ,
27
+ ready : true ,
28
+ port : port ,
29
+ }
30
+
31
+ h .e .GET ("/healthz" , h .healthHandler ())
32
+ h .e .GET ("/readyz" , h .readyHandler ())
33
+
34
+ return h
35
+ }
36
+
37
+ func (h * Health ) Start () error {
38
+ return h .e .Start (fmt .Sprintf (":%d" , h .port ))
39
+ }
40
+
41
+ func (h * Health ) Stop (ctx context.Context ) error {
42
+ return h .e .Shutdown (ctx )
43
+ }
44
+
45
+ func (h * Health ) healthHandler () echo.HandlerFunc {
46
+ return func (c echo.Context ) error {
47
+ if h .healthy {
48
+ return c .String (http .StatusOK , "HEALTHY" )
49
+ }
50
+ return c .String (http .StatusServiceUnavailable , "UNHEALTHY" )
51
+ }
52
+ }
53
+
54
+ func (h * Health ) readyHandler () echo.HandlerFunc {
55
+ return func (c echo.Context ) error {
56
+ if h .ready {
57
+ return c .String (http .StatusOK , "READY" )
58
+ }
59
+ return c .String (http .StatusServiceUnavailable , "NOT READY" )
60
+ }
61
+ }
You can’t perform that action at this time.
0 commit comments