Skip to content

Commit

Permalink
sql exception logging for more entity methods (#3025)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb authored Sep 10, 2024
1 parent ba12839 commit 54010c7
Showing 1 changed file with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class EntityService(protected val ctx: RawlsRequestContext,
entityManager <- entityManager.resolveProviderFuture(EntityRequestArguments(workspaceContext, ctx))
result <- entityManager.createEntity(entity)
} yield result
}
}.recover(sqlLoggingRecover(s"createEntity: $workspaceName"))

def getEntity(workspaceName: WorkspaceName,
entityType: String,
Expand All @@ -102,6 +102,7 @@ class EntityService(protected val ctx: RawlsRequestContext,
ErrorReport(StatusCodes.NotFound, s"${entityType} ${entityName} does not exist in $workspaceName")
)
}
.recover(sqlLoggingRecover(s"getEntity: $workspaceName $entityType/$entityName"))
.recover(bigQueryRecover)
}

Expand Down Expand Up @@ -138,7 +139,7 @@ class EntityService(protected val ctx: RawlsRequestContext,
}
}
}
}
}.recover(sqlLoggingRecover(s"updateEntity: $workspaceName $entityType/$entityName ${operations.size} operations"))

def deleteEntities(workspaceName: WorkspaceName,
entRefs: Seq[AttributeEntityReference],
Expand Down Expand Up @@ -203,9 +204,9 @@ class EntityService(protected val ctx: RawlsRequestContext,
entityType: String,
attributeNames: Set[AttributeName]
): Future[Unit] =
getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.write,
Some(WorkspaceAttributeSpecs(all = false))
(getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.write,
Some(WorkspaceAttributeSpecs(all = false))
) flatMap { workspaceContext =>
dataSource.inTransaction { dataAccess =>
dataAccess
Expand All @@ -218,12 +219,14 @@ class EntityService(protected val ctx: RawlsRequestContext,
case _ => DBIO.successful(())
}
}
}
}).recover(
sqlLoggingRecover(s"deleteEntityAttributes: $workspaceName $entityType ${attributeNames.size} attribute names")
)

def renameEntity(workspaceName: WorkspaceName, entityType: String, entityName: String, newName: String): Future[Int] =
getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.write,
Some(WorkspaceAttributeSpecs(all = false))
(getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.write,
Some(WorkspaceAttributeSpecs(all = false))
) flatMap { workspaceContext =>
dataSource.inTransaction { dataAccess =>
withEntity(workspaceContext, entityType, entityName, dataAccess) { entity =>
Expand All @@ -237,7 +240,9 @@ class EntityService(protected val ctx: RawlsRequestContext,
}
}
}
}
}).recover(
sqlLoggingRecover(s"renameEntity: $workspaceName $entityType $entityName")
)

def renameEntityType(workspaceName: WorkspaceName, oldName: String, renameInfo: EntityTypeRename): Future[Int] = {
import org.broadinstitute.dsde.rawls.dataaccess.slick.{DataAccess, ReadAction}
Expand Down Expand Up @@ -275,9 +280,9 @@ class EntityService(protected val ctx: RawlsRequestContext,
)
}

getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.write,
Some(WorkspaceAttributeSpecs(all = false))
(getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.write,
Some(WorkspaceAttributeSpecs(all = false))
) flatMap { workspaceContext =>
dataSource.inTransaction { dataAccess =>
for {
Expand All @@ -286,17 +291,19 @@ class EntityService(protected val ctx: RawlsRequestContext,
renameResult <- dataAccess.entityQuery.changeEntityTypeName(workspaceContext, oldName, renameInfo.newName)
} yield renameResult
}
}
}).recover(
sqlLoggingRecover(s"renameEntityType: $workspaceName $oldName")
)
}

def evaluateExpression(workspaceName: WorkspaceName,
entityType: String,
entityName: String,
expression: String
): Future[Seq[AttributeValue]] =
getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.read,
Some(WorkspaceAttributeSpecs(all = false))
(getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.read,
Some(WorkspaceAttributeSpecs(all = false))
) flatMap { workspaceContext =>
dataSource.inTransaction(
dataAccess =>
Expand Down Expand Up @@ -333,16 +340,18 @@ class EntityService(protected val ctx: RawlsRequestContext,
},
TransactionIsolation.ReadCommitted
)
}
}).recover(
sqlLoggingRecover(s"evaluateExpression: $workspaceName $entityType $entityName $expression")
)

