Skip to content

Commit

Permalink
Measure step activation (#1006)
Browse files Browse the repository at this point in the history
* Measure step activation

* *
  • Loading branch information
ofalvai authored Oct 10, 2024
1 parent 9ea0867 commit 089e8e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions analytics/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const (
stepTitleProperty = "step_title"
stepVersionProperty = "step_version"
stepSourceProperty = "step_source"
stepActivateDurationProperty = "step_activate_duration_ms"
skippableProperty = "skippable"
timeoutProperty = "timeout"
runTimeProperty = "runtime"
Expand Down Expand Up @@ -108,7 +109,7 @@ type StepResult struct {
type Tracker interface {
SendWorkflowStarted(properties analytics.Properties, name string, title string)
SendWorkflowFinished(properties analytics.Properties, failed bool)
SendStepStartedEvent(properties analytics.Properties, info StepInfo, expandedInputs map[string]interface{}, originalInputs map[string]string)
SendStepStartedEvent(properties analytics.Properties, info StepInfo, activateDuration time.Duration, expandedInputs map[string]interface{}, originalInputs map[string]string)
SendStepFinishedEvent(properties analytics.Properties, result StepResult)
SendCLIWarning(message string)
SendToolVersionSnapshot(toolVersions, snapshotType string)
Expand Down Expand Up @@ -249,12 +250,13 @@ func (t tracker) SendToolVersionSnapshot(toolVersions, snapshotType string) {
t.tracker.Enqueue(toolVersionSnapshotEventName, properties)
}

func (t tracker) SendStepStartedEvent(properties analytics.Properties, info StepInfo, expandedInputs map[string]interface{}, originalInputs map[string]string) {
func (t tracker) SendStepStartedEvent(properties analytics.Properties, info StepInfo, activateDuration time.Duration, expandedInputs map[string]interface{}, originalInputs map[string]string) {
if !t.stateChecker.Enabled() {
return
}

extraProperties := []analytics.Properties{properties, prepareStartProperties(info)}
extraProperties = append(extraProperties, analytics.Properties{stepActivateDurationProperty: activateDuration.Milliseconds()})
if len(expandedInputs) > 0 {
inputMap := map[string]Input{}
for k, v := range expandedInputs {
Expand Down
2 changes: 1 addition & 1 deletion cli/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ func write(t *testing.T, content, toPth string) {

type noOpTracker struct{}

func (n noOpTracker) SendStepStartedEvent(analytics.Properties, cliAnalytics.StepInfo, map[string]interface{}, map[string]string) {
func (n noOpTracker) SendStepStartedEvent(analytics.Properties, cliAnalytics.StepInfo, time.Duration, map[string]interface{}, map[string]string) {
}
func (n noOpTracker) SendStepFinishedEvent(analytics.Properties, cliAnalytics.StepResult) {}
func (n noOpTracker) SendCLIWarning(string) {}
Expand Down
4 changes: 3 additions & 1 deletion cli/run_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ func (r WorkflowRunner) activateAndRunStep(
) activateAndRunStepResult {
//
// Activate step
activateStartTime := time.Now()
activateResult := r.activateStep(step, stepID, defaultStepLibSource, buildRunResults, isStepLibOfflineMode)
activateDuration := time.Since(activateStartTime)
if activateResult.Err != nil {
return newActivateAndRunStepResult(activateResult.Step, activateResult.StepInfoPtr, models.StepRunStatusCodePreparationFailed, 1, activateResult.Err, true, map[string]string{}, nil)
}
Expand Down Expand Up @@ -257,7 +259,7 @@ func (r WorkflowRunner) activateAndRunStep(
redactedStepInputs := prepareEnvsResult.RedactedStepInputs

// Run the step
tracker.SendStepStartedEvent(stepStartedProperties, prepareAnalyticsStepInfo(mergedStep, stepInfoPtr), redactedInputsWithType, redactedOriginalInputs)
tracker.SendStepStartedEvent(stepStartedProperties, prepareAnalyticsStepInfo(mergedStep, stepInfoPtr), activateDuration, redactedInputsWithType, redactedOriginalInputs)

exit, outEnvironments, stepRunErr := r.runStep(stepExecutionID, mergedStep, stepIDData, stepDir, stepDeclaredEnvironments, stepSecretValues, containerID, groupID)

Expand Down

0 comments on commit 089e8e7

Please sign in to comment.