Skip to content

Commit

Permalink
fix some typo and func name
Browse files Browse the repository at this point in the history
  • Loading branch information
googs1025 committed Jul 5, 2024
1 parent 434f4d2 commit d8495da
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package constants

const (
// JobSetName is the name of the JobSet
JobSetName = "jobset"
// JobSetSubsystemName is the name of the subsystem used for metrics
JobSetSubsystemName = "jobset"

// JobOwnerKey is the field used to build the JobSet index, which enables looking up Jobs
// by the owner JobSet quickly.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/failure_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func setJobSetFailedCondition(js *jobset.JobSet, reason, msg string, updateStatu
setCondition(js, makeFailedConditionOpts(reason, msg), updateStatusOpts)
js.Status.TerminalState = string(jobset.JobSetFailed)
// Update the metrics
metrics.FailedCase(fmt.Sprintf("%s/%s", js.Namespace, js.Name))
metrics.JobSetFailed(fmt.Sprintf("%s/%s", js.Namespace, js.Name))
}

// findJobFailureTimeAndReason is a helper function which extracts the Job failure condition from a Job,
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/jobset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ func setJobSetCompletedCondition(js *jobset.JobSet, updateStatusOpts *statusUpda
setCondition(js, makeCompletedConditionsOpts(), updateStatusOpts)
js.Status.TerminalState = string(jobset.JobSetCompleted)
// Update the metrics
metrics.CompletedCase(fmt.Sprintf("%s/%s", js.Namespace, js.Name))
metrics.JobSetCompleted(fmt.Sprintf("%s/%s", js.Namespace, js.Name))
}

// setJobSetSuspendedCondition sets a condition on the JobSet status indicating it is currently suspended.
Expand Down
20 changes: 10 additions & 10 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ import (
var (
FailedTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: constants.JobSetName,
Subsystem: constants.JobSetSubsystemName,
Name: "jobset_failed_total",
Help: `The total number of jobset failed case`,
}, []string{"jobsetName"},
Help: `The total number of failed JobSets`,
}, []string{"jobset_name"},
)

CompletedTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: constants.JobSetName,
Subsystem: constants.JobSetSubsystemName,
Name: "jobset_completed_total",
Help: `The total number of jobset completed case`,
}, []string{"jobsetName"},
Help: `The total number of completed JobSets`,
}, []string{"jobset_name"},
)
)

// FailedCase records the failed case
// JobSetFailed records the failed case
// label values: namespace/name
func FailedCase(namespaceName string) {
func JobSetFailed(namespaceName string) {
FailedTotal.WithLabelValues(namespaceName).Inc()
}

// CompletedCase records the completed case
// JobSetCompleted records the completed case
// label values: namespace/name
func CompletedCase(namespaceName string) {
func JobSetCompleted(namespaceName string) {
CompletedTotal.WithLabelValues(namespaceName).Inc()
}

Expand Down
29 changes: 14 additions & 15 deletions pkg/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package metrics

import (
"fmt"
"testing"

"github.com/prometheus/client_golang/prometheus"
Expand All @@ -27,39 +26,39 @@ import (
func TestFailedCase(t *testing.T) {
prometheus.MustRegister(FailedTotal)

FailedCase(fmt.Sprintf("%s/%s", "default", "jobset-test1"))
FailedCase(fmt.Sprintf("%s/%s", "default", "jobset-test2"))
FailedCase(fmt.Sprintf("%s/%s", "default", "jobset-test1"))
JobSetFailed("default/jobset-test1")
JobSetFailed("default/jobset-test2")
JobSetFailed("default/jobset-test1")

if count := testutil.CollectAndCount(FailedTotal); count != 2 {
t.Errorf("Expecting %d metrics, got: %d", 2, count)
}

if count := testutil.ToFloat64(FailedTotal.WithLabelValues(fmt.Sprintf("%s/%s", "default", "jobset-test1"))); count != float64(2) {
t.Errorf("Expecting %s to have value %d, but got %f", fmt.Sprintf("%s/%s", "default", "jobset-test1"), 2, count)
if count := testutil.ToFloat64(FailedTotal.WithLabelValues("default/jobset-test1")); count != float64(2) {
t.Errorf("Expecting %s to have value %d, but got %f", "default/jobset-test1", 2, count)
}

if count := testutil.ToFloat64(FailedTotal.WithLabelValues(fmt.Sprintf("%s/%s", "default", "jobset-test2"))); count != float64(1) {
t.Errorf("Expecting %s to have value %d, but got %f", fmt.Sprintf("%s/%s", "default", "jobset-test2"), 1, count)
if count := testutil.ToFloat64(FailedTotal.WithLabelValues("default/jobset-test2")); count != float64(1) {
t.Errorf("Expecting %s to have value %d, but got %f", "default/jobset-test2", 1, count)
}
}

func TestCompletedCase(t *testing.T) {
prometheus.MustRegister(CompletedTotal)

CompletedCase(fmt.Sprintf("%s/%s", "default", "jobset-test1"))
CompletedCase(fmt.Sprintf("%s/%s", "default", "jobset-test2"))
CompletedCase(fmt.Sprintf("%s/%s", "default", "jobset-test1"))
JobSetCompleted("default/jobset-test1")
JobSetCompleted("default/jobset-test2")
JobSetCompleted("default/jobset-test1")

if count := testutil.CollectAndCount(CompletedTotal); count != 2 {
t.Errorf("Expecting %d metrics, got: %d", 2, count)
}

if count := testutil.ToFloat64(CompletedTotal.WithLabelValues(fmt.Sprintf("%s/%s", "default", "jobset-test1"))); count != float64(2) {
t.Errorf("Expecting %s to have value %d, but got %f", "lws-sample-0", 2, count)
if count := testutil.ToFloat64(CompletedTotal.WithLabelValues("default/jobset-test1")); count != float64(2) {
t.Errorf("Expecting %s to have value %d, but got %f", "default/jobset-test1", 2, count)
}

if count := testutil.ToFloat64(CompletedTotal.WithLabelValues(fmt.Sprintf("%s/%s", "default", "jobset-test2"))); count != float64(1) {
t.Errorf("Expecting %s to have value %d, but got %f", "lws-sample-1", 1, count)
if count := testutil.ToFloat64(CompletedTotal.WithLabelValues("default/jobset-test2")); count != float64(1) {
t.Errorf("Expecting %s to have value %d, but got %f", "default/jobset-test2", 1, count)
}
}

0 comments on commit d8495da

Please sign in to comment.