Merge branch '2-nil-reference-pointer-exception-when-getting-queried-by-prometheus' into 'main'
Resolve "Nil reference pointer exception when getting queried by Prometheus" Closes #2 See merge request adoralaura/ntppool-exporter!1
This commit is contained in:
commit
68823aa602
2 changed files with 11 additions and 7 deletions
|
@ -1,8 +1,9 @@
|
|||
FROM golang:1.22-alpine AS dev
|
||||
FROM golang:1.22-bullseye AS dev
|
||||
|
||||
COPY . /var/app
|
||||
WORKDIR /var/app
|
||||
|
||||
|
||||
ENV GO111MODULE="on" \
|
||||
CGO_ENABLED=0 \
|
||||
GOOS=linux
|
||||
|
@ -13,14 +14,16 @@ ENTRYPOINT ["sh"]
|
|||
|
||||
FROM dev as build
|
||||
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --assume-yes ca-certificates
|
||||
RUN go mod download && go mod verify
|
||||
RUN go build -o ntppool-exporter main.go$
|
||||
RUN go build -o ntppool-exporter main.go
|
||||
RUN chmod +x ntppool-exporter
|
||||
|
||||
|
||||
FROM scratch AS prod
|
||||
FROM debian:12 AS prod
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=build /var/app/ntppool-exporter /bin/
|
||||
|
||||
LABEL maintainer="Adora Laura Kalb <adora@lila.network>"
|
||||
|
|
|
@ -77,15 +77,16 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger log.Logger) {
|
|||
}
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Error in HTTP response", "status", res.Status)
|
||||
httpError = true
|
||||
level.Error(logger).Log("msg", "Error in HTTP response", "error", err)
|
||||
return
|
||||
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Error reading HTTP response body", "error", err)
|
||||
httpError = true
|
||||
return
|
||||
}
|
||||
|
||||
var response models.ApiResponse
|
||||
|
@ -93,7 +94,7 @@ func (c Collector) collect(ch chan<- prometheus.Metric, logger log.Logger) {
|
|||
err = json.Unmarshal(body, &response)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Error unmarshaling JSON body", "error", err)
|
||||
httpError = true
|
||||
return
|
||||
}
|
||||
|
||||
if !httpError {
|
||||
|
|
Loading…
Reference in a new issue