From a9befbc0597ac9b96926ac682cf431a5f71132ee Mon Sep 17 00:00:00 2001 From: MiguelNdeCarvalho Date: Sun, 8 Dec 2024 17:37:58 +0000 Subject: [PATCH 1/2] Run go fmt on all code --- cmd/aws_batch_exporter.go | 4 ++-- collector.go | 31 +++++++++++++++---------------- main.go | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/cmd/aws_batch_exporter.go b/cmd/aws_batch_exporter.go index 6d3bbdb..c4248bd 100644 --- a/cmd/aws_batch_exporter.go +++ b/cmd/aws_batch_exporter.go @@ -1,9 +1,9 @@ package main import ( - "github.com/atr0phy/aws_batch_exporter" + awsBatchExporter "github.com/atr0phy/aws_batch_exporter" ) func main() { awsBatchExporter.Run() -} \ No newline at end of file +} diff --git a/collector.go b/collector.go index a913ab2..5d1d780 100644 --- a/collector.go +++ b/collector.go @@ -14,14 +14,14 @@ import ( ) type Collector struct { - client batchiface.BatchAPI - region string + client batchiface.BatchAPI + region string timeout time.Duration } const ( namespace = "aws_batch" - timeout = 10 * time.Second + timeout = 10 * time.Second ) var ( @@ -69,7 +69,7 @@ var ( prometheus.BuildFQName(namespace, "", "failed_job"), "Job in the queue that are in the FAILED state", []string{"region", "id", "queue", "name"}, nil, - ) + ) jobSucceeded = prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "succeeded_job"), @@ -79,20 +79,19 @@ var ( jobDescMap = map[string]*prometheus.Desc{ batch.JobStatusSubmitted: jobSubmitted, - batch.JobStatusPending: jobPending, - batch.JobStatusRunnable: jobRunnable, - batch.JobStatusStarting: jobStarting, - batch.JobStatusRunning: jobRunning, - batch.JobStatusFailed: jobFailed, + batch.JobStatusPending: jobPending, + batch.JobStatusRunnable: jobRunnable, + batch.JobStatusStarting: jobStarting, + batch.JobStatusRunning: jobRunning, + batch.JobStatusFailed: jobFailed, batch.JobStatusSucceeded: jobSucceeded, } - ) type JobResult struct { - id string - queue string - name string + id string + queue string + name string status string } @@ -103,8 +102,8 @@ func New(region string) (*Collector, error) { } return &Collector{ - client: batch.New(s), - region: "ap-northeast-1", + client: batch.New(s), + region: "ap-northeast-1", timeout: timeout, }, nil } @@ -134,7 +133,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) { defer wg.Done() var results []JobResult for _, s := range jobStatus { - r, err := c.client.ListJobsWithContext(ctx, &batch.ListJobsInput{JobQueue: d.JobQueueName,JobStatus: &s}) + r, err := c.client.ListJobsWithContext(ctx, &batch.ListJobsInput{JobQueue: d.JobQueueName, JobStatus: &s}) if err != nil { log.Printf("Error collecting job status metrics: %v\n", err) continue diff --git a/main.go b/main.go index e51f139..5bf1733 100644 --- a/main.go +++ b/main.go @@ -30,4 +30,4 @@ func Run() { prometheus.MustRegister(collector) http.Handle("/metrics", promhttp.Handler()) log.Fatal(http.ListenAndServe(addr, nil)) -} \ No newline at end of file +} From d2759a39cdb59575073bfad95bfbea9b5cecdc76 Mon Sep 17 00:00:00 2001 From: MiguelNdeCarvalho Date: Sun, 8 Dec 2024 17:38:32 +0000 Subject: [PATCH 2/2] collector.go: Fix hardcoded AWS Region --- collector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector.go b/collector.go index 5d1d780..52805b6 100644 --- a/collector.go +++ b/collector.go @@ -103,7 +103,7 @@ func New(region string) (*Collector, error) { return &Collector{ client: batch.New(s), - region: "ap-northeast-1", + region: region, timeout: timeout, }, nil }