Class QueryLifecycle
- Initialization (
initialize(Query)) - Authorization (
authorize(HttpServletRequest) - Execution (
execute() - Logging (
emitLogsAndMetrics(Throwable, String, long)
runSimple(Query, AuthenticationResult, AuthorizationResult).
This object is not thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionQueryLifecycle(QueryRunnerFactoryConglomerate conglomerate, QuerySegmentWalker texasRanger, GenericQueryMetricsFactory queryMetricsFactory, ServiceEmitter emitter, RequestLogger requestLogger, AuthorizerMapper authorizerMapper, DefaultQueryConfig defaultQueryConfig, AuthConfig authConfig, PolicyEnforcer policyEnforcer, long startMs, long startNs) -
Method Summary
Modifier and TypeMethodDescriptionauthorize(javax.servlet.http.HttpServletRequest req) ReturnsAuthorizationResultbased onDRUID_AUTHENTICATION_RESULTin the given request, base query would be transformed with restrictions on the AuthorizationResult.authorize(AuthenticationResult authenticationResult) ReturnsAuthorizationResultbased on the givenAuthenticationResult, base query would be transformed with restrictions on the AuthorizationResult.voidemitLogsAndMetrics(Throwable e, String remoteAddress, long bytesWritten) Emits logs and metrics for this query.<T> QueryResponse<T>execute()Executes the query.Query<?>getQuery()voidinitialize(Query<?> baseQuery) Initializes this object to execute a specific query.com.fasterxml.jackson.databind.ObjectMappernewOutputWriter(ResourceIOReaderWriterFactory.ResourceIOReaderWriter ioReaderWriter) <T> QueryResponse<T>runSimple(Query<T> query, AuthenticationResult authenticationResult, AuthorizationResult authorizationResult) For callers who have already authorized their query, and where simplicity is desired over flexibility.static booleanshouldLogStackTrace(Throwable e, QueryContext queryContext) Returns whether stack traces should be logged for a particular exception thrown with a particular query context.threadName(String currThreadName)
-
Constructor Details
-
QueryLifecycle
public QueryLifecycle(QueryRunnerFactoryConglomerate conglomerate, QuerySegmentWalker texasRanger, GenericQueryMetricsFactory queryMetricsFactory, ServiceEmitter emitter, RequestLogger requestLogger, AuthorizerMapper authorizerMapper, DefaultQueryConfig defaultQueryConfig, AuthConfig authConfig, PolicyEnforcer policyEnforcer, long startMs, long startNs)
-
-
Method Details
-
runSimple
public <T> QueryResponse<T> runSimple(Query<T> query, AuthenticationResult authenticationResult, AuthorizationResult authorizationResult) For callers who have already authorized their query, and where simplicity is desired over flexibility. This method does it all in one call. Logs and metrics are emitted when the Sequence is either fully iterated or throws an exception.The
statetransitions from NEW, to INITIALIZED, to AUTHORIZING, to AUTHORIZED, to EXECUTING, then DONE.- Parameters:
query- the queryauthenticationResult- authentication result indicating identity of the requesterauthorizationResult- authorization result of requester- Returns:
- results
- Throws:
DruidException- if the given authorizationResult deny access, which indicates a bug
-
initialize
Initializes this object to execute a specific query. Does not actually execute the query.The
statetransitions from NEW, to INITIALIZED.- Parameters:
baseQuery- the query- Throws:
DruidException- if the current state is not NEW, which indicates a bug
-
authorize
ReturnsAuthorizationResultbased onDRUID_AUTHENTICATION_RESULTin the given request, base query would be transformed with restrictions on the AuthorizationResult.The
statetransitions from INITIALIZED, to AUTHORIZING, then to AUTHORIZED or UNAUTHORIZED.Note this won't throw exception if authorization deny access or impose policy restrictions. It is the caller's responsibility to throw exception on denial and impose policy restriction.
- Parameters:
req- HTTP request to be authorized. The auth-related fields in the HTTP request will be set.- Returns:
- authorization result denoting whether the query is authorized or not, along with policy restrictions
- Throws:
IllegalStateException- if the request was not authenticatedDruidException- if the current state is not INITIALIZED, which indicates a bug
-
authorize
ReturnsAuthorizationResultbased on the givenAuthenticationResult, base query would be transformed with restrictions on the AuthorizationResult.The
statetransitions from INITIALIZED, to AUTHORIZING, then to AUTHORIZED or UNAUTHORIZED.Note this won't throw exception if authorization deny access or impose policy restrictions. It is the caller's responsibility to throw exception on denial and impose policy restriction.
This method is to be used by the grpc-query-extension.
- Parameters:
authenticationResult- authentication result indicating identity of the requester- Returns:
- authorization result denoting whether the query is authorized or not, along with policy restrictions.
- Throws:
DruidException- if the current state is not INITIALIZED, which indicates a bug
-
execute
Executes the query.Note that query logs and metrics will not be emitted automatically when the Sequence is fully iterated withou. It is the caller's responsibility to call
emitLogsAndMetrics(Throwable, String, long)to emit logs and metrics.The
statetransitions from AUTHORIZED, to EXECUTING.- Returns:
- result sequence and response context
- Throws:
DruidException- if the current state is not AUTHORIZED, which indicates a bug
-
emitLogsAndMetrics
public void emitLogsAndMetrics(@Nullable Throwable e, @Nullable String remoteAddress, long bytesWritten) Emits logs and metrics for this query.The
statetransitions to DONE. The initial state can be anything, but it likely shouldn't be set to DONE.If
baseQueryis null, likely becauseinitialize(Query)was never call, do nothing.- Parameters:
e- exception that occurred while processing this queryremoteAddress- remote address, for logging; or null if unknownbytesWritten- number of bytes written; will become a query/bytes metric if >= 0
-
getQuery
-
getQueryId
-
threadName
-
newOutputWriter
public com.fasterxml.jackson.databind.ObjectMapper newOutputWriter(ResourceIOReaderWriterFactory.ResourceIOReaderWriter ioReaderWriter) -
getToolChest
-
shouldLogStackTrace
Returns whether stack traces should be logged for a particular exception thrown with a particular query context. Stack traces are logged ifQueryContext.isDebug(), or if theDruidException.PersonaisDruidException.Persona.DEVELOPERorDruidException.Persona.OPERATOR. The idea is that other personas are meant to interact with the API, not with code or logs, so logging stack traces by default adds clutter that is not very helpful.- Parameters:
e- exceptionqueryContext- query context
-