-
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
[GAWB-2056] The status of the last run is showing green when there are errors in them #709
Changes from 5 commits
cbe29ff
21b62b0
fe4fcfa
3ee7afb
5144a52
7136d42
22d8f0b
ee31eb5
a5120c7
746feaa
f819423
2a7610e
7927a22
103a4da
bc1aebf
3553256
bb205b3
00df98b
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 |
---|---|---|
|
@@ -3,13 +3,14 @@ package org.broadinstitute.dsde.rawls.dataaccess.slick | |
import java.sql.Timestamp | ||
import java.util.{Date, UUID} | ||
|
||
import cats.instances.int._ | ||
import cats.instances.option._ | ||
import org.broadinstitute.dsde.rawls.RawlsException | ||
import org.broadinstitute.dsde.rawls.dataaccess.SlickWorkspaceContext | ||
import org.broadinstitute.dsde.rawls.model.Attributable.AttributeMap | ||
import org.broadinstitute.dsde.rawls.model.WorkspaceAccessLevels.WorkspaceAccessLevel | ||
import org.broadinstitute.dsde.rawls.model._ | ||
import org.joda.time.DateTime | ||
import org.broadinstitute.dsde.rawls.dataaccess.SlickWorkspaceContext | ||
import org.broadinstitute.dsde.rawls.model.Attributable.AttributeMap | ||
|
||
/** | ||
* Created by dvoet on 2/4/16. | ||
*/ | ||
|
@@ -499,36 +500,63 @@ trait WorkspaceComponent { | |
} | ||
|
||
/** | ||
* gets the submission stats (last workflow failed date, last workflow success date, running submission count) | ||
* gets the submission stats (last submission failed date, last submission success date, running submission count) | ||
* for each workspace | ||
* | ||
* @param workspaceIds the workspace ids to query for | ||
* @return WorkspaceSubmissionStats keyed by workspace id | ||
*/ | ||
def listSubmissionSummaryStats(workspaceIds: Seq[UUID]): ReadAction[Map[UUID, WorkspaceSubmissionStats]] = { | ||
// workflow date query: select workspaceId, workflow.status, max(workflow.statusLastChangedDate) ... group by workspaceId, workflow.status | ||
val workflowDatesQuery = for { | ||
|
||
// submission date query: | ||
// | ||
// select workspaceId, status, max(submissionDate) | ||
// from ( | ||
// select submission.workspaceId, workflow.status, submission.submissionDate, count(1) | ||
// from submission | ||
// join workflow on workflow.submissionId = submission.id | ||
// where submission.workspaceId in (:workspaceIds) | ||
// group by 1, 2, 3) v | ||
// where (status = 'Failure' or (status = 'Succeeded' and count = 1) | ||
// group by 1, 2 | ||
|
||
val workflowStatusQuery = for { | ||
submissions <- submissionQuery if submissions.workspaceId.inSetBind(workspaceIds) | ||
workflows <- workflowQuery if submissions.id === workflows.submissionId | ||
} yield (submissions.workspaceId, workflows.status, workflows.statusLastChangedDate) | ||
} yield (submissions.workspaceId, workflows.status, submissions.submissionDate) | ||
|
||
val workflowDatesGroupedQuery = workflowDatesQuery.groupBy { case (wsId, status, _) => (wsId, status) }. | ||
map { case ((wsId, wfStatus), records) => (wsId, wfStatus, records.map { case (_, _, lastChanged) => lastChanged }.max) } | ||
val groupedWorkflowStatusQuery = workflowStatusQuery.groupBy { case (wsId, status, submissionDate) => | ||
(wsId, status, submissionDate) | ||
}.map { case ((wsId, status, submissionDate), records) => | ||
(wsId, status, submissionDate, records.map(_._3).length) | ||
} | ||
|
||
// Note: a submission is successful if it contains _only_ successful workflows. | ||
// A submission is a failure if it contains _any_ failed workflows. | ||
val filteredWorkflowStatusQuery = groupedWorkflowStatusQuery.filter { case (_, status, _, count) => | ||
status === WorkflowStatuses.Failed.toString || (status === WorkflowStatuses.Succeeded.toString && count === 1) | ||
} | ||
|
||
val submissionDateQuery = filteredWorkflowStatusQuery.groupBy { case (workspaceId, status, submissionDate, _) => | ||
(workspaceId, status) | ||
}.map { case ((workspaceId, status), recs) => | ||
(workspaceId, status, recs.map(_._3).max) | ||
} | ||
|
||
// running submission query: select workspaceId, count(1) ... where submissions.status === Submitted group by workspaceId | ||
val runningSubmissionsQuery = (for { | ||
submissions <- submissionQuery if submissions.workspaceId.inSetBind(workspaceIds) && submissions.status.inSetBind(SubmissionStatuses.activeStatuses.map(_.toString)) | ||
} yield submissions).groupBy(_.workspaceId).map { case (wfId, submissions) => (wfId, submissions.length)} | ||
|
||
for { | ||
workflowDates <- workflowDatesGroupedQuery.result | ||
submissionDates <- submissionDateQuery.result | ||
runningSubmissions <- runningSubmissionsQuery.result | ||
} yield { | ||
val workflowDatesByWorkspaceByStatus: Map[UUID, Map[String, Option[Timestamp]]] = groupByWorkspaceIdThenStatus(workflowDates) | ||
val runningSubmissionCountByWorkspace: Map[UUID, Int] = groupByWorkspaceId(runningSubmissions) | ||
val submissionDatesByWorkspaceByStatus = groupTriplesK(submissionDates) | ||
val runningSubmissionCountByWorkspace = groupPairs(runningSubmissions) | ||
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. I think the rename from 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. Sure |
||
|
||
workspaceIds.map { wsId => | ||
val (lastFailedDate, lastSuccessDate) = workflowDatesByWorkspaceByStatus.get(wsId) match { | ||
val (lastFailedDate, lastSuccessDate) = submissionDatesByWorkspaceByStatus.get(wsId) match { | ||
case None => (None, None) | ||
case Some(datesByStatus) => | ||
(datesByStatus.getOrElse(WorkflowStatuses.Failed.toString, None), datesByStatus.getOrElse(WorkflowStatuses.Succeeded.toString, None)) | ||
|
@@ -731,14 +759,6 @@ trait WorkspaceComponent { | |
WorkspaceGroups(toGroupMap(realmAclRecs), toGroupMap(accessGroupRecs)) | ||
} | ||
} | ||
|
||
private def groupByWorkspaceId(runningSubmissions: Seq[(UUID, Int)]): Map[UUID, Int] = { | ||
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. These methods seemed useful so I cats-ified and generalized them and moved to |
||
runningSubmissions.groupBy{ case (wsId, count) => wsId }.mapValues { case Seq((_, count)) => count } | ||
} | ||
|
||
private def groupByWorkspaceIdThenStatus(workflowDates: Seq[(UUID, String, Option[Timestamp])]): Map[UUID, Map[String, Option[Timestamp]]] = { | ||
workflowDates.groupBy { case (wsId, _, _) => wsId }.mapValues(_.groupBy { case (_, status, _) => status }.mapValues { case Seq((_, _, timestamp)) => timestamp }) | ||
} | ||
} | ||
|
||
private case class WorkspaceGroups( | ||
|
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.
something tells me it'll be a while before this PR gets merged! (i have to wrap my head around this)
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.
Yeah sorry if this got a little fancy.. it's not really too bad. Check out:
https://github.com/typelevel/cats/blob/master/docs/src/main/tut/typeclasses/semigroupk.md
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.
A bunch of feedback here.
CollectionUtils
- seems like a good place for these to go.groupPairs
returns a map. You're then dereferencing the key defined byM.algebra[B]
? I don't know what that does and I'd have thought that this would give you a result type ofF[B]
.groupPairsK
example is equivalent totoMap
, which doesn't help me understand. Perhapswould be more helpful, assuming I've read the Cats documentation (and therefore know that in the absence of a quantified
F
(=Option
) means it'll just doorElse
).TLDR: I am 👍 on
groupPairs
andgroupTriples
, though they should go intoCollectionUtils
. I am 👎 on the K-versions; they rely on non-obvious behaviour (e.g.orElse
forOption
) that make them hard to understand.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.
Thanks for the feedback here. After reflecting a bit, maybe it would have been better to leave
groupByWorkspaceIdThenStatus
andgroupByWorkspaceId
as is -- I didn't really need to change them for this bug. I'm still learning how to scala in a large team, and readability is important.Digging in to your points:
-feature
compiler flag to see it. I guess it's complaining about theF[_]
type parameter. The scaladoc is kind of funny:4,5. So here's why I added the K version. In this case I wanted to group triples where the map value is an
Option[java.sql.Timestamp]
. Therefore I need a Monoid instance forjava.sql.Timestamp
, which doesn't exist. It wouldn't make much sense to define a Monoid for timestamps -- what would you do, add them together? However, in this case I'm guaranteed to have no key conflicts because of the SQL structure (group by
, etc). So I can just use a Monoid for Option which just takes one or the other, regardless of the value inside the "box". That's exactly whatMonoidK[Option]
does.Furthermore, I'm not sure how I would implement this in terms of
groupTriples
without usingMonoidK
. Perhaps this would be more clear?Then at least the
MonoidK
stuff is localized in a private method with some explanation specific to the use case.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.
I went ahead and pushed a commit with ^ those changes, please take a look.