Skip to content

Commit 449f002

Browse files
fix: address review comments
Signed-off-by: Ricky Moorhouse <[email protected]>
1 parent f44d561 commit 449f002

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

Dockerfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ WORKDIR /app/
44

55
RUN dnf upgrade --assumeyes
66
RUN dnf install -y curl jq tar --allowerasing
7-
7+
COPY . .
88
# Set the Go version dynamically by fetching the latest version
9-
RUN GOVERSION=$(curl -s 'https://go.dev/dl/?mode=json' | jq -r '.[0].version' | sed 's/^go//') && \
9+
RUN GOVERSION=$(egrep "^toolchain " go.mod | awk -Fgo '{print $2}') && \
1010
echo "Installing Go version: $GOVERSION" && \
1111
curl -sSL "https://golang.org/dl/go$GOVERSION.linux-amd64.tar.gz" | tar -C /usr/local -xzf - && \
1212
ln -s /usr/local/go/bin/go /usr/bin/go
1313

14-
COPY . .
1514
RUN go mod download
1615

1716
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./out/trawler .

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module rickymoorhouse/exporter
22

33
go 1.23.0
44

5-
toolchain go1.23.5
5+
toolchain go1.23.9
66

77
require (
88
github.com/IBM/alchemy-logging/src/go v1.0.3

nets/consumption/consumption.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var healthStatus = promauto.NewGaugeVec(
4545

4646
func (a *Consumption) apiCallCount(analytics_url string) {
4747
formFactor := os.Getenv(("formFactor"))
48-
fmt.Println("Form factor is", formFactor)
48+
log.Log(alog.DEBUG, "Form factor is", formFactor)
4949
certPath := os.Getenv("ANALYTICS_CERTS")
5050
timeframe := "timeframe=last1minute"
5151
//url := fmt.Sprintf("%s/cloud/dashboards/status?%s", analytics_url, timeframe)
@@ -67,22 +67,22 @@ func (a *Consumption) apiCallCount(analytics_url string) {
6767
log.Log(alog.DEBUG, "%v", total)
6868
if total.Total > 0 {
6969
if formFactor == "ibm-cloud" {
70-
err := SendMetrics("success")
70+
err := SendMetrics(True)
7171
if err != nil {
72-
fmt.Println("Error sending metrics:", err)
72+
log.Log(alog.ERROR, "Error sending metrics:", err)
7373
} else {
74-
fmt.Println("Metrics sent successfully.")
74+
log.Log(alog.INFO, "Metrics sent successfully.")
7575
}
7676

7777
}
7878
healthStatus.WithLabelValues("API Calls", a.Config.CrnMask).Set(float64(1))
7979
} else {
8080
if formFactor == "ibm-cloud" {
81-
err := SendMetrics("failure")
81+
err := SendMetrics(False)
8282
if err != nil {
83-
fmt.Println("Error sending metrics:", err)
83+
log.Log(alog.ERROR, "Error sending metrics:", err)
8484
} else {
85-
fmt.Println("Metrics sent successfully.")
85+
log.Log(alog.INFO, "Metrics sent successfully.")
8686
}
8787

8888
}

nets/consumption/ibmcloud.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ func getIAMToken() (string, error) {
7979
return iamResp.AccessToken, nil
8080
}
8181

82-
func SendMetrics(state string) error {
82+
func SendMetrics(isSuccess bool) error {
8383

8484
status := 0
8585
var alert *Alert
8686
serviceOutput := "Lifecycle: API Call traffic detected."
8787

88-
if state == "failure" {
88+
if !isSuccess {
8989
status = 1
9090
alert = &Alert{
9191
Severity: 2,
@@ -121,7 +121,7 @@ func SendMetrics(state string) error {
121121

122122
jsonPayload, _ := json.Marshal(payload)
123123
client := &http.Client{}
124-
fmt.Println("Payload before sending to edb:", string(jsonPayload))
124+
log.Log(alog.INFO, "Payload before sending to edb:", string(jsonPayload))
125125

126126
// Add query parameters
127127
params := url.Values{}
@@ -147,7 +147,7 @@ func SendMetrics(state string) error {
147147
defer resp.Body.Close()
148148

149149
body, _ := io.ReadAll(resp.Body)
150-
fmt.Println("Response Status Code:", resp.StatusCode)
151-
fmt.Println("Successfully sent payload to EDB:", string(body))
150+
log.Log(alog.INFO, "Response Status Code:", resp.StatusCode)
151+
log.Log(alog.INFO, "Successfully sent payload to EDB:", string(body))
152152
return nil
153153
}

0 commit comments

Comments
 (0)