Skip to content

Commit 9bbca22

Browse files
Merge pull request #24 from featheredtoast/fix-mem-leak
Fix mem leak
2 parents 26bce16 + f9132ef commit 9bbca22

File tree

13 files changed

+69
-29
lines changed

13 files changed

+69
-29
lines changed

.github/workflows/pull_request.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
on: pull_request
22
name: Pull Request
3-
defaults:
4-
run:
5-
shell: powershell
63
jobs:
4+
lint:
5+
runs-on: ubuntu-latest
6+
timeout-minutes: 5
7+
strategy:
8+
fail-fast: true
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-go@v5
12+
with:
13+
go-version: ">=1.22.0"
14+
- name: gofmt
15+
working-directory: ./Companion
16+
run: |
17+
if [ "$(gofmt -l . | wc -l)" -gt 0 ]; then
18+
exit 1
19+
fi
720
test:
21+
defaults:
22+
run:
23+
shell: powershell
824
name: test
925
runs-on: windows-latest
1026
steps:
@@ -34,4 +50,4 @@ jobs:
3450
3551
- name: Test README generation
3652
run: |
37-
make readme
53+
make readme

Companion/exporter/collector_runner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"time"
66

77
"github.com/AP-Hunt/FicsitRemoteMonitoringCompanion/Companion/exporter"
8-
. "github.com/onsi/ginkgo/v2"
98
"github.com/coder/quartz"
9+
. "github.com/onsi/ginkgo/v2"
1010
. "github.com/onsi/gomega"
1111
)
1212

@@ -61,7 +61,7 @@ var _ = Describe("CollectorRunner", func() {
6161
})
6262

6363
It("sanitizes session name", func() {
64-
Expect(exporter.SanitizeSessionName(`it's giving -- 123456!@#$%^&*() yo hollar "'"`)).To(Equal(`its giving 123456 yo hollar ` ))
64+
Expect(exporter.SanitizeSessionName(`it's giving -- 123456!@#$%^&*() yo hollar "'"`)).To(Equal(`its giving 123456 yo hollar `))
6565
})
6666
})
6767
})

Companion/exporter/common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ func retrieveData(frmAddress string, details any) error {
4343
return err
4444
}
4545

46+
defer resp.Body.Close()
4647
if resp.StatusCode != 200 {
4748
return fmt.Errorf("non-200 returned when retireving data: %d", resp.StatusCode)
4849
}
4950

50-
defer resp.Body.Close()
51-
5251
decoder := json.NewDecoder(resp.Body)
5352

5453
err = decoder.Decode(&details)

Companion/exporter/factory_building_collector_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ var _ = Describe("FactoryBuildingCollector", func() {
5555
IsPaused: false,
5656
CircuitGroupId: 0,
5757
PowerInfo: exporter.PowerInfo{
58-
CircuitGroupId: 1,
59-
PowerConsumed: 23,
60-
MaxPowerConsumed: 4,
58+
CircuitGroupId: 1,
59+
PowerConsumed: 23,
60+
MaxPowerConsumed: 4,
6161
},
6262
},
6363
})

Companion/exporter/frm_server_fake_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type FRMServerFake struct {
2424
extractorData []exporter.ExtractorDetails
2525
portalData []exporter.PortalDetails
2626
hypertubeData []exporter.HypertubeDetails
27-
frackingData []exporter.FrackingDetails
27+
frackingData []exporter.FrackingDetails
2828
}
2929

3030
func NewFRMServerFake() *FRMServerFake {

Companion/exporter/registration_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ var _ = Describe("metrics dropper", func() {
3636
globalReg.Unregister(metric)
3737
})
3838
It("Keeps fresh metrics", func() {
39-
dropper.CacheFreshMetricLabel(prometheus.Labels{"label1":"val1"})
40-
metric.WithLabelValues("val1","val2").Set(1)
39+
dropper.CacheFreshMetricLabel(prometheus.Labels{"label1": "val1"})
40+
metric.WithLabelValues("val1", "val2").Set(1)
4141
dropper.DropStaleMetricLabels()
4242
expectGauge(metric, "val1", "val2").To(Equal(1.0))
4343
})
4444
It("drops old metrics", func() {
45-
dropper.CacheFreshMetricLabel(prometheus.Labels{"label1":"val1"})
46-
metric.WithLabelValues("val1","val2").Set(1)
47-
metric.WithLabelValues("val3","val4").Set(1)
45+
dropper.CacheFreshMetricLabel(prometheus.Labels{"label1": "val1"})
46+
metric.WithLabelValues("val1", "val2").Set(1)
47+
metric.WithLabelValues("val3", "val4").Set(1)
4848
dropper.DropStaleMetricLabels()
49-
metric.WithLabelValues("val3","val4").Set(2)
49+
metric.WithLabelValues("val3", "val4").Set(2)
5050
dropper.DropStaleMetricLabels()
5151
expectGauge(metric, "val1", "val2").To(Equal(0.0))
5252
expectGauge(metric, "val3", "val4").To(Equal(2.0))

Companion/exporter/vehicle_collector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type VehicleCollector struct {
1111
endpoint string
1212
TrackedVehicles map[string]*VehicleDetails
13-
metricsDropper *MetricsDropper
13+
metricsDropper *MetricsDropper
1414
}
1515

1616
type VehicleDetails struct {
@@ -23,7 +23,7 @@ type VehicleDetails struct {
2323
PathName string `json:"PathName"`
2424
DepartTime time.Time
2525
Departed bool
26-
LastTracked time.Time
26+
LastTracked time.Time
2727
}
2828

2929
type Fuel struct {

Companion/main.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os/signal"
99
"path"
1010
"path/filepath"
11+
"strconv"
1112
"strings"
1213
"syscall"
1314
"text/template"
@@ -46,18 +47,21 @@ func main() {
4647
frmHostname = lookupEnvWithDefault("FRM_HOST", frmHostname)
4748
frmPort = lookupEnvWithDefault("FRM_PORT", frmPort)
4849
frmHostnames = lookupEnvWithDefault("FRM_HOSTS", frmHostnames)
50+
logStdout, _ := strconv.ParseBool(lookupEnvWithDefault("FRM_LOG_STDOUT", "0"))
4951

5052
if genReadme {
5153
generateReadme()
5254
os.Exit(0)
5355
}
5456

55-
logFile, err := createLogFile()
56-
if err != nil {
57-
fmt.Printf("error creating log file: %s", err)
58-
os.Exit(1)
57+
if !logStdout {
58+
logFile, err := createLogFile()
59+
if err != nil {
60+
fmt.Printf("error creating log file: %s", err)
61+
os.Exit(1)
62+
}
63+
log.Default().SetOutput(logFile)
5964
}
60-
log.Default().SetOutput(logFile)
6165

6266
// Create exporter
6367
frmUrls := []string{}
@@ -75,6 +79,7 @@ func main() {
7579
promExporter = exporter.NewPrometheusExporter(frmUrls)
7680

7781
var prom *prometheus.PrometheusWrapper
82+
var err error
7883
if !noProm {
7984
// Create prometheus
8085
prom, err = prometheus.NewPrometheusWrapper()

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ The [Prometheus metrics server](https://prometheus.io/) allows you to [explore t
2424

2525
(* Link goes to the address on your local system. If FRMC is not running, you will see an error)
2626

27+
### Env vars
28+
29+
`FRM_HOST`: The host to the Ficsit Remote Monitoring server. EG: `172.17.0.1`.
30+
31+
`FRM_PORT`: The port of the Ficist Remote Monitoring server. EG: `8080`.
32+
33+
`FRM_HOSTS`: A comma separated list of Ficsit Remote Monitoring servers. If protocol is unspecified, it defaults to http. EG: `http://myserver1.frm.example:8080,myserver2.frm.example:8080,https://myserver3.frm.example:8081`
34+
35+
`FRM_LOG_STDOUT`: If FRMC should print to stdout rather than a separate logfile. Useful for docker/containerization. default false.
36+
2737
## What metrics are available
2838

2939

map/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)