Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
report metric only once when workflow timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
apanicker-nflx committed Aug 17, 2020
1 parent 6bd8a37 commit c5789ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
@@ -1,17 +1,14 @@
/*
* Copyright 2016 Netflix, Inc.
* Copyright 2020 Netflix, Inc.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.netflix.conductor.core.execution;

Expand Down Expand Up @@ -509,13 +506,14 @@ void checkWorkflowTimeout(Workflow workflow) {
return;
}

String reason = String.format("Workflow timed out after %d seconds. Timeout configured as %d. " +
"Timeout policy configured to %s",elapsedTime/1000L, timeout, workflowDef.getTimeoutPolicy().name());
Monitors.recordWorkflowTermination(workflow.getWorkflowName(), WorkflowStatus.TIMED_OUT, workflow.getOwnerApp());
String reason = String.format("Workflow '%s' timed out after %d seconds. Timeout configured as %d. " +
"Timeout policy configured to %s", workflow.getWorkflowId(), elapsedTime / 1000L, timeout,
workflowDef.getTimeoutPolicy().name());

switch (workflowDef.getTimeoutPolicy()) {
case ALERT_ONLY:
LOGGER.info(reason);
Monitors.recordWorkflowTermination(workflow.getWorkflowName(), WorkflowStatus.TIMED_OUT, workflow.getOwnerApp());
return;
case TIME_OUT_WF:
throw new TerminateWorkflowException(reason, WorkflowStatus.TIMED_OUT);
Expand Down
Expand Up @@ -984,6 +984,7 @@ public void testCheckWorkflowTimeout() {
Workflow workflow = new Workflow();
workflow.setOwnerApp("junit");
workflow.setStartTime(System.currentTimeMillis() - 5_000);
workflow.setWorkflowId("workflow_id");

// no-op
workflow.setWorkflowDefinition(null);
Expand All @@ -1004,7 +1005,7 @@ public void testCheckWorkflowTimeout() {
workflowDef.setTimeoutPolicy(WorkflowDef.TimeoutPolicy.TIME_OUT_WF);
workflow.setWorkflowDefinition(workflowDef);
exception.expect(TerminateWorkflowException.class);
exception.expectMessage("Workflow timed out");
exception.expectMessage("Workflow 'workflow_id' timed out");
deciderService.checkWorkflowTimeout(workflow);
assertEquals(1, counter.count());
}
Expand Down

0 comments on commit c5789ca

Please sign in to comment.