diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 748ed53..57cc916 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -9,6 +9,7 @@ on: - "go.mod" - "go.sum" - "Dockerfile" + - "**/*.go" - ".github/workflows/docker.yml" pull_request: branches: @@ -19,6 +20,7 @@ on: - "go.mod" - "go.sum" - "Dockerfile" + - "**/*.go" - ".github/workflows/docker.yml" workflow_dispatch: diff --git a/Dockerfile b/Dockerfile index d97b54c..206504d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM docker.io/golang:1.22-alpine3.19 AS builder LABEL maintainer="Said Sef (saidsef.co.uk/)" -ENV PORT ${PORT:-8080} - WORKDIR /app COPY . /app/ RUN apk add --no-cache curl git && \ @@ -11,6 +9,7 @@ RUN apk add --no-cache curl git && \ FROM docker.io/alpine:3.20 LABEL maintainer="Said Sef (saidsef.co.uk/)" +ENV PORT=${PORT:-8080} USER nobody diff --git a/charts/reverse-geocoding/Chart.yaml b/charts/reverse-geocoding/Chart.yaml index ac2831c..7c57f67 100644 --- a/charts/reverse-geocoding/Chart.yaml +++ b/charts/reverse-geocoding/Chart.yaml @@ -2,11 +2,11 @@ apiVersion: v2 name: reverse-geocoding description: Reverse GeoCode Helm chart for Kubernetes type: application -version: &version 0.3.1 +version: &version 0.3.2 appVersion: *version kubeVersion: ">= 1.27" keywords: - - reverse-geocoding + - reverse geocoding - geocoding - kubernetes maintainers: diff --git a/charts/reverse-geocoding/values.yaml b/charts/reverse-geocoding/values.yaml index 1e87a20..c733839 100644 --- a/charts/reverse-geocoding/values.yaml +++ b/charts/reverse-geocoding/values.yaml @@ -56,10 +56,10 @@ ingress: resources: limits: - cpu: 100m - memory: 512Mi + cpu: 60m + memory: 256Mi requests: - cpu: 100m + cpu: 30m memory: 128Mi livenessProbe: diff --git a/deployment/base/deployment.yml b/deployment/base/deployment.yml index e243c45..338e118 100644 --- a/deployment/base/deployment.yml +++ b/deployment/base/deployment.yml @@ -50,11 +50,11 @@ spec: name: http resources: requests: - memory: "50Mi" - cpu: "20m" + memory: "30Mi" + cpu: "10m" limits: - memory: "100Mi" - cpu: "40m" + memory: "60Mi" + cpu: "20m" livenessProbe: exec: command: diff --git a/internal/geo/coordinates.go b/internal/geo/coordinates.go index a041bb3..84af882 100644 --- a/internal/geo/coordinates.go +++ b/internal/geo/coordinates.go @@ -3,6 +3,8 @@ package geo import ( "encoding/json" "strconv" + + "github.com/saidsef/faas-reverse-geocoding/internal/utils" ) // Coordinates defines a structure for geographical coordinates with latitude and longitude. @@ -29,16 +31,19 @@ func (c *Coordinates) UnmarshalJSON(data []byte) error { } if err := json.Unmarshal(data, &aux); err != nil { + utils.Logger.Errorf("Error parsing json payload: %s", err) return err } lat, err := strconv.ParseFloat(aux.Lat, 32) if err != nil { + utils.Logger.Errorf("Error parsing Lat json payload: %s", err) return err } long, err := strconv.ParseFloat(aux.Long, 32) if err != nil { + utils.Logger.Errorf("Error parsing Long json payload: %s", err) return err } diff --git a/internal/handlers/latitude_longitude.go b/internal/handlers/latitude_longitude.go index b094a84..5556202 100644 --- a/internal/handlers/latitude_longitude.go +++ b/internal/handlers/latitude_longitude.go @@ -66,11 +66,17 @@ func handlePostRequest(w http.ResponseWriter, r *http.Request) { if err := decodeRequestBody(r, &c); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + if utils.Verbose { + utils.Logger.Errorf("Error decoding json payload: %s", err) + } return } if err := validateCoordinates(c); err != nil { http.Error(w, err.Error(), http.StatusBadRequest) + if utils.Verbose { + utils.Logger.Errorf("Error validating json payload: %s", err) + } return } @@ -120,14 +126,18 @@ func handleCacheMiss(w http.ResponseWriter, c geo.Coordinates, cacheKey string) defer resp.Body.Close() if err := decodeResponseBody(resp, &location); err != nil { - utils.Logger.Errorf("Failed to decode response body: %v", err) http.Error(w, "Failed to decode response", http.StatusInternalServerError) + if utils.Verbose { + utils.Logger.Errorf("Failed to decode response body: %v", err) + } return } if resp.StatusCode != http.StatusOK { - utils.Logger.Errorf("Failed to get proper status code response: %d", resp.StatusCode) http.Error(w, fmt.Sprintf("External API error: %s", location), resp.StatusCode) + if utils.Verbose { + utils.Logger.Errorf("Failed to get proper status code response: %d", resp.StatusCode) + } return } diff --git a/internal/httpclient/logging_round_tripper.go b/internal/httpclient/logging_round_tripper.go index 35002e5..afd1712 100644 --- a/internal/httpclient/logging_round_tripper.go +++ b/internal/httpclient/logging_round_tripper.go @@ -22,8 +22,10 @@ func (lrt *LoggingRoundTripper) RoundTrip(req *http.Request) (*http.Response, er duration := time.Since(startTime) if err != nil { - utils.Logger.Errorf("HTTP request error: %s", err) - return nil, err + if utils.Verbose { + utils.Logger.Errorf("HTTP request error: %s", err) + } + return resp, err } utils.Logger.Infof("Request: %s %s %s, Response: %d, Duration: %s, remote: %s", req.Method, req.URL, req.Proto, resp.StatusCode, duration, req.RemoteAddr)