From ada50f32eae014ad1e151776d0376ea3623bf8d9 Mon Sep 17 00:00:00 2001 From: Tomasz Prus Date: Thu, 15 Feb 2024 23:52:29 +0100 Subject: [PATCH] Refresh dependencies, ci pipeline etc. --- .github/workflows/test.yaml | 23 +++++++++++++++++++ .travis.yml | 8 ------- Dockerfile | 16 ++++++++------ airly_test.go | 44 ++++++++++++++++++------------------- go.mod | 19 ++++++++++++++++ go.sum | 28 +++++++++++++++++++++++ main.go | 15 ++++++------- 7 files changed, 108 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/test.yaml delete mode 100644 .travis.yml create mode 100644 go.mod create mode 100644 go.sum diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..d3033ee --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,23 @@ +name: Upload Go test results + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: 1.22 + - name: Install dependencies + run: go mod download + - name: Build + run: | + go build + ./airly-exporter -h + - name: Test + run: go test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6037d7a..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go - -go: - - 1.10.x - -script: - - go get -t ./... - - go test -v ./... diff --git a/Dockerfile b/Dockerfile index b10a635..28367a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,21 @@ -FROM golang:1.10-alpine +FROM golang:1.22-alpine RUN apk add --no-cache git -WORKDIR /go/src/airly-exporter -COPY *.go /go/src/airly-exporter/ +WORKDIR /app +COPY *.go . +COPY go.mod . +COPY go.sum . -RUN go get -d -v ./... -RUN go install -v ./... +RUN go mod download +RUN go build FROM alpine RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* -WORKDIR /go/bin/ -COPY --from=0 /go/bin/airly-exporter /go/bin/airly-exporter +WORKDIR /app +COPY --from=0 /app/airly-exporter /app/airly-exporter EXPOSE 8080 diff --git a/airly_test.go b/airly_test.go index 125c78e..896aa85 100644 --- a/airly_test.go +++ b/airly_test.go @@ -166,14 +166,14 @@ func TestSensorMeasurements(t *testing.T) { FromDateTime: "2018-01-01T21:46:25.476Z", TillDateTime: "2018-01-01T22:46:25.476Z", Values: []MeasuredValue{ - MeasuredValue{Name: "PM1", Value: 17.01}, - MeasuredValue{Name: "PM25", Value: 25.69}, - MeasuredValue{Name: "PM10", Value: 49.7}, - MeasuredValue{Name: "PRESSURE", Value: 1025.82}, - MeasuredValue{Name: "HUMIDITY", Value: 82.91}, - MeasuredValue{Name: "TEMPERATURE", Value: 7.64}}, + {Name: "PM1", Value: 17.01}, + {Name: "PM25", Value: 25.69}, + {Name: "PM10", Value: 49.7}, + {Name: "PRESSURE", Value: 1025.82}, + {Name: "HUMIDITY", Value: 82.91}, + {Name: "TEMPERATURE", Value: 7.64}}, Indexes: []MeasuredIndex{ - MeasuredIndex{ + { Name: "AIRLY_CAQI", Value: 49.7, Level: "LOW", @@ -181,25 +181,25 @@ func TestSensorMeasurements(t *testing.T) { Advice: "How about going for a walk?", Color: "#D1CF1E"}}, Standards: []MeasuredStandard{ - MeasuredStandard{ + { Name: "WHO", Pollutant: "PM25", Limit: 25, Percent: 102.77}}, }, History: []MeasurementsTimeFramed{ - MeasurementsTimeFramed{ + { FromDateTime: "2018-10-19T22:00:00Z", TillDateTime: "2018-10-19T23:00:00Z", Values: []MeasuredValue{ - MeasuredValue{Name: "PM1", Value: 26.66}, - MeasuredValue{Name: "PM25", Value: 42.97}, - MeasuredValue{Name: "PM10", Value: 79.19}, - MeasuredValue{Name: "PRESSURE", Value: 1025.44}, - MeasuredValue{Name: "HUMIDITY", Value: 92.64}, - MeasuredValue{Name: "TEMPERATURE", Value: 10.22}}, + {Name: "PM1", Value: 26.66}, + {Name: "PM25", Value: 42.97}, + {Name: "PM10", Value: 79.19}, + {Name: "PRESSURE", Value: 1025.44}, + {Name: "HUMIDITY", Value: 92.64}, + {Name: "TEMPERATURE", Value: 10.22}}, Indexes: []MeasuredIndex{ - MeasuredIndex{ + { Name: "AIRLY_CAQI", Value: 68.24, Level: "MEDIUM", @@ -207,7 +207,7 @@ func TestSensorMeasurements(t *testing.T) { Advice: "Neither good nor bad. Think before leaving the house.", Color: "#EFBB0F"}}, Standards: []MeasuredStandard{ - MeasuredStandard{ + { Name: "WHO", Pollutant: "PM25", Limit: 25, @@ -215,14 +215,14 @@ func TestSensorMeasurements(t *testing.T) { }, }, Forecast: []MeasurementsTimeFramed{ - MeasurementsTimeFramed{ + { FromDateTime: "2018-01-01T22:00:00Z", TillDateTime: "2018-01-01T23:00:00Z", Values: []MeasuredValue{ - MeasuredValue{Name: "PM25", Value: 27.48}, - MeasuredValue{Name: "PM10", Value: 53.29}}, + {Name: "PM25", Value: 27.48}, + {Name: "PM10", Value: 53.29}}, Indexes: []MeasuredIndex{ - MeasuredIndex{ + { Name: "AIRLY_CAQI", Value: 52.06, Level: "MEDIUM", @@ -230,7 +230,7 @@ func TestSensorMeasurements(t *testing.T) { Advice: "Protect your lungs!", Color: "#EFBB0F"}}, Standards: []MeasuredStandard{ - MeasuredStandard{ + { Name: "WHO", Pollutant: "PM25", Limit: 25, diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..83890e0 --- /dev/null +++ b/go.mod @@ -0,0 +1,19 @@ +module airly-exporter + +go 1.22.0 + +require ( + github.com/fsnotify/fsnotify v1.7.0 + github.com/prometheus/client_golang v1.18.0 +) + +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.45.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + golang.org/x/sys v0.15.0 // indirect + google.golang.org/protobuf v1.31.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..b4e0a02 --- /dev/null +++ b/go.sum @@ -0,0 +1,28 @@ +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= +google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/main.go b/main.go index 610ef41..fbfc4cb 100644 --- a/main.go +++ b/main.go @@ -1,20 +1,19 @@ -// Copyright 2018 Airly-exporter Authors - package main import ( "bufio" "flag" "fmt" - "github.com/fsnotify/fsnotify" - "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" "log" "net/http" "os" "strconv" "strings" "time" + + "github.com/fsnotify/fsnotify" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" ) // AirlyExporter contains parameters for Airly-exporter @@ -136,8 +135,8 @@ func (airlyExporter *AirlyExporter) flagParse() { airlyExporter.listenAddress = flagStringWithDefaultFromEnv("listen-address", ":8080", "the address to listen on for http requests.") airlyExporter.apiKey = flagStringWithDefaultFromEnv("api-key", "", "Your key for Airly API") airlyExporter.apiURL = flagStringWithDefaultFromEnv("api-url", "https://airapi.airly.eu", "Airly API endpoint") - airlyExporter.refreshInterval = flagStringWithDefaultFromEnv("refresh-interval", "5m", "Refresh sensor interval with units") - airlyExporter.sensors = flagStringWithDefaultFromEnv("sensors", "204,822", "Comma separated sensors/installations IDs") + airlyExporter.refreshInterval = flagStringWithDefaultFromEnv("refresh-interval", "60m", "Refresh sensor interval with units") + airlyExporter.sensors = flagStringWithDefaultFromEnv("sensors", "17,97128", "Comma separated sensors/installations IDs (default Krakow, Warszawa)") flag.Parse() } @@ -157,7 +156,7 @@ func main() { go airlyExporter.watchSensors() - http.Handle("/", http.RedirectHandler("/metrics", 302)) + http.Handle("/", http.RedirectHandler("/metrics", http.StatusFound)) http.Handle("/metrics", promhttp.Handler()) log.Fatal(http.ListenAndServe(*airlyExporter.listenAddress, nil)) }