def entityTypeMetadata(workspaceName: WorkspaceName,
dataReference: Option[DataReferenceName],
billingProject: Option[GoogleProjectId],
useCache: Boolean
): Future[Map[String, EntityTypeMetadata]] =
getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.read,
Some(WorkspaceAttributeSpecs(all = false))
(getV2WorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.read,
Some(WorkspaceAttributeSpecs(all = false))
) flatMap { workspaceContext =>
val entityRequestArguments = EntityRequestArguments(workspaceContext, ctx, dataReference, billingProject)

Expand All @@ -352,7 +361,9 @@ class EntityService(protected val ctx: RawlsRequestContext,
} yield metadata

metadataFuture.recover(bigQueryRecover)
}
}).recover(
sqlLoggingRecover(s"entityTypeMetadata: $workspaceName")
)

/*
* Queries the db for a stream of entity attributes.
Expand All @@ -375,13 +386,15 @@ class EntityService(protected val ctx: RawlsRequestContext,
}

def listEntities(workspaceName: WorkspaceName, entityType: String) =
getWorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.read,
Some(WorkspaceAttributeSpecs(all = false))
(getWorkspaceContextAndPermissions(workspaceName,
SamWorkspaceActions.read,
Some(WorkspaceAttributeSpecs(all = false))
) map { workspaceContext =>
val dbSource = listEntitiesDbSource(workspaceContext, entityType)
EntityStreamingUtils.gatherEntities(dataSource, dbSource)
}
}).recover(
sqlLoggingRecover(s"listEntities: $workspaceName $entityType")
)

def queryEntitiesSource(workspaceName: WorkspaceName,
dataReference: Option[DataReferenceName],
Expand Down Expand Up @@ -411,7 +424,7 @@ class EntityService(protected val ctx: RawlsRequestContext,
}

def copyEntities(entityCopyDef: EntityCopyDefinition, linkExistingEntities: Boolean): Future[EntityCopyResponse] =
for {
(for {
destWsCtx <- getV2WorkspaceContextAndPermissions(entityCopyDef.destinationWorkspace,
SamWorkspaceActions.write,
Some(WorkspaceAttributeSpecs(all = false))
Expand All @@ -434,7 +447,10 @@ class EntityService(protected val ctx: RawlsRequestContext,
ctx
)
.recover(bigQueryRecover)
} yield entityCopyResponse
} yield entityCopyResponse)
.recover(
sqlLoggingRecover(s"copyEntities: $entityCopyDef $linkExistingEntities")
)

def batchUpdateEntitiesInternal(workspaceName: WorkspaceName,
entityUpdates: Seq[EntityUpdateDefinition],
Expand Down Expand Up @@ -464,13 +480,19 @@ class EntityService(protected val ctx: RawlsRequestContext,
billingProject: Option[GoogleProjectId]
): Future[Traversable[Entity]] =
batchUpdateEntitiesInternal(workspaceName, entityUpdates, upsert = false, dataReference, billingProject)
.recover(
sqlLoggingRecover(s"batchUpdateEntities: $workspaceName ${entityUpdates.size} updates")
)

def batchUpsertEntities(workspaceName: WorkspaceName,
entityUpdates: Seq[EntityUpdateDefinition],
dataReference: Option[DataReferenceName],
billingProject: Option[GoogleProjectId]
): Future[Traversable[Entity]] =
batchUpdateEntitiesInternal(workspaceName, entityUpdates, upsert = true, dataReference, billingProject)
.recover(
sqlLoggingRecover(s"batchUpsertEntities: $workspaceName ${entityUpdates.size} upserts")
)

def renameAttribute(workspaceName: WorkspaceName,
entityType: String,
Expand Down Expand Up @@ -530,7 +552,9 @@ class EntityService(protected val ctx: RawlsRequestContext,
} yield rowsUpdated
}
}
}
}.recover(
sqlLoggingRecover(s"renameAttribute: $workspaceName $oldAttributeName $attributeRenameRequest")
)

private def sqlLoggingRecover[U](logHint: String): PartialFunction[Throwable, U] = {
case sqlException: SQLException =>
Expand Down

0 comments on commit 54010c7

Please sign in to comment.