-
Notifications
You must be signed in to change notification settings - Fork 4
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
WOR-1823 part 3: workspace deletion refactoring #3049
Changes from all commits
a85850a
5c4d9a2
7a44f60
860cc9a
ec3c984
fff57c0
bc2f459
7b62fdb
4a64f2f
8ee5087
7956f1e
09cff13
f6ce425
b280c87
fb66ae0
c6e10d1
4a9082c
9bac0c0
21899ff
2be1d09
b727928
be34c72
696ddd3
e4cdad4
5b944c5
8f932ec
f644662
8190331
8a4d4d5
905e3f1
0a691a4
6b3e91b
daf7335
d5e3507
52b1b18
aa4f1dc
5c5067a
74fe8a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,11 +40,12 @@ object MetricsHelper { | |
def incrementFastPassRevokedCounter(memberType: IamMemberType): IO[Unit] = | ||
incrementFastPassUpdatedCounter(memberType, "revoke") | ||
|
||
def incrementCounter(name: String, | ||
count: Int = 1, | ||
labels: Map[String, String] = Map.empty, | ||
description: Option[String] = None | ||
): IO[Unit] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unneccesary IO wrapping - only called in one place anyway. |
||
def incrementCounter( | ||
name: String, | ||
count: Int = 1, | ||
labels: Map[String, String] = Map.empty, | ||
description: Option[String] = None | ||
): Unit = { | ||
val metrics = meter | ||
.counterBuilder(s"$PREFIX/$name") | ||
.setDescription(description.getOrElse("none")) | ||
|
@@ -53,7 +54,7 @@ object MetricsHelper { | |
labels.foreach { case (k, v) => | ||
labelBuilder.put(k, v) | ||
} | ||
IO(metrics.add(count, labelBuilder.build())) | ||
metrics.add(count, labelBuilder.build()) | ||
} | ||
|
||
private def incrementFastPassUpdatedCounter(memberType: IamMemberType, action: String) = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.broadinstitute.dsde.rawls.submissions | ||
|
||
import org.broadinstitute.dsde.rawls.dataaccess.SlickDataSource | ||
import org.broadinstitute.dsde.rawls.dataaccess.slick.WorkflowRecord | ||
import org.broadinstitute.dsde.rawls.metrics.RawlsInstrumented | ||
import org.broadinstitute.dsde.rawls.model.{WorkflowStatuses, Workspace, WorkspaceName} | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
/** | ||
* Data access for workflow submissions | ||
* | ||
* The intention of this class is to hide direct dependencies on Slick behind a relatively clean interface | ||
* to ease testability of higher level business logic. | ||
*/ | ||
class SubmissionsRepository( | ||
dataSource: SlickDataSource, | ||
trackDetailedSubmissionMetrics: Boolean = true, | ||
override val workbenchMetricBaseName: String | ||
) extends RawlsInstrumented { | ||
|
||
import dataSource.dataAccess.driver.api._ | ||
|
||
def getActiveWorkflowsAndSetStatusToAborted( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was moved in wholesale from |
||
workspace: Workspace | ||
)(implicit ex: ExecutionContext): Future[Seq[WorkflowRecord]] = | ||
dataSource | ||
.inTransaction { dataAccess => | ||
for { | ||
// Gather any active workflows with external ids | ||
workflowsToAbort <- dataAccess.workflowQuery.findActiveWorkflowsWithExternalIds(workspace) | ||
|
||
// If a workflow is not done, automatically change its status to Aborted | ||
_ <- dataAccess.workflowQuery.findWorkflowsByWorkspace(workspace).result.map { workflowRecords => | ||
workflowRecords | ||
.filter(workflowRecord => !WorkflowStatuses.withName(workflowRecord.status).isDone) | ||
.foreach { workflowRecord => | ||
dataAccess.workflowQuery.updateStatus(workflowRecord, WorkflowStatuses.Aborted) { status => | ||
if (trackDetailedSubmissionMetrics) | ||
Option( | ||
workflowStatusCounter( | ||
workspaceSubmissionMetricBuilder(workspace.toWorkspaceName, workflowRecord.submissionId) | ||
)( | ||
status | ||
) | ||
) | ||
else None | ||
} | ||
} | ||
} | ||
} yield workflowsToAbort | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package org.broadinstitute.dsde.rawls.util | ||
|
||
import akka.http.scaladsl.model.StatusCodes | ||
import org.broadinstitute.dsde.rawls.RawlsExceptionWithErrorReport | ||
import org.broadinstitute.dsde.rawls.{RawlsException, RawlsExceptionWithErrorReport} | ||
import org.broadinstitute.dsde.rawls.model.Attributable.AttributeMap | ||
import org.broadinstitute.dsde.rawls.model.AttributeUpdateOperations.{ | ||
AddListMember, | ||
|
@@ -26,7 +26,6 @@ import org.broadinstitute.dsde.rawls.model.{ | |
ErrorReport, | ||
MethodConfiguration | ||
} | ||
import org.broadinstitute.dsde.rawls.workspace.{AttributeNotFoundException, AttributeUpdateOperationException} | ||
|
||
import scala.concurrent.Future | ||
|
||
|
@@ -172,10 +171,13 @@ trait AttributeSupport { | |
* | ||
* @param entity to update | ||
* @param operations sequence of operations | ||
* @throws org.broadinstitute.dsde.rawls.workspace.AttributeNotFoundException when removing from a list attribute that does not exist | ||
* @throws AttributeNotFoundException when removing from a list attribute that does not exist | ||
* @throws AttributeUpdateOperationException when adding or removing from an attribute that is not a list | ||
* @return the updated entity | ||
*/ | ||
def applyOperationsToEntity(entity: Entity, operations: Seq[AttributeUpdateOperation]): Entity = | ||
entity.copy(attributes = applyAttributeUpdateOperations(entity, operations)) | ||
} | ||
|
||
class AttributeUpdateOperationException(message: String) extends RawlsException(message) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place these are thrown, so it makes sense for them to be defined here. |
||
class AttributeNotFoundException(message: String) extends AttributeUpdateOperationException(message) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,33 @@ object TracingUtils { | |
def traceFuture[T](name: String)(f: RawlsTracingContext => Future[T])(implicit ec: ExecutionContext): Future[T] = | ||
traceFutureWithParent(name, RawlsTracingContext(otelContext = Option(Context.root())))(f) | ||
|
||
/** | ||
* Trace a sync operation with the RawlsRequestContext | ||
* | ||
* @param name The name that will be used in the trace | ||
* @param parentContext the RawlsRequestContext to use for tracing, if `parentContext.otelContext` is defined | ||
* @param f the operation to execute within the trace | ||
* @return the result of the operation `f` | ||
*/ | ||
def trace[T](name: String, parentContext: RawlsRequestContext)(f: RawlsRequestContext => T): T = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not having this was pushing a lot of different places to use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to be equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's using It's arguable that the better approach would be an overload or something, but we have similar divergence between others, such as between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, right. Reading is hard. I prefer this to overloading 👍 |
||
parentContext.otelContext match { | ||
case Some(otelContext) if instrumenter.shouldStart(otelContext, name) => | ||
val childContext = instrumenter.start(otelContext, name) | ||
val result = Try(f(parentContext.copy(otelContext = Option(childContext)))) | ||
instrumenter.end(childContext, name, name, result.failed.toOption.orNull) | ||
result.get | ||
case _ => | ||
f(parentContext) | ||
} | ||
|
||
/** | ||
* Trace a sync operation with the RawlsTracingContext | ||
* | ||
* @param name The name that will be used in the trace | ||
* @param parentContext the RawlsTracingContext to use for tracing, if `parentContext.otelContext` is defined | ||
* @param f the operation to execute within the trace | ||
* @return the result of the operation `f` | ||
*/ | ||
def traceNakedWithParent[T](name: String, parentContext: RawlsTracingContext)( | ||
f: RawlsTracingContext => T | ||
): T = | ||
|
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.
The changes in this file are just from moving an exception definition to the place where it's thrown.