-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: xshao <[email protected]>
- Loading branch information
Showing
10 changed files
with
393 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
"github.com/onsi/gomega" | ||
"testing" | ||
) | ||
|
||
// Test | ||
func TestNodeTurnsOntoStep(t *testing.T) { | ||
g := gomega.NewGomegaWithT(t) | ||
|
||
r := &RollingUpgradeStatus{} | ||
|
||
r.NodeStep("test-asg", "node-1", NodeRotationKickoff) | ||
|
||
g.Expect(r.InProcessingNodes).NotTo(gomega.BeNil()) | ||
g.Expect(r.Statistics).To(gomega.BeNil()) | ||
|
||
r.NodeStep("test-asg", "node-1", NodeRotationDesiredNodeReady) | ||
|
||
g.Expect(r.Statistics).NotTo(gomega.BeNil()) | ||
g.Expect(len(r.Statistics)).To(gomega.Equal(1)) | ||
g.Expect(r.Statistics[0].StepName).To(gomega.Equal(NodeRotationKickoff)) | ||
|
||
//Retry desired_node_ready | ||
r.NodeStep("test-asg", "node-1", NodeRotationDesiredNodeReady) | ||
g.Expect(len(r.Statistics)).To(gomega.Equal(1)) | ||
g.Expect(r.Statistics[0].StepName).To(gomega.Equal(NodeRotationKickoff)) | ||
|
||
//Retry desired_node_ready again | ||
r.NodeStep("test-asg", "node-1", NodeRotationDesiredNodeReady) | ||
g.Expect(len(r.Statistics)).To(gomega.Equal(1)) | ||
g.Expect(r.Statistics[0].StepName).To(gomega.Equal(NodeRotationKickoff)) | ||
|
||
//Completed | ||
r.NodeStep("test-asg", "node-1", NodeRotationCompleted) | ||
g.Expect(len(r.Statistics)).To(gomega.Equal(3)) | ||
g.Expect(r.Statistics[1].StepName).To(gomega.Equal(NodeRotationDesiredNodeReady)) | ||
g.Expect(r.Statistics[2].StepName).To(gomega.Equal(NodeRotationTotal)) | ||
|
||
//Second node | ||
r.NodeStep("test-asg", "node-2", NodeRotationKickoff) | ||
g.Expect(len(r.Statistics)).To(gomega.Equal(3)) | ||
|
||
r.NodeStep("test-asg", "node-2", NodeRotationDesiredNodeReady) | ||
g.Expect(len(r.Statistics)).To(gomega.Equal(3)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/keikoproj/upgrade-manager/controllers/common/log" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"reflect" | ||
"sigs.k8s.io/controller-runtime/pkg/metrics" | ||
"strings" | ||
"time" | ||
) | ||
|
||
//All cluster level node upgrade statistics | ||
|
||
var nodeRotationTotal = prometheus.NewHistogram( | ||
prometheus.HistogramOpts{ | ||
Namespace: "node", | ||
Name: "rotation_total_seconds", | ||
Help: "Node rotation total", | ||
Buckets: []float64{ | ||
10.0, | ||
30.0, | ||
60.0, | ||
90.0, | ||
120.0, | ||
180.0, | ||
300.0, | ||
600.0, | ||
900.0, | ||
}, | ||
}) | ||
|
||
var stepSummaries = make(map[string]map[string]prometheus.Summary) | ||
|
||
func InitMetrics() { | ||
metrics.Registry.MustRegister(nodeRotationTotal) | ||
} | ||
|
||
// Add rolling update step duration when the step is completed | ||
func AddRollingUpgradeStepDuration(asgName string, stepName string, duration time.Duration) { | ||
if strings.EqualFold(stepName, "total") { //Histogram | ||
nodeRotationTotal.Observe(duration.Seconds()) | ||
} else { //Summary | ||
var steps map[string]prometheus.Summary | ||
if m, ok := stepSummaries[asgName]; !ok { | ||
steps = make(map[string]prometheus.Summary) | ||
stepSummaries[asgName] = steps | ||
} else { | ||
steps = m | ||
} | ||
|
||
var summary prometheus.Summary | ||
if s, ok := steps[stepName]; !ok { | ||
summary = prometheus.NewSummary( | ||
prometheus.SummaryOpts{ | ||
Namespace: "node", | ||
Name: stepName + "_seconds", | ||
Help: "Summary for node " + stepName, | ||
ConstLabels: prometheus.Labels{"asg": asgName}, | ||
}) | ||
err := metrics.Registry.Register(summary) | ||
if err != nil { | ||
if reflect.TypeOf(err).String() == "prometheus.AlreadyRegisteredError" { | ||
log.Warnf("summary was registered again, ASG: %s, step: %s", asgName, stepName) | ||
} else { | ||
log.Errorf("register summary error, ASG: %s, step: %s, %v", asgName, stepName, err) | ||
} | ||
} | ||
steps[stepName] = summary | ||
} else { | ||
summary = s | ||
} | ||
summary.Observe(duration.Seconds()) | ||
} | ||
} |
Oops, something went wrong.