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

perf(echo): don't send task events #4825

Merged
merged 1 commit into from
Jan 21, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionType.ORCHE
@Slf4j
class EchoNotifyingStageListener implements StageListener {
public static final String INCLUDE_FULL_EXECUTION_PROPERTY = "echo.events.includeFullExecution"
public static final String IGNORE_TASK_EVENTS_PROPERTY = "echo.events.ignoreTaskEvents"
private final EchoService echoService
private final ContextParameterProcessor contextParameterProcessor
private final DynamicConfigService dynamicConfigService
Expand All @@ -56,7 +57,9 @@ class EchoNotifyingStageListener implements StageListener {

@Override
void beforeTask(StageExecution stage, TaskExecution task) {
recordEvent('task', 'starting', stage, task)
if (!dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false)) {
recordEvent('task', 'starting', stage, task)
}
}

@Override
Expand All @@ -69,7 +72,7 @@ class EchoNotifyingStageListener implements StageListener {
void afterTask(StageExecution stage,
TaskExecution task) {
ExecutionStatus status = task.getStatus()
if (status == RUNNING) {
if (dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) || status == RUNNING) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ package com.netflix.spinnaker.orca.echo.spring

import com.netflix.spinnaker.kork.dynamicconfig.DynamicConfigService
import com.netflix.spinnaker.orca.echo.EchoService
import com.netflix.spinnaker.orca.listeners.Persister
import com.netflix.spinnaker.orca.pipeline.model.PipelineExecutionImpl
import com.netflix.spinnaker.orca.pipeline.model.StageExecutionImpl
import com.netflix.spinnaker.orca.pipeline.model.TaskExecutionImpl
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository
import com.netflix.spinnaker.orca.pipeline.util.ContextParameterProcessor
import spock.lang.Shared
import spock.lang.Specification
import spock.lang.Subject
import spock.lang.Unroll
import static com.netflix.spinnaker.orca.api.pipeline.models.ExecutionStatus.*
import static com.netflix.spinnaker.orca.echo.spring.EchoNotifyingStageListener.INCLUDE_FULL_EXECUTION_PROPERTY
import static com.netflix.spinnaker.orca.echo.spring.EchoNotifyingStageListener.IGNORE_TASK_EVENTS_PROPERTY


class EchoNotifyingStageListenerSpec extends Specification {

Expand All @@ -30,6 +30,7 @@ class EchoNotifyingStageListenerSpec extends Specification {
@Shared
def orchestrationStage = new StageExecutionImpl(PipelineExecutionImpl.newOrchestration("orca"), "test")

@Unroll
def "triggers an event when a task step starts"() {
given:
def task = new TaskExecutionImpl(status: NOT_STARTED)
Expand All @@ -38,7 +39,12 @@ class EchoNotifyingStageListenerSpec extends Specification {
echoListener.beforeTask(pipelineStage, task)

then:
1 * echoService.recordEvent({ event -> event.details.type == "orca:task:starting" })
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> ignoreTaskEvents
if (!ignoreTaskEvents) 1 * echoService.recordEvent({ event -> event.details.type == "orca:task:starting" })
else 0 * echoService.recordEvent(_)

where:
ignoreTaskEvents << [true, false]
}

def "triggers an event when a stage starts"() {
Expand All @@ -49,20 +55,25 @@ class EchoNotifyingStageListenerSpec extends Specification {
1 * echoService.recordEvent({ event -> event.details.type == "orca:stage:starting" })
}

@Unroll
def "triggers an event when a task starts"() {
given:
def task = new TaskExecutionImpl(stageStart: false)

and:
def events = []
echoService.recordEvent(_) >> { events << it[0]; null }

when:
echoListener.beforeTask(pipelineStage, task)

then:
events.size() == 1
events.details.type == ["orca:task:starting"]
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> ignoreTaskEvents
if (!ignoreTaskEvents) {
def events = []
1 * echoService.recordEvent(_) >> { events << it[0]; null }
events.size() == 1
events.details.type == ["orca:task:starting"]
} else 0 * echoService.recordEvent(_)

where:
ignoreTaskEvents << [true, false]
}

@Unroll
Expand All @@ -75,17 +86,25 @@ class EchoNotifyingStageListenerSpec extends Specification {
echoListener.afterTask(stage, task)

then:
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> ignoreTaskEvents
invocations * echoService.recordEvent(_)

where:
invocations | stage | executionStatus | isEnd
0 | orchestrationStage | RUNNING | false
1 | orchestrationStage | STOPPED | false
1 | orchestrationStage | SUCCEEDED | false
1 | pipelineStage | SUCCEEDED | false
1 | pipelineStage | SUCCEEDED | true
1 | pipelineStage | TERMINAL | false
1 | orchestrationStage | SUCCEEDED | true
invocations | stage | executionStatus | isEnd | ignoreTaskEvents
0 | orchestrationStage | RUNNING | false | false
1 | orchestrationStage | STOPPED | false | false
1 | orchestrationStage | SUCCEEDED | false | false
1 | pipelineStage | SUCCEEDED | false | false
1 | pipelineStage | SUCCEEDED | true | false
1 | pipelineStage | TERMINAL | false | false
1 | orchestrationStage | SUCCEEDED | true | false
0 | orchestrationStage | RUNNING | false | true
0 | orchestrationStage | STOPPED | false | true
0 | orchestrationStage | SUCCEEDED | false | true
0 | pipelineStage | SUCCEEDED | false | true
0 | pipelineStage | SUCCEEDED | true | true
0 | pipelineStage | TERMINAL | false | true
0 | orchestrationStage | SUCCEEDED | true | true

taskName = "xxx"
}
Expand Down Expand Up @@ -121,6 +140,7 @@ class EchoNotifyingStageListenerSpec extends Specification {
echoListener.afterTask(stage, task)

then:
1 * dynamicConfigService.getConfig(Boolean, IGNORE_TASK_EVENTS_PROPERTY, false) >> false
1 * dynamicConfigService.getConfig(Boolean, INCLUDE_FULL_EXECUTION_PROPERTY, _) >> fullExecutionToggle
message.details.source == "orca"
message.details.application == pipelineStage.execution.application
Expand Down
Loading