1
1
package healthcheck
2
2
3
3
import (
4
- "encoding/json"
5
4
"fmt"
6
5
"net/http"
7
6
"net/url"
@@ -25,8 +24,8 @@ type Healthcheck struct {
25
24
// Time we received the last block height
26
25
lastHeightTime time.Time
27
26
28
- // dnsOK Are we currently serving DNS responses?
29
- dnsOK bool
27
+ // Last time we got a successful DNS response
28
+ lastDNSTime time. Time
30
29
}
31
30
32
31
// NewHealthcheck returns a new instance of healthcheck
@@ -35,7 +34,6 @@ func NewHealthcheck(port uint16, logLevel log.Level) (*Healthcheck, error) {
35
34
36
35
healthcheck := & Healthcheck {
37
36
healthcheckPort : port ,
38
- dnsOK : false ,
39
37
}
40
38
41
39
log .SetLevel (logLevel )
@@ -103,30 +101,6 @@ func (h *Healthcheck) websocketReceive(resp *types.WebsocketResponse, err error)
103
101
}
104
102
}
105
103
106
- func (h * Healthcheck ) fullNodeReceive (resp * types.WebsocketResponse ) {
107
- var blockHeight uint32
108
-
109
- if resp .Command != "get_blockchain_state" {
110
- return
111
- }
112
-
113
- block := & types.WebsocketBlockchainState {}
114
- err := json .Unmarshal (resp .Data , block )
115
- if err != nil {
116
- log .Errorf ("Error unmarshalling: %s\n " , err .Error ())
117
- return
118
- }
119
- blockHeight = block .BlockchainState .Peak .OrEmpty ().Height
120
-
121
- // Edge case, but we should be sure block height is increasing
122
- if blockHeight <= h .lastHeight {
123
- return
124
- }
125
-
126
- h .lastHeight = blockHeight
127
- h .lastHeightTime = time .Now ()
128
- }
129
-
130
104
func (h * Healthcheck ) walletReceive (resp * types.WebsocketResponse ) {}
131
105
132
106
func (h * Healthcheck ) crawlerReceive (resp * types.WebsocketResponse ) {}
@@ -150,21 +124,19 @@ func (h *Healthcheck) reconnectHandler() {
150
124
}
151
125
}
152
126
153
- // Healthcheck endpoint for the full node service as a whole
154
- func (h * Healthcheck ) fullNodeHealthcheck () func (http.ResponseWriter , * http.Request ) {
155
- return func (w http.ResponseWriter , r * http.Request ) {
156
- if time .Since (h .lastHeightTime ) < viper .GetDuration ("healthcheck-threshold" ) {
157
- w .WriteHeader (http .StatusOK )
158
- _ , err := fmt .Fprintf (w , "Ok" )
159
- if err != nil {
160
- log .Errorf ("Error writing healthcheck response %s\n " , err .Error ())
161
- }
162
- } else {
163
- w .WriteHeader (http .StatusInternalServerError )
164
- _ , err := fmt .Fprintf (w , "Not OK" )
165
- if err != nil {
166
- log .Errorf ("Error writing healthcheck response %s\n " , err .Error ())
167
- }
127
+ func timeMetricHealthcheckHelper (lastTime time.Time , w http.ResponseWriter , r * http.Request ) {
128
+ if time .Since (lastTime ) < viper .GetDuration ("healthcheck-threshold" ) {
129
+ w .WriteHeader (http .StatusOK )
130
+ _ , err := fmt .Fprintf (w , "Ok" )
131
+ if err != nil {
132
+ log .Errorf ("Error writing healthcheck response %s\n " , err .Error ())
133
+ }
134
+ } else {
135
+ w .WriteHeader (http .StatusInternalServerError )
136
+ _ , err := fmt .Fprintf (w , "Not OK" )
137
+ if err != nil {
138
+ log .Errorf ("Error writing healthcheck response %s\n " , err .Error ())
168
139
}
169
140
}
170
141
}
142
+
0 commit comments