Skip to content

Commit

Permalink
feat: add time taken to complete deployment (#3715)
Browse files Browse the repository at this point in the history
* feat: add time taken to complete deployment

Signed-off-by: darshanime <deathbullet@gmail.com>

* feat: add test for adding deploy started at time

Signed-off-by: darshanime <deathbullet@gmail.com>

* feat: use hourglass for time to deploy

Signed-off-by: darshanime <deathbullet@gmail.com>

* feat: add comments to RevisionHistory fields

Signed-off-by: darshanime <deathbullet@gmail.com>
  • Loading branch information
darshanime committed Jun 10, 2020
1 parent e102ec1 commit d63ced4
Show file tree
Hide file tree
Showing 16 changed files with 471 additions and 345 deletions.
9 changes: 7 additions & 2 deletions assets/swagger.json
Expand Up @@ -4460,15 +4460,20 @@
"type": "object",
"title": "RevisionHistory contains information relevant to an application deployment",
"properties": {
"deployStartedAt": {
"$ref": "#/definitions/v1Time"
},
"deployedAt": {
"$ref": "#/definitions/v1Time"
},
"id": {
"type": "string",
"format": "int64"
"format": "int64",
"title": "ID is an auto incrementing identifier of the RevisionHistory"
},
"revision": {
"type": "string"
"type": "string",
"title": "Revision holds the revision of the sync"
},
"source": {
"$ref": "#/definitions/v1alpha1ApplicationSource"
Expand Down
13 changes: 7 additions & 6 deletions controller/state.go
Expand Up @@ -476,16 +476,17 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *ap
return &compRes
}

func (m *appStateManager) persistRevisionHistory(app *v1alpha1.Application, revision string, source v1alpha1.ApplicationSource) error {
func (m *appStateManager) persistRevisionHistory(app *v1alpha1.Application, revision string, source v1alpha1.ApplicationSource, startedAt metav1.Time) error {
var nextID int64
if len(app.Status.History) > 0 {
nextID = app.Status.History[len(app.Status.History)-1].ID + 1
nextID = app.Status.History.LastRevisionHistory().ID + 1
}
app.Status.History = append(app.Status.History, v1alpha1.RevisionHistory{
Revision: revision,
DeployedAt: metav1.NewTime(time.Now().UTC()),
ID: nextID,
Source: source,
Revision: revision,
DeployedAt: metav1.NewTime(time.Now().UTC()),
DeployStartedAt: startedAt,
ID: nextID,
Source: source,
})

app.Status.History = app.Status.History.Trunc(app.Spec.GetRevisionHistoryLimit())
Expand Down
8 changes: 7 additions & 1 deletion controller/state_test.go
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"encoding/json"
"testing"
"time"

"github.com/argoproj/gitops-engine/pkg/health"
synccommon "github.com/argoproj/gitops-engine/pkg/sync/common"
Expand Down Expand Up @@ -399,7 +400,7 @@ func Test_appStateManager_persistRevisionHistory(t *testing.T) {
app.Spec.RevisionHistoryLimit = &i
}
addHistory := func() {
err := manager.persistRevisionHistory(app, "my-revision", argoappv1.ApplicationSource{})
err := manager.persistRevisionHistory(app, "my-revision", argoappv1.ApplicationSource{}, metav1.Time{})
assert.NoError(t, err)
}
addHistory()
Expand Down Expand Up @@ -433,4 +434,9 @@ func Test_appStateManager_persistRevisionHistory(t *testing.T) {
setRevisionHistoryLimit(9)
addHistory()
assert.Len(t, app.Status.History, 9)

metav1NowTime := metav1.NewTime(time.Now())
err := manager.persistRevisionHistory(app, "my-revision", argoappv1.ApplicationSource{}, metav1NowTime)
assert.NoError(t, err)
assert.Equal(t, app.Status.History.LastRevisionHistory().DeployStartedAt, metav1NowTime)
}
2 changes: 1 addition & 1 deletion controller/sync.go
Expand Up @@ -178,7 +178,7 @@ func (m *appStateManager) SyncAppState(app *v1alpha1.Application, state *v1alpha
logEntry.WithField("duration", time.Since(start)).Info("sync/terminate complete")

if !syncOp.DryRun && len(syncOp.Resources) == 0 && state.Phase.Successful() {
err := m.persistRevisionHistory(app, compareResult.syncStatus.Revision, source)
err := m.persistRevisionHistory(app, compareResult.syncStatus.Revision, source, state.StartedAt)
if err != nil {
state.Phase = common.OperationError
state.Message = fmt.Sprintf("failed to record sync to history: %v", err)
Expand Down
7 changes: 7 additions & 0 deletions manifests/crds/application-crd.yaml
Expand Up @@ -625,13 +625,20 @@ spec:
description: RevisionHistory contains information relevant to an application
deployment
properties:
deployStartedAt:
description: DeployStartedAt holds the time the deployment started
format: date-time
type: string
deployedAt:
description: DeployedAt holds the time the deployment completed
format: date-time
type: string
id:
description: ID is an auto incrementing identifier of the RevisionHistory
format: int64
type: integer
revision:
description: Revision holds the revision of the sync
type: string
source:
description: ApplicationSource contains information about github
Expand Down
7 changes: 7 additions & 0 deletions manifests/ha/install.yaml
Expand Up @@ -626,13 +626,20 @@ spec:
description: RevisionHistory contains information relevant to an application
deployment
properties:
deployStartedAt:
description: DeployStartedAt holds the time the deployment started
format: date-time
type: string
deployedAt:
description: DeployedAt holds the time the deployment completed
format: date-time
type: string
id:
description: ID is an auto incrementing identifier of the RevisionHistory
format: int64
type: integer
revision:
description: Revision holds the revision of the sync
type: string
source:
description: ApplicationSource contains information about github
Expand Down
7 changes: 7 additions & 0 deletions manifests/ha/namespace-install.yaml
Expand Up @@ -626,13 +626,20 @@ spec:
description: RevisionHistory contains information relevant to an application
deployment
properties:
deployStartedAt:
description: DeployStartedAt holds the time the deployment started
format: date-time
type: string
deployedAt:
description: DeployedAt holds the time the deployment completed
format: date-time
type: string
id:
description: ID is an auto incrementing identifier of the RevisionHistory
format: int64
type: integer
revision:
description: Revision holds the revision of the sync
type: string
source:
description: ApplicationSource contains information about github
Expand Down
7 changes: 7 additions & 0 deletions manifests/install.yaml
Expand Up @@ -626,13 +626,20 @@ spec:
description: RevisionHistory contains information relevant to an application
deployment
properties:
deployStartedAt:
description: DeployStartedAt holds the time the deployment started
format: date-time
type: string
deployedAt:
description: DeployedAt holds the time the deployment completed
format: date-time
type: string
id:
description: ID is an auto incrementing identifier of the RevisionHistory
format: int64
type: integer
revision:
description: Revision holds the revision of the sync
type: string
source:
description: ApplicationSource contains information about github
Expand Down
7 changes: 7 additions & 0 deletions manifests/namespace-install.yaml
Expand Up @@ -626,13 +626,20 @@ spec:
description: RevisionHistory contains information relevant to an application
deployment
properties:
deployStartedAt:
description: DeployStartedAt holds the time the deployment started
format: date-time
type: string
deployedAt:
description: DeployedAt holds the time the deployment completed
format: date-time
type: string
id:
description: ID is an auto incrementing identifier of the RevisionHistory
format: int64
type: integer
revision:
description: Revision holds the revision of the sync
type: string
source:
description: ApplicationSource contains information about github
Expand Down

0 comments on commit d63ced4

Please sign in to comment.