Skip to content

Commit

Permalink
[KYUUBI #1780] Log error message on REST endpoints
Browse files Browse the repository at this point in the history
### _Why are the changes needed?_
closes #1780

Add error log in Rest be

### _How was this patch tested?_
- [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible

- [ ] Add screenshots for manual tests if appropriate

- [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request

Closes #1781 from simon824/printerror.

Closes #1780

5dfaafa [simon] style
17a2a3b [simon] logging
2abc9c8 [simon] print error log

Authored-by: simon <zhangshiming@cvte.com>
Signed-off-by: Cheng Pan <chengpan@apache.org>
  • Loading branch information
simon824 authored and pan3793 committed Jan 19, 2022
1 parent a4de0e6 commit dd4c2fa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 32 deletions.
Expand Up @@ -29,14 +29,15 @@ import io.swagger.v3.oas.annotations.tags.Tag
import org.apache.hive.service.rpc.thrift._

import org.apache.kyuubi.KyuubiSQLException
import org.apache.kyuubi.Logging
import org.apache.kyuubi.events.KyuubiOperationEvent
import org.apache.kyuubi.operation.{FetchOrientation, KyuubiOperation}
import org.apache.kyuubi.operation.OperationHandle.parseOperationHandle
import org.apache.kyuubi.server.api.ApiRequestContext

@Tag(name = "Operation")
@Produces(Array(MediaType.APPLICATION_JSON))
private[v1] class OperationsResource extends ApiRequestContext {
private[v1] class OperationsResource extends ApiRequestContext with Logging {

@ApiResponse(
responseCode = "200",
Expand All @@ -53,8 +54,10 @@ private[v1] class OperationsResource extends ApiRequestContext {
val operation = fe.be.sessionManager.operationManager.getOperation(opHandle)
KyuubiOperationEvent(operation.asInstanceOf[KyuubiOperation])
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error getting an operation event")
case NonFatal(e) =>
val errorMsg = "Error getting an operation event"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -78,9 +81,10 @@ private[v1] class OperationsResource extends ApiRequestContext {
}
Response.ok().build()
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error applying ${request.action} " +
s"for operation handle $operationHandleStr")
case NonFatal(e) =>
val errorMsg = s"Error applying ${request.action} for operation handle $operationHandleStr"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand Down Expand Up @@ -116,9 +120,10 @@ private[v1] class OperationsResource extends ApiRequestContext {
c.getComment)
}))
} catch {
case NonFatal(_) =>
throw new NotFoundException(
s"Error getting result set metadata for operation handle $operationHandleStr")
case NonFatal(e) =>
val errorMsg = s"Error getting result set metadata for operation handle $operationHandleStr"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -141,9 +146,10 @@ private[v1] class OperationsResource extends ApiRequestContext {
val logRowSet = rowSet.getColumns.get(0).getStringVal.getValues.asScala
OperationLog(logRowSet, logRowSet.size)
} catch {
case NonFatal(_) =>
throw new NotFoundException(
s"Error getting operation log for operation handle $operationHandleStr")
case NonFatal(e) =>
val errorMsg = s"Error getting operation log for operation handle $operationHandleStr"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand Down Expand Up @@ -188,9 +194,10 @@ private[v1] class OperationsResource extends ApiRequestContext {
})
ResultRowSet(rows, rows.size)
} catch {
case NonFatal(_) =>
throw new NotFoundException(
s"Error getting result row set for operation handle $operationHandleStr")
case NonFatal(e) =>
val errorMsg = s"Error getting result row set for operation handle $operationHandleStr"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}
}
Expand Up @@ -28,7 +28,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag
import org.apache.hive.service.rpc.thrift.{TGetInfoType, TProtocolVersion}

import org.apache.kyuubi.Utils.error
import org.apache.kyuubi.Logging
import org.apache.kyuubi.events.KyuubiEvent
import org.apache.kyuubi.operation.OperationHandle
import org.apache.kyuubi.server.api.ApiRequestContext
Expand All @@ -37,7 +37,7 @@ import org.apache.kyuubi.session.SessionHandle.parseSessionHandle

@Tag(name = "Session")
@Produces(Array(MediaType.APPLICATION_JSON))
private[v1] class SessionsResource extends ApiRequestContext {
private[v1] class SessionsResource extends ApiRequestContext with Logging {

@ApiResponse(
responseCode = "200",
Expand Down Expand Up @@ -162,8 +162,10 @@ private[v1] class SessionsResource extends ApiRequestContext {
request.runAsync,
request.queryTimeout)
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error executing statement")
case NonFatal(e) =>
val errorMsg = "Error executing statement"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -178,8 +180,10 @@ private[v1] class SessionsResource extends ApiRequestContext {
try {
fe.be.getTypeInfo(parseSessionHandle(sessionHandleStr))
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error getting type information")
case NonFatal(e) =>
val errorMsg = "Error getting type information"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -194,8 +198,10 @@ private[v1] class SessionsResource extends ApiRequestContext {
try {
fe.be.getCatalogs(parseSessionHandle(sessionHandleStr))
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error getting catalogs")
case NonFatal(e) =>
val errorMsg = "Error getting catalogs"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -218,7 +224,9 @@ private[v1] class SessionsResource extends ApiRequestContext {
operationHandle
} catch {
case NonFatal(e) =>
throw new NotFoundException(s"Error getting schemas", e)
val errorMsg = "Error getting schemas"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -240,8 +248,10 @@ private[v1] class SessionsResource extends ApiRequestContext {
request.tableName,
request.tableTypes)
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error getting tables")
case NonFatal(e) =>
val errorMsg = "Error getting tables"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -256,8 +266,10 @@ private[v1] class SessionsResource extends ApiRequestContext {
try {
fe.be.getTableTypes(parseSessionHandle(sessionHandleStr))
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error getting table types")
case NonFatal(e) =>
val errorMsg = "Error getting table types"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -279,8 +291,10 @@ private[v1] class SessionsResource extends ApiRequestContext {
request.tableName,
request.columnName)
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error getting columns")
case NonFatal(e) =>
val errorMsg = "Error getting columns"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}

Expand All @@ -301,8 +315,10 @@ private[v1] class SessionsResource extends ApiRequestContext {
request.schemaName,
request.functionName)
} catch {
case NonFatal(_) =>
throw new NotFoundException(s"Error getting functions")
case NonFatal(e) =>
val errorMsg = "Error getting functions"
error(errorMsg, e)
throw new NotFoundException(errorMsg)
}
}
}

0 comments on commit dd4c2fa

Please sign in to comment.