Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix golangci reports #97

Merged
merged 5 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions collectors/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewApplicationsCollector(
Help: "Labeled Cloud Foundry Application information with a constant '1' value.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "detected_buildpack", "buildpack", "organization_id", "organization_name", "space_id", "space_name", "stack_id", "state"},
[]string{"applicationID", "application_name", "detected_buildpack", "buildpack", "organization_id", "organization_name", "space_id", "space_name", "stack_id", "state"},
)

applicationInstancesMetric := prometheus.NewGaugeVec(
Expand All @@ -50,7 +50,7 @@ func NewApplicationsCollector(
Help: "Number of desired Cloud Foundry Application Instances.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "organization_id", "organization_name", "space_id", "space_name", "state"},
[]string{"applicationID", "application_name", "organization_id", "organization_name", "space_id", "space_name", "state"},
)

applicationInstancesRunningMetric := prometheus.NewGaugeVec(
Expand All @@ -61,7 +61,7 @@ func NewApplicationsCollector(
Help: "Number of running Cloud Foundry Application Instances.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "organization_id", "organization_name", "space_id", "space_name", "state"},
[]string{"applicationID", "application_name", "organization_id", "organization_name", "space_id", "space_name", "state"},
)

applicationMemoryMbMetric := prometheus.NewGaugeVec(
Expand All @@ -72,7 +72,7 @@ func NewApplicationsCollector(
Help: "Cloud Foundry Application Memory (Mb).",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "organization_id", "organization_name", "space_id", "space_name"},
[]string{"applicationID", "application_name", "organization_id", "organization_name", "space_id", "space_name"},
)

applicationDiskQuotaMbMetric := prometheus.NewGaugeVec(
Expand All @@ -83,7 +83,7 @@ func NewApplicationsCollector(
Help: "Cloud Foundry Application Disk Quota (Mb).",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "application_name", "organization_id", "organization_name", "space_id", "space_name"},
[]string{"applicationID", "application_name", "organization_id", "organization_name", "space_id", "space_name"},
)

applicationsScrapesTotalMetric := prometheus.NewCounter(
Expand Down
2 changes: 1 addition & 1 deletion collectors/service_bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewServiceBindingsCollector(
Help: "Labeled Cloud Foundry Service Binding information with a constant '1' value.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"service_binding_id", "application_id", "service_instance_id"},
[]string{"service_binding_id", "applicationID", "service_instance_id"},
)

serviceBindingsScrapesTotalMetric := prometheus.NewCounter(
Expand Down
58 changes: 28 additions & 30 deletions collectors/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package collectors
import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/bosh-prometheus/cf_exporter/models"
"github.com/prometheus/client_golang/prometheus"
)

type TasksCollector struct {
namespace string
environment string
deployment string
namespace string
environment string
deployment string
taskInfoMetric *prometheus.GaugeVec
tasksCountMetric *prometheus.GaugeVec
tasksMemoryMbSumMetric *prometheus.GaugeVec
Expand All @@ -36,7 +36,7 @@ func NewTasksCollector(
Help: "Labeled Cloud Foundry Task information with a constant '1' value.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "state"},
[]string{"applicationID", "state"},
)

tasksCountMetric := prometheus.NewGaugeVec(
Expand All @@ -47,7 +47,7 @@ func NewTasksCollector(
Help: "Number of Cloud Foundry Tasks.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "state"},
[]string{"applicationID", "state"},
)

tasksMemoryMbSumMetric := prometheus.NewGaugeVec(
Expand All @@ -58,7 +58,7 @@ func NewTasksCollector(
Help: "Sum of Cloud Foundry Tasks Memory (Mb).",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "state"},
[]string{"applicationID", "state"},
)

tasksDiskQuotaMbSumMetric := prometheus.NewGaugeVec(
Expand All @@ -69,7 +69,7 @@ func NewTasksCollector(
Help: "Sum of Cloud Foundry Tasks Disk Quota (Mb).",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "state"},
[]string{"applicationID", "state"},
)

tasksOldestCreatedAtMetric := prometheus.NewGaugeVec(
Expand All @@ -80,7 +80,7 @@ func NewTasksCollector(
Help: "Number of seconds since 1970 of creation time of oldest Cloud Foundry task.",
ConstLabels: prometheus.Labels{"environment": environment, "deployment": deployment},
},
[]string{"application_id", "state"},
[]string{"applicationID", "state"},
)

tasksScrapesTotalMetric := prometheus.NewCounter(
Expand Down Expand Up @@ -134,9 +134,9 @@ func NewTasksCollector(
)

return &TasksCollector{
namespace: namespace,
environment: environment,
deployment: deployment,
namespace: namespace,
environment: environment,
deployment: deployment,
taskInfoMetric: taskInfoMetric,
tasksCountMetric: tasksCountMetric,
tasksMemoryMbSumMetric: tasksMemoryMbSumMetric,
Expand Down Expand Up @@ -186,58 +186,58 @@ func (c TasksCollector) Describe(ch chan<- *prometheus.Desc) {
c.lastTasksScrapeDurationSecondsMetric.Describe(ch)
}

func (c TasksCollector) reportTasksMetrics(objs *models.CFObjects, ch chan<- prometheus.Metric) error {
func (c TasksCollector) reportTasksMetrics(objs *models.CFObjects, ch chan<- prometheus.Metric) {
c.taskInfoMetric.Reset()
c.tasksCountMetric.Reset()
c.tasksMemoryMbSumMetric.Reset()
c.tasksDiskQuotaMbSumMetric.Reset()
c.tasksOldestCreatedAtMetric.Reset()

type keyType struct {
application_id string
state string
applicationID string
state string
}
groupedTasks := map[keyType][]*models.Task{}
groupedTasks := map[keyType][]models.Task{}
for _, task := range objs.Tasks {
application_id := "unavailable"
applicationID := "unavailable"
if app, ok := task.Relationships["app"]; ok && app.GUID != "" {
application_id = app.GUID
applicationID = app.GUID
}
key := keyType{application_id, string(task.State)}
key := keyType{applicationID, string(task.State)}

existingValue, ok := groupedTasks[key]
if !ok {
existingValue = []*models.Task{}
existingValue = []models.Task{}
}
groupedTasks[key] = append(existingValue, &task)
groupedTasks[key] = append(existingValue, task)
}

for key, tasks := range groupedTasks {
c.taskInfoMetric.WithLabelValues(
key.application_id,
key.applicationID,
key.state,
).Set(float64(1))

c.tasksCountMetric.WithLabelValues(
key.application_id,
key.applicationID,
key.state,
).Set(float64(len(tasks)))

memorySum := int64(0)
for _, task := range tasks {
memorySum += int64(task.MemoryInMb)
memorySum += task.MemoryInMb
}
c.tasksMemoryMbSumMetric.WithLabelValues(
key.application_id,
key.applicationID,
key.state,
).Set(float64(memorySum))

diskSum := int64(0)
for _, task := range tasks {
diskSum += int64(task.DiskInMb)
diskSum += task.DiskInMb
}
c.tasksDiskQuotaMbSumMetric.WithLabelValues(
key.application_id,
key.applicationID,
key.state,
).Set(float64(diskSum))

Expand All @@ -248,7 +248,7 @@ func (c TasksCollector) reportTasksMetrics(objs *models.CFObjects, ch chan<- pro
}
}
c.tasksOldestCreatedAtMetric.WithLabelValues(
key.application_id,
key.applicationID,
key.state,
).Set(float64(createdAtOldest.Unix()))
}
Expand All @@ -258,6 +258,4 @@ func (c TasksCollector) reportTasksMetrics(objs *models.CFObjects, ch chan<- pro
c.tasksMemoryMbSumMetric.Collect(ch)
c.tasksDiskQuotaMbSumMetric.Collect(ch)
c.tasksOldestCreatedAtMetric.Collect(ch)

return nil
}
4 changes: 2 additions & 2 deletions fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ var _ = Describe("Fetcher", func() {

When("tasks filter is set", func() {
BeforeEach(func() {
active = []string{ filters.Tasks }
expected = []string{ "info", "tasks" }
active = []string{filters.Tasks}
expected = []string{"info", "tasks"}
})
It("plans only specific jobs", func() {
Ω(jobs).Should(ConsistOf(expected))
Expand Down
4 changes: 2 additions & 2 deletions fetcher/sessionext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ var _ = Describe("Extensions", func() {
ghttp.VerifyRequest("GET", "/v3/tasks", "per_page=5000&states=PENDING,RUNNING,CANCELING"),
ghttp.RespondWith(http.StatusOK, serializeList(
models.Task{
GUID: "guid1",
GUID: "guid1",
State: constant.TaskPending,
},
models.Task{
GUID: "guid2",
GUID: "guid2",
State: constant.TaskCanceling,
},
)),
Expand Down