Skip to content

Commit

Permalink
feat(STONEINTG-534): add SLI to measure time from SEB created to ready
Browse files Browse the repository at this point in the history
Signed-off-by: Jing Qi <[email protected]>

Add metric for measuring the time between SEB is created and SEB is
ready to use
  • Loading branch information
jinqi7 committed Sep 13, 2023
1 parent fd8631a commit 1df72e9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions controllers/binding/snapshotenvironmentbinding_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func (a *Adapter) EnsureIntegrationTestPipelineForScenarioExists() (controller.O
}
a.logger.Info("The SnapshotEnvironmentBinding's deployment succeeded", "snapshotEnvironmentBinding.Name", a.snapshotEnvironmentBinding.Name)

gitops.PrepareAndRegisterSEBReady(a.snapshotEnvironmentBinding)

if a.integrationTestScenario != nil {
integrationPipelineRun, err := loader.GetLatestPipelineRunForSnapshotAndScenario(a.client, a.context, a.loader, a.snapshot, a.integrationTestScenario)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions gitops/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.
package gitops

import (
"time"

applicationapiv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
"github.com/redhat-appstudio/integration-service/metrics"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -116,3 +119,9 @@ func hasDeploymentFailed(objectOld, objectNew client.Object) bool {
}
return (oldCondition == nil || oldCondition.Status != metav1.ConditionTrue) && newCondition.Status == metav1.ConditionTrue
}

// PrepareAndRegisterSEBReady is to do preparation and register SEBCreatedToReadySeconds
func PrepareAndRegisterSEBReady(seb *applicationapiv1alpha1.SnapshotEnvironmentBinding) {
sebReadyTime := &metav1.Time{Time: time.Now()}
go metrics.RegisterSEBCreatedToReady(seb.GetCreationTimestamp(), sebReadyTime)
}
1 change: 1 addition & 0 deletions gitops/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() {

Expect(gitops.IsBindingDeployed(newSnapshotEnvironmentBinding)).NotTo(BeTrue())
Expect(gitops.HaveBindingsFailed(newSnapshotEnvironmentBinding)).NotTo(BeTrue())
gitops.PrepareAndRegisterSEBReady(newSnapshotEnvironmentBinding)
})

It("ensures an existing deployed SnapshotEnvironmentBinding conditions are recognized", func() {
Expand Down
16 changes: 16 additions & 0 deletions metrics/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ var (
},
)

SEBCreatedToReadySeconds = prometheus.NewHistogram(
sebCreatedToReadySecondsOpts,
)

sebCreatedToReadySecondsOpts = prometheus.HistogramOpts{
Name: "seb_created_to_ready_seconds",
Help: "Time duration from the moment the snapshotEnvironmentBinding was created till the snapshot is deployed to the environtment",
Buckets: []float64{1, 5, 10, 20, 40, 60, 80, 120, 160, 200, 300},
}

IntegrationPipelineRunTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "integration_pipelinerun_total",
Expand Down Expand Up @@ -87,6 +97,11 @@ func RegisterPipelineRunStarted(snapshotCreatedTime metav1.Time, pipelineRunStar
SnapshotCreatedToPipelineRunStartedSeconds.Observe(pipelineRunStartTime.Sub(snapshotCreatedTime.Time).Seconds())
}

func RegisterSEBCreatedToReady(sebCreatedTime metav1.Time, sebReadyTime *metav1.Time) {
SEBCreatedToReadySeconds.
Observe(sebReadyTime.Sub(sebCreatedTime.Time).Seconds())
}

func RegisterIntegrationResponse(buildPipelineFinishTime metav1.Time, inProgressTime *metav1.Time) {
IntegrationSvcResponseSeconds.Observe(inProgressTime.Sub(buildPipelineFinishTime.Time).Seconds())
}
Expand All @@ -103,6 +118,7 @@ func RegisterNewIntegrationPipelineRun(snapshotCreatedTime metav1.Time, pipeline
func init() {
metrics.Registry.MustRegister(
SnapshotCreatedToPipelineRunStartedSeconds,
SEBCreatedToReadySeconds,
IntegrationSvcResponseSeconds,
IntegrationPipelineRunTotal,
SnapshotConcurrentTotal,
Expand Down
21 changes: 21 additions & 0 deletions metrics/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
. "github.com/onsi/gomega"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/redhat-appstudio/operator-toolkit/test"
"sigs.k8s.io/controller-runtime/pkg/metrics"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -196,4 +197,24 @@ var _ = Describe("Metrics Integration", Ordered, func() {
strings.NewReader(readerData))).To(Succeed())
})
})

When("RegisterSEBCreatedToReady is called", func() {
var completionTime *metav1.Time
var startTime metav1.Time

BeforeEach(func() {
completionTime = &metav1.Time{}
startTime = metav1.Time{Time: completionTime.Add(-60 * time.Second)}
})

It("adds an observation to ReleaseProcessingDurationSeconds", func() {
RegisterSEBCreatedToReady(startTime, completionTime)
Expect(testutil.CollectAndCompare(SEBCreatedToReadySeconds,
test.NewHistogramReader(
sebCreatedToReadySecondsOpts,
nil,
&startTime, completionTime,
))).To(Succeed())
})
})
})

0 comments on commit 1df72e9

Please sign in to comment.