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(operator): compute deployment interval on deployment endtime #842

Merged
merged 1 commit into from
Feb 14, 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
2 changes: 1 addition & 1 deletion operator/controllers/common/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func ObserveDeploymentInterval(ctx context.Context, client client.Client, reconc
continue
}

previousInterval := reconcileObject.GetEndTime().Sub(predecessor.GetStartTime())
previousInterval := reconcileObject.GetEndTime().Sub(predecessor.GetEndTime())
gauge.Observe(ctx, previousInterval.Seconds(), reconcileObject.GetDurationMetricsAttributes()...)
}
}
Expand Down
91 changes: 80 additions & 11 deletions operator/controllers/common/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,70 @@ func TestMetrics_ObserveDeploymentInterval(t *testing.T) {
},
err: nil,
},
{
name: "previous version - object found with endtime and revision",
list: &lifecyclev1alpha2.KeptnAppVersionList{},
previous: &lifecyclev1alpha2.KeptnAppVersion{},
clientObjects: &lifecyclev1alpha2.KeptnAppVersionList{
Items: []lifecyclev1alpha2.KeptnAppVersion{
{
ObjectMeta: metav1.ObjectMeta{
Name: "appName-version-1",
Namespace: "namespace",
Generation: 1,
},
Spec: lifecyclev1alpha2.KeptnAppVersionSpec{
KeptnAppSpec: lifecyclev1alpha2.KeptnAppSpec{
Version: "version",
},
AppName: "appName",
PreviousVersion: "previousVersion",
},
Status: lifecyclev1alpha2.KeptnAppVersionStatus{
EndTime: metav1.Time{Time: metav1.Now().Time.Add(5 * time.Second)},
StartTime: metav1.Time{Time: metav1.Now().Time},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "appName-previousVersion-2",
Namespace: "namespace",
Generation: 2,
},
Spec: lifecyclev1alpha2.KeptnAppVersionSpec{
KeptnAppSpec: lifecyclev1alpha2.KeptnAppSpec{
Version: "previousVersion",
},
AppName: "appName",
PreviousVersion: "",
},
Status: lifecyclev1alpha2.KeptnAppVersionStatus{
EndTime: metav1.Time{Time: metav1.Now().Time.Add(5 * time.Second)},
StartTime: metav1.Time{Time: metav1.Now().Time},
},
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "appName-previousVersion-1",
Namespace: "namespace",
Generation: 1,
},
Spec: lifecyclev1alpha2.KeptnAppVersionSpec{
KeptnAppSpec: lifecyclev1alpha2.KeptnAppSpec{
Version: "previousVersion",
},
AppName: "appName",
PreviousVersion: "",
},
Status: lifecyclev1alpha2.KeptnAppVersionStatus{
EndTime: metav1.Time{Time: metav1.Now().Time.Add(5 * time.Second)},
StartTime: metav1.Time{Time: metav1.Now().Time},
},
},
},
},
err: nil,
},
}

gauge, err := noop.NewNoopMeter().AsyncFloat64().Gauge("mine")
Expand All @@ -322,12 +386,12 @@ func TestGetPredecessor(t *testing.T) {
Items: []lifecyclev1alpha2.KeptnAppVersion{
{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-1.0.0-1",
Name: "my-app-1.0.0-1",
Generation: 1,
},
Spec: lifecyclev1alpha2.KeptnAppVersionSpec{
KeptnAppSpec: lifecyclev1alpha2.KeptnAppSpec{
Version: "1.0.0",
Revision: 0,
Version: "1.0.0",
},
AppName: "my-app",
},
Expand All @@ -338,12 +402,12 @@ func TestGetPredecessor(t *testing.T) {
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-1.0.0-2",
Name: "my-app-1.0.0-2",
Generation: 2,
},
Spec: lifecyclev1alpha2.KeptnAppVersionSpec{
KeptnAppSpec: lifecyclev1alpha2.KeptnAppSpec{
Version: "1.0.0",
Revision: 0,
Version: "1.0.0",
},
AppName: "my-app",
},
Expand All @@ -354,14 +418,15 @@ func TestGetPredecessor(t *testing.T) {
},
{
ObjectMeta: metav1.ObjectMeta{
Name: "my-app-1.1.0-1",
Name: "my-app-1.1.0-1",
Generation: 1,
},
Spec: lifecyclev1alpha2.KeptnAppVersionSpec{
KeptnAppSpec: lifecyclev1alpha2.KeptnAppSpec{
Version: "1.0.0",
Revision: 0,
Version: "1.1.0",
},
AppName: "my-app",
AppName: "my-app",
PreviousVersion: "1.0.0",
},
Status: lifecyclev1alpha2.KeptnAppVersionStatus{
StartTime: metav1.NewTime(now),
Expand All @@ -375,10 +440,14 @@ func TestGetPredecessor(t *testing.T) {
require.Nil(t, err)

latestAppVersion, err := interfaces.NewMetricsObjectWrapperFromClientObject(appVersionsWrapper.GetItems()[2])

require.Nil(t, err)

require.Equal(t, "1.0.0", latestAppVersion.GetPreviousVersion())

predecessor := getPredecessor(latestAppVersion, appVersionsWrapper.GetItems())

require.Equal(t, "", predecessor.GetPreviousVersion())

expectedPredecessor, err := interfaces.NewMetricsObjectWrapperFromClientObject(appVersionsWrapper.GetItems()[0])
require.Nil(t, err)

Expand Down