Skip to content

Commit 2be6928

Browse files
Merge branch 'main' into update-helm-changelog
2 parents c836e68 + f6f1996 commit 2be6928

File tree

6 files changed

+70
-94
lines changed

6 files changed

+70
-94
lines changed

.github/workflows/build-push-staging.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

.github/workflows/pr-prechecks.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ name: "prechecks"
22

33
on:
44
workflow_dispatch:
5-
pull_request_target:
6-
branches: [main]
5+
pull_request:
6+
types: [opened, reopened, synchronize]
7+
paths:
8+
- "**.go"
79

810
jobs:
911
test:
@@ -17,13 +19,13 @@ jobs:
1719
- name: Setup golang environment
1820
uses: actions/setup-go@v5
1921
with:
20-
go-version: "1.22"
22+
go-version: "1.24"
2123

2224
- name: Install dependencies
2325
run: go mod tidy
2426

2527
- name: Run go test
26-
run: make test
28+
run: go test -v -cover -coverprofile cp.out -p 1 -race $(find . -name "*_test.go" -not -wholename "*/vendor/*" -exec dirname {} \; | uniq)
2729

2830
build:
2931
runs-on: ubuntu-latest
@@ -36,10 +38,20 @@ jobs:
3638
- name: Setup golang environment
3739
uses: actions/setup-go@v5
3840
with:
39-
go-version: "1.22"
41+
go-version: "1.24"
4042

4143
- name: Install dependencies
4244
run: go mod tidy
4345

4446
- name: Make sure app can build
45-
run: make build
47+
run: |
48+
export REPO_VERSION=$(git rev-parse --git-dir > /dev/null 2>&1 && git fetch -q origin --tags && git describe --always --dirty --tags)
49+
export REPO_REV=$(git rev-parse --git-dir > /dev/null 2>&1 && git rev-parse HEAD 2>/dev/null)
50+
export BUILD_DATE=$(date -u +%FT%T)
51+
52+
mkdir -p build/usr/bin
53+
go build -a -ldflags "\
54+
-X \"github.com/comcast/fishymetrics/buildinfo.gitVersion=${REPO_VERSION}\"\
55+
-X \"github.com/comcast/fishymetrics/buildinfo.gitRevision=${REPO_REV}\"\
56+
-X \"github.com/comcast/fishymetrics/buildinfo.date=${BUILD_DATE}\"\
57+
" -v -o build/usr/bin/fishymetrics $(pwd)/cmd/fishymetrics
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "security-checks"
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- "**.go"
8+
9+
jobs:
10+
security:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
16+
- name: Run Snyk to check for vulnerabilities
17+
uses: snyk/actions/golang@v4
18+
env:
19+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
20+
with:
21+
args: --severity-threshold=high

exporter/handlers.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (e *Exporter) exportFirmwareMetrics(body []byte) error {
7171
var dm = (*e.DeviceMetrics)["deviceInfo"]
7272
err := json.Unmarshal(body, &mgr)
7373
if err != nil {
74-
return fmt.Errorf("Error Unmarshalling FirmwareMetrics - " + err.Error())
74+
return fmt.Errorf("Error Unmarshalling FirmwareMetrics - %s", err.Error())
7575
}
7676

7777
(*dm)["deviceInfo"].WithLabelValues(e.systemHostname, e.ChassisSerialNumber, e.Model, mgr.FirmwareVersion, e.biosVersion).Set(1.0)
@@ -87,7 +87,7 @@ func (e *Exporter) exportPowerMetrics(body []byte) error {
8787
var bay int
8888
err := json.Unmarshal(body, &pm)
8989
if err != nil {
90-
return fmt.Errorf("Error Unmarshalling PowerMetrics - " + err.Error())
90+
return fmt.Errorf("Error Unmarshalling PowerMetrics - %s", err.Error())
9191
}
9292

9393
for _, pc := range pm.PowerControl.PowerControl {
@@ -195,7 +195,7 @@ func (e *Exporter) exportThermalMetrics(body []byte) error {
195195
var therm = (*e.DeviceMetrics)["thermalMetrics"]
196196
err := json.Unmarshal(body, &tm)
197197
if err != nil {
198-
return fmt.Errorf("Error Unmarshalling ThermalMetrics - " + err.Error())
198+
return fmt.Errorf("Error Unmarshalling ThermalMetrics - %s", err.Error())
199199
}
200200

201201
if tm.Status.State == "Enabled" {
@@ -277,7 +277,7 @@ func (e *Exporter) exportPhysicalDriveMetrics(body []byte) error {
277277
var cap int
278278
err := json.Unmarshal(body, &dlphysical)
279279
if err != nil {
280-
return fmt.Errorf("Error Unmarshalling DiskDriveMetrics - " + err.Error())
280+
return fmt.Errorf("Error Unmarshalling DiskDriveMetrics - %s", err.Error())
281281
}
282282
// Check physical drive is enabled then check status and convert string to numeric values
283283
if dlphysical.Status.State == "Absent" {
@@ -323,7 +323,7 @@ func (e *Exporter) exportLogicalDriveMetrics(body []byte) error {
323323
var volIdentifier string
324324
err := json.Unmarshal(body, &dllogical)
325325
if err != nil {
326-
return fmt.Errorf("Error Unmarshalling LogicalDriveMetrics - " + err.Error())
326+
return fmt.Errorf("Error Unmarshalling LogicalDriveMetrics - %s", err.Error())
327327
}
328328
if dllogical.Raid == "" {
329329
ldName = dllogical.DisplayName
@@ -358,7 +358,7 @@ func (e *Exporter) exportNVMeDriveMetrics(body []byte) error {
358358
var dlnvmedrive = (*e.DeviceMetrics)["nvmeMetrics"]
359359
err := json.Unmarshal(body, &dlnvme)
360360
if err != nil {
361-
return fmt.Errorf("Error Unmarshalling NVMeDriveMetrics - " + err.Error())
361+
return fmt.Errorf("Error Unmarshalling NVMeDriveMetrics - %s", err.Error())
362362
}
363363

364364
// Check nvme drive is enabled then check status and convert string to numeric values
@@ -382,18 +382,18 @@ func (e *Exporter) exportUnknownDriveMetrics(body []byte) error {
382382
var protocol oem.DriveProtocol
383383
err := json.Unmarshal(body, &protocol)
384384
if err != nil {
385-
return fmt.Errorf("Error Unmarshalling for drive protocol - " + err.Error())
385+
return fmt.Errorf("Error Unmarshalling for drive protocol - %s", err.Error())
386386
}
387387

388388
if protocol.Protocol == "NVMe" {
389389
err = e.exportNVMeDriveMetrics(body)
390390
if err != nil {
391-
return fmt.Errorf("Error Unmarshalling NVMeDriveMetrics - " + err.Error())
391+
return fmt.Errorf("Error Unmarshalling NVMeDriveMetrics - %s", err.Error())
392392
}
393393
} else {
394394
err = e.exportPhysicalDriveMetrics(body)
395395
if err != nil {
396-
return fmt.Errorf("Error Unmarshalling DiskDriveMetrics - " + err.Error())
396+
return fmt.Errorf("Error Unmarshalling DiskDriveMetrics - %s", err.Error())
397397
}
398398
}
399399

@@ -408,7 +408,7 @@ func (e *Exporter) exportStorageControllerMetrics(body []byte) error {
408408
var drv = (*e.DeviceMetrics)["storageCtrlMetrics"]
409409
err := json.Unmarshal(body, &scm)
410410
if err != nil {
411-
return fmt.Errorf("Error Unmarshalling StorageControllerMetrics - " + err.Error())
411+
return fmt.Errorf("Error Unmarshalling StorageControllerMetrics - %s", err.Error())
412412
}
413413

414414
for _, sc := range scm.StorageController.StorageController {
@@ -447,7 +447,7 @@ func (e *Exporter) exportMemorySummaryMetrics(body []byte) error {
447447
var totalSystemMemoryGiB string
448448
err := json.Unmarshal(body, &dlm)
449449
if err != nil {
450-
return fmt.Errorf("Error Unmarshalling MemorySummaryMetrics - " + err.Error())
450+
return fmt.Errorf("Error Unmarshalling MemorySummaryMetrics - %s", err.Error())
451451
}
452452
// Check memory status and convert string to numeric values
453453
// Ignore memory summary if status is not present
@@ -479,7 +479,7 @@ func (e *Exporter) exportStorageBattery(body []byte) error {
479479
var storBattery = (*e.DeviceMetrics)["storBatteryMetrics"]
480480
err := json.Unmarshal(body, &chasStorBatt)
481481
if err != nil {
482-
return fmt.Errorf("Error Unmarshalling Storage Battery Metrics - " + err.Error())
482+
return fmt.Errorf("Error Unmarshalling Storage Battery Metrics - %s", err.Error())
483483
}
484484

485485
if fmt.Sprint(chasStorBatt.Oem.Hp.Battery) != "null" && len(chasStorBatt.Oem.Hp.Battery) > 0 {
@@ -540,7 +540,7 @@ func (e *Exporter) exportMemoryMetrics(body []byte) error {
540540
var mem = (*e.DeviceMetrics)["memoryMetrics"]
541541
err := json.Unmarshal(body, &mm)
542542
if err != nil {
543-
return fmt.Errorf("Error Unmarshalling MemoryMetrics - " + err.Error())
543+
return fmt.Errorf("Error Unmarshalling MemoryMetrics - %s", err.Error())
544544
}
545545

546546
if mm.DIMMStatus != "" {
@@ -620,7 +620,7 @@ func (e *Exporter) exportProcessorMetrics(body []byte) error {
620620
var proc = (*e.DeviceMetrics)["processorMetrics"]
621621
err := json.Unmarshal(body, &pm)
622622
if err != nil {
623-
return fmt.Errorf("Error Unmarshalling ProcessorMetrics - " + err.Error())
623+
return fmt.Errorf("Error Unmarshalling ProcessorMetrics - %s", err.Error())
624624
}
625625

626626
switch pm.TotalCores.(type) {
@@ -654,7 +654,7 @@ func (e *Exporter) exportFirmwareInventoryMetrics(body []byte) error {
654654

655655
err := json.Unmarshal(body, &fwcomponent)
656656
if err != nil {
657-
return fmt.Errorf("Error Unmarshalling FirmwareInventoryMetrics - " + err.Error())
657+
return fmt.Errorf("Error Unmarshalling FirmwareInventoryMetrics - %s", err.Error())
658658
}
659659
// Export for iLO4 since it has a different structure
660660
if len(fwcomponent.Current.Firmware) > 0 {
@@ -666,7 +666,7 @@ func (e *Exporter) exportFirmwareInventoryMetrics(body []byte) error {
666666
var fwcomponent oem.GenericFirmware
667667
err := json.Unmarshal(body, &fwcomponent)
668668
if err != nil {
669-
return fmt.Errorf("Error Unmarshalling FirmwareInventoryMetrics - " + err.Error())
669+
return fmt.Errorf("Error Unmarshalling FirmwareInventoryMetrics - %s", err.Error())
670670
}
671671

672672
(*component)["componentFirmware"].WithLabelValues(fwcomponent.Id, strings.TrimRight(fwcomponent.Name, " "), fwcomponent.Description, fwcomponent.Version).Set(1.0)
@@ -682,7 +682,7 @@ func (e *Exporter) exportIloSelfTest(body []byte) error {
682682
var iloSelfTst = (*e.DeviceMetrics)["iloSelfTestMetrics"]
683683
err := json.Unmarshal(body, &sysm)
684684
if err != nil {
685-
return fmt.Errorf("Error Unmarshalling iLO Self Test Metrics - " + err.Error())
685+
return fmt.Errorf("Error Unmarshalling iLO Self Test Metrics - %s", err.Error())
686686
}
687687

688688
if fmt.Sprint(sysm.Oem.Hp.IloSelfTest) != "null" && len(sysm.Oem.Hp.IloSelfTest) > 0 {

exporter/helpers.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ func getMemberUrls(url, host string, client *retryablehttp.Client) ([]string, er
5151

5252
body, err := io.ReadAll(resp.Body)
5353
if err != nil {
54-
return urls, fmt.Errorf("Error reading Response Body - " + err.Error())
54+
return urls, fmt.Errorf("Error reading Response Body - %s", err.Error())
5555
}
5656

5757
err = json.Unmarshal(body, &coll)
5858
if err != nil {
59-
return urls, fmt.Errorf("Error Unmarshalling Chassis struct - " + err.Error())
59+
return urls, fmt.Errorf("Error Unmarshalling Chassis struct - %s", err.Error())
6060
}
6161

6262
for _, member := range coll.Members {
@@ -88,12 +88,12 @@ func getSystemEndpoints(chassisUrls []string, host string, client *retryablehttp
8888

8989
body, err := io.ReadAll(resp.Body)
9090
if err != nil {
91-
return sysEnd, fmt.Errorf("Error reading Response Body - " + err.Error())
91+
return sysEnd, fmt.Errorf("Error reading Response Body - %s", err.Error())
9292
}
9393

9494
err = json.Unmarshal(body, &chas)
9595
if err != nil {
96-
return sysEnd, fmt.Errorf("Error Unmarshalling Chassis struct - " + err.Error())
96+
return sysEnd, fmt.Errorf("Error Unmarshalling Chassis struct - %s", err.Error())
9797
}
9898

9999
// parse through Links to get the System Endpoints for each Chassis and only use unique URLs
@@ -225,12 +225,12 @@ func getSystemsMetadata(url, host string, client *retryablehttp.Client) (oem.Sys
225225

226226
body, err := io.ReadAll(resp.Body)
227227
if err != nil {
228-
return sys, fmt.Errorf("Error reading Response Body - " + err.Error())
228+
return sys, fmt.Errorf("Error reading Response Body - %s", err.Error())
229229
}
230230

231231
err = json.Unmarshal(body, &sys)
232232
if err != nil {
233-
return sys, fmt.Errorf("Error Unmarshalling ServerManager struct - " + err.Error())
233+
return sys, fmt.Errorf("Error Unmarshalling ServerManager struct - %s", err.Error())
234234
}
235235

236236
return sys, nil
@@ -271,12 +271,12 @@ func getDIMMEndpoints(url, host string, client *retryablehttp.Client) (oem.Colle
271271

272272
body, err := io.ReadAll(resp.Body)
273273
if err != nil {
274-
return dimms, fmt.Errorf("Error reading Response Body - " + err.Error())
274+
return dimms, fmt.Errorf("Error reading Response Body - %s", err.Error())
275275
}
276276

277277
err = json.Unmarshal(body, &dimms)
278278
if err != nil {
279-
return dimms, fmt.Errorf("Error Unmarshalling Memory Collection struct - " + err.Error())
279+
return dimms, fmt.Errorf("Error Unmarshalling Memory Collection struct - %s", err.Error())
280280
}
281281

282282
return dimms, nil
@@ -321,12 +321,12 @@ func getDriveEndpoint(url, host string, client *retryablehttp.Client) (oem.Gener
321321

322322
body, err := io.ReadAll(resp.Body)
323323
if err != nil {
324-
return drive, fmt.Errorf("Error reading Response Body - " + err.Error())
324+
return drive, fmt.Errorf("Error reading Response Body - %s", err.Error())
325325
}
326326

327327
err = json.Unmarshal(body, &drive)
328328
if err != nil {
329-
return drive, fmt.Errorf("Error Unmarshalling drive struct - " + err.Error())
329+
return drive, fmt.Errorf("Error Unmarshalling drive struct - %s", err.Error())
330330
}
331331

332332
return drive, nil
@@ -501,12 +501,12 @@ func getProcessorEndpoints(url, host string, client *retryablehttp.Client) (oem.
501501

502502
body, err := io.ReadAll(resp.Body)
503503
if err != nil {
504-
return processors, fmt.Errorf("Error reading Response Body - " + err.Error())
504+
return processors, fmt.Errorf("Error reading Response Body - %s", err.Error())
505505
}
506506

507507
err = json.Unmarshal(body, &processors)
508508
if err != nil {
509-
return processors, fmt.Errorf("Error Unmarshalling Processors Collection struct - " + err.Error())
509+
return processors, fmt.Errorf("Error Unmarshalling Processors Collection struct - %s", err.Error())
510510
}
511511

512512
return processors, nil

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/comcast/fishymetrics
22

3-
go 1.23
3+
go 1.24
4+
45
toolchain go1.24.1
56

67
require (

0 commit comments

Comments
 (0)