-
Notifications
You must be signed in to change notification settings - Fork 360
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
[AN-146] Emit VM cost for GCP Batch #7582
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3b0c87c
[AN-146] Calculate VM cost for GCP Batch
lucymcnatt affde7e
adding a spec file for the BatchPollResultMonitorActorSpec
lucymcnatt 89986b7
remove comment
lucymcnatt 875e340
ugh formatting
lucymcnatt 9a1771b
getting vm info from job
lucymcnatt faecfeb
formatting
lucymcnatt 4c519d2
add test
lucymcnatt f711f3a
formatting
lucymcnatt 26f94ed
cleanup
lucymcnatt 2af8d35
Merge branch 'develop' into AN-146-batch-vm-cost
lucymcnatt 3134ed3
more tests + add support for missing location
lucymcnatt e0dd042
Merge branch 'develop' into AN-146-batch-vm-cost
lucymcnatt 369b42e
remove .vscode/settings.json
lucymcnatt c3b662d
extra run file
lucymcnatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
...src/test/scala/cromwell/backend/google/batch/actors/BatchPollResultMonitorActorSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package cromwell.backend.google.batch.actors | ||
|
||
import akka.actor.{ActorRef, ActorSystem, Props} | ||
import akka.testkit.{TestKit, TestProbe} | ||
import cats.data.Validated.Valid | ||
import common.mock.MockSugar | ||
import cromwell.backend.google.batch.models.GcpBatchRuntimeAttributes | ||
import cromwell.backend.{BackendJobDescriptor, BackendJobDescriptorKey, RuntimeAttributeDefinition} | ||
import cromwell.core.callcaching.NoDocker | ||
import cromwell.core.{ExecutionEvent, WorkflowOptions} | ||
import cromwell.core.logging.JobLogger | ||
import cromwell.services.cost.{GcpCostLookupRequest, GcpCostLookupResponse, InstantiatedVmInfo} | ||
import cromwell.services.keyvalue.InMemoryKvServiceActor | ||
import org.scalatest.flatspec.AnyFlatSpecLike | ||
import org.scalatest.matchers.should.Matchers | ||
import cromwell.backend.google.batch.models.GcpBatchTestConfig._ | ||
import wom.graph.CommandCallNode | ||
import cromwell.backend._ | ||
import cromwell.backend.google.batch.models._ | ||
import cromwell.backend.io.TestWorkflows | ||
import cromwell.backend.standard.pollmonitoring.ProcessThisPollResult | ||
import cromwell.services.metadata.CallMetadataKeys | ||
import cromwell.services.metadata.MetadataService.PutMetadataAction | ||
import org.slf4j.helpers.NOPLogger | ||
import wom.values.WomString | ||
|
||
import java.time.{Instant, OffsetDateTime} | ||
import java.time.temporal.ChronoUnit | ||
import scala.concurrent.duration.DurationInt | ||
|
||
class BatchPollResultMonitorActorSpec | ||
lucymcnatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
extends TestKit(ActorSystem("BatchPollResultMonitorActorSpec")) | ||
with AnyFlatSpecLike | ||
with BackendSpec | ||
with Matchers | ||
with MockSugar { | ||
|
||
var kvService: ActorRef = system.actorOf(Props(new InMemoryKvServiceActor), "kvService") | ||
val runtimeAttributesBuilder = GcpBatchRuntimeAttributes.runtimeAttributesBuilder(gcpBatchConfiguration) | ||
val jobLogger = mock[JobLogger] | ||
val serviceRegistry = TestProbe() | ||
|
||
val workflowDescriptor = buildWdlWorkflowDescriptor(TestWorkflows.HelloWorld) | ||
val call: CommandCallNode = workflowDescriptor.callable.taskCallNodes.head | ||
val jobKey = BackendJobDescriptorKey(call, None, 1) | ||
|
||
val jobDescriptor = BackendJobDescriptor(workflowDescriptor, | ||
jobKey, | ||
runtimeAttributes = Map.empty, | ||
evaluatedTaskInputs = Map.empty, | ||
NoDocker, | ||
None, | ||
Map.empty | ||
) | ||
|
||
val runtimeAttributes = Map("docker" -> WomString("ubuntu:latest")) | ||
|
||
val staticRuntimeAttributeDefinitions: Set[RuntimeAttributeDefinition] = | ||
GcpBatchRuntimeAttributes.runtimeAttributesBuilder(GcpBatchTestConfig.gcpBatchConfiguration).definitions.toSet | ||
|
||
val defaultedAttributes = | ||
RuntimeAttributeDefinition.addDefaultsToAttributes(staticRuntimeAttributeDefinitions, | ||
WorkflowOptions.fromMap(Map.empty).get | ||
)( | ||
runtimeAttributes | ||
) | ||
val validatedRuntimeAttributes = runtimeAttributesBuilder.build(defaultedAttributes, NOPLogger.NOP_LOGGER) | ||
|
||
val actor = system.actorOf( | ||
BatchPollResultMonitorActor.props(serviceRegistry.ref, | ||
workflowDescriptor, | ||
jobDescriptor, | ||
validatedRuntimeAttributes, | ||
Some(Gcp), | ||
jobLogger | ||
) | ||
) | ||
val vmInfo = InstantiatedVmInfo("europe-west9", "custom-16-32768", false) | ||
|
||
behavior of "BatchPollResultMonitorActor" | ||
|
||
it should "send a cost lookup request with the correct vm info after receiving a success pollResult" in { | ||
|
||
val terminalPollResult = | ||
RunStatus.Success(Seq(ExecutionEvent("fakeEvent", OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS))), | ||
Some(vmInfo) | ||
) | ||
val message = ProcessThisPollResult(terminalPollResult) | ||
|
||
actor ! message | ||
|
||
serviceRegistry.expectMsgPF(1.seconds) { case m: GcpCostLookupRequest => | ||
m.vmInfo shouldBe vmInfo | ||
} | ||
} | ||
|
||
it should "emit the correct cost metadata after receiving a costLookupResponse" in { | ||
|
||
val costLookupResponse = GcpCostLookupResponse(vmInfo, Valid(BigDecimal(0.1))) | ||
|
||
actor ! costLookupResponse | ||
|
||
serviceRegistry.expectMsgPF(1.seconds) { case m: PutMetadataAction => | ||
val event = m.events.head | ||
m.events.size shouldBe 1 | ||
event.key.key shouldBe CallMetadataKeys.VmCostPerHour | ||
event.value.get.value shouldBe "0.1" | ||
} | ||
} | ||
|
||
it should "emit the correct start time after receiving a running pollResult" in { | ||
|
||
val vmStartTime = OffsetDateTime.now().minus(2, ChronoUnit.HOURS) | ||
val pollResult = RunStatus.Running( | ||
Seq(ExecutionEvent(CallMetadataKeys.VmStartTime, vmStartTime)), | ||
Some(vmInfo) | ||
) | ||
val message = ProcessThisPollResult(pollResult) | ||
|
||
actor ! message | ||
|
||
serviceRegistry.expectMsgPF(1.seconds) { case m: PutMetadataAction => | ||
val event = m.events.head | ||
m.events.size shouldBe 1 | ||
event.key.key shouldBe CallMetadataKeys.VmStartTime | ||
assert( | ||
Instant | ||
.parse(event.value.get.value) | ||
.equals(vmStartTime.toInstant.truncatedTo(ChronoUnit.MILLIS)) | ||
) | ||
} | ||
} | ||
|
||
it should "emit the correct end time after receiving a running pollResult" in { | ||
|
||
val vmEndTime = OffsetDateTime.now().minus(2, ChronoUnit.HOURS) | ||
val pollResult = RunStatus.Running( | ||
Seq(ExecutionEvent(CallMetadataKeys.VmEndTime, vmEndTime)), | ||
Some(vmInfo) | ||
) | ||
val message = ProcessThisPollResult(pollResult) | ||
|
||
actor ! message | ||
|
||
serviceRegistry.expectMsgPF(1.seconds) { case m: PutMetadataAction => | ||
val event = m.events.head | ||
m.events.size shouldBe 1 | ||
event.key.key shouldBe CallMetadataKeys.VmEndTime | ||
assert( | ||
Instant | ||
.parse(event.value.get.value) | ||
.equals(vmEndTime.toInstant.truncatedTo(ChronoUnit.MILLIS)) | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
necessary in order to mock a final method in the gcp BatchServiceClient