-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
6b689a8
commit 459a6ef
Showing
35 changed files
with
405 additions
and
66 deletions.
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
39 changes: 39 additions & 0 deletions
39
backend/src/main/scala/cromwell/backend/standard/GroupMetricsActor.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,39 @@ | ||
package cromwell.backend.standard | ||
|
||
import akka.actor.{Actor, ActorLogging, Props} | ||
import akka.dispatch.MessageDispatcher | ||
import common.util.StringUtil.EnhancedToStringable | ||
import cromwell.backend.standard.GroupMetricsActor.RecordGroupQuotaExhaustion | ||
import cromwell.core.Dispatcher | ||
import cromwell.core.Dispatcher.EngineDispatcher | ||
import cromwell.database.sql.EngineSqlDatabase | ||
import cromwell.database.sql.SqlConverters.OffsetDateTimeToSystemTimestamp | ||
import cromwell.database.sql.tables.GroupMetricsEntry | ||
|
||
import java.time.OffsetDateTime | ||
|
||
class GroupMetricsActor(engineDbInterface: EngineSqlDatabase) extends Actor with ActorLogging { | ||
|
||
implicit val ec: MessageDispatcher = context.system.dispatchers.lookup(Dispatcher.EngineDispatcher) | ||
|
||
override def receive: Receive = { | ||
case RecordGroupQuotaExhaustion(group) => | ||
val groupMetricsEntry = GroupMetricsEntry(group, OffsetDateTime.now.toSystemTimestamp) | ||
engineDbInterface.recordGroupMetricsEntry(groupMetricsEntry) | ||
() | ||
case other => | ||
log.error( | ||
s"Programmer Error: Unexpected message ${other.toPrettyElidedString(1000)} received by ${this.self.path.name}." | ||
) | ||
} | ||
} | ||
|
||
object GroupMetricsActor { | ||
|
||
sealed trait GroupMetricsActorMessage | ||
|
||
case class RecordGroupQuotaExhaustion(group: String) extends GroupMetricsActorMessage | ||
|
||
def props(engineDbInterface: EngineSqlDatabase): Props = | ||
Props(new GroupMetricsActor(engineDbInterface)).withDispatcher(EngineDispatcher) | ||
} |
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
47 changes: 47 additions & 0 deletions
47
backend/src/test/scala/cromwell/backend/standard/GroupMetricsActorSpec.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,47 @@ | ||
package cromwell.backend.standard | ||
|
||
import akka.actor.ActorSystem | ||
import akka.testkit.{TestActorRef, TestProbe} | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
import cromwell.backend.standard.GroupMetricsActor.RecordGroupQuotaExhaustion | ||
import cromwell.database.slick.EngineSlickDatabase | ||
import cromwell.database.sql.tables.GroupMetricsEntry | ||
import cromwell.services.EngineServicesStore | ||
import cromwell.services.ServicesStore.EnhancedSqlDatabase | ||
import org.scalatest.concurrent.Eventually.eventually | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class GroupMetricsActorSpec extends AnyFlatSpec with Matchers { | ||
|
||
implicit val system: ActorSystem = ActorSystem("GroupMetricsActorSpec") | ||
|
||
val testHogGroup: String = "groot-hog-group" | ||
val DatabaseConfig: Config = ConfigFactory.load.getConfig("database") | ||
var recordMethodCallCount: Int = 0 | ||
|
||
def databaseInterface(): EngineSlickDatabase = | ||
new EngineSlickDatabase(DatabaseConfig) { | ||
override def recordGroupMetricsEntry(groupMetricsEntry: GroupMetricsEntry)(implicit | ||
ec: ExecutionContext | ||
): Future[Unit] = { | ||
recordMethodCallCount = recordMethodCallCount + 1 | ||
Future.successful(()) | ||
} | ||
}.initialized(EngineServicesStore.EngineLiquibaseSettings) | ||
|
||
behavior of "GroupMetricsActor" | ||
|
||
it should "receive new quota exhaustion message and call database function" in { | ||
val db = databaseInterface() | ||
val mockGroupMetricsActor = TestActorRef(GroupMetricsActor.props(db)) | ||
|
||
mockGroupMetricsActor.tell(RecordGroupQuotaExhaustion(testHogGroup), TestProbe().ref) | ||
|
||
eventually { | ||
recordMethodCallCount shouldBe 1 | ||
} | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
database/sql/src/main/scala/cromwell/database/slick/GroupMetricsSlickDatabase.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,32 @@ | ||
package cromwell.database.slick | ||
|
||
import cromwell.database.sql.GroupMetricsSqlDatabase | ||
import cromwell.database.sql.tables.GroupMetricsEntry | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
trait GroupMetricsSlickDatabase extends GroupMetricsSqlDatabase { | ||
this: EngineSlickDatabase => | ||
|
||
import dataAccess.driver.api._ | ||
|
||
override def recordGroupMetricsEntry( | ||
groupMetricsEntry: GroupMetricsEntry | ||
)(implicit ec: ExecutionContext): Future[Unit] = { | ||
val action = for { | ||
updateCount <- dataAccess | ||
.quotaExhaustionForGroupId(groupMetricsEntry.groupId) | ||
.update(groupMetricsEntry.quotaExhaustionDetected) | ||
_ <- updateCount match { | ||
case 0 => dataAccess.groupMetricsEntryIdsAutoInc += groupMetricsEntry | ||
case _ => assertUpdateCount("recordGroupMetricsEntry", updateCount, 1) | ||
} | ||
} yield () | ||
runTransaction(action) | ||
} | ||
|
||
override def countGroupMetricsEntries(groupId: String)(implicit ec: ExecutionContext): Future[Int] = { | ||
val action = dataAccess.countGroupMetricsEntriesForGroupId(groupId).result | ||
runTransaction(action) | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
database/sql/src/main/scala/cromwell/database/sql/GroupMetricsSqlDatabase.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,21 @@ | ||
package cromwell.database.sql | ||
|
||
import cromwell.database.sql.tables.GroupMetricsEntry | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
trait GroupMetricsSqlDatabase { | ||
|
||
this: SqlDatabase => | ||
|
||
/** | ||
* Insert or update Group Metrics entry to the table | ||
* | ||
*/ | ||
def recordGroupMetricsEntry(groupMetricsEntry: GroupMetricsEntry)(implicit ec: ExecutionContext): Future[Unit] | ||
|
||
/** | ||
* Returns number of entries associated with given group | ||
*/ | ||
def countGroupMetricsEntries(groupId: String)(implicit ec: ExecutionContext): Future[Int] | ||
} |
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
Oops, something went wrong.