Java Code Examples for org.apache.kylin.rest.response.SQLResponse#getIsException()
The following examples show how to use
org.apache.kylin.rest.response.SQLResponse#getIsException() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryController.java From Kylin with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/query/prestate", method = RequestMethod.POST, produces = "application/json") @ResponseBody @Timed(name = "query") public SQLResponse prepareQuery(@RequestBody PrepareSqlRequest sqlRequest) { long startTimestamp = System.currentTimeMillis(); SQLResponse response = doQuery(sqlRequest); response.setDuration(System.currentTimeMillis() - startTimestamp); queryService.logQuery(sqlRequest, response, new Date(startTimestamp), new Date(System.currentTimeMillis())); if (response.getIsException()) { String errorMsg = response.getExceptionMessage(); throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly(errorMsg)); } return response; }
Example 2
Source File: QueryMetrics2Facade.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
private static void update(String name, SQLResponse sqlResponse) { try { incrQueryCount(name, sqlResponse); incrCacheHitCount(name, sqlResponse); if (!sqlResponse.getIsException()) { metrics.updateTimer(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_DURATION), sqlResponse.getDuration(), TimeUnit.MILLISECONDS); metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_RESULT_ROWCOUNT), sqlResponse.getResults().size()); metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_SCAN_ROWCOUNT), sqlResponse.getTotalScanCount()); } } catch (Exception e) { logger.error(e.getMessage()); } }
Example 3
Source File: DashboardController.java From kylin with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/metric/query", method = RequestMethod.GET) @ResponseBody public MetricsResponse getQueryMetrics(@RequestParam(value = "projectName", required = false) String projectName, @RequestParam(value = "cubeName", required = false) String cubeName, @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) { checkAuthorization(projectName); MetricsResponse queryMetrics = new MetricsResponse(); PrepareSqlRequest sqlRequest = dashboardService.getQueryMetricsSQLRequest(startTime, endTime, projectName, cubeName); SQLResponse sqlResponse = queryService.doQueryWithCache(sqlRequest); if (!sqlResponse.getIsException()) { queryMetrics.increase("queryCount", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(0))); queryMetrics.increase("avgQueryLatency", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(1))); queryMetrics.increase("maxQueryLatency", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(2))); queryMetrics.increase("minQueryLatency", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(3))); } return queryMetrics; }
Example 4
Source File: DashboardController.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/metric/query", method = RequestMethod.GET) @ResponseBody public MetricsResponse getQueryMetrics(@RequestParam(value = "projectName", required = false) String projectName, @RequestParam(value = "cubeName", required = false) String cubeName, @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) { checkAuthorization(projectName); MetricsResponse queryMetrics = new MetricsResponse(); PrepareSqlRequest sqlRequest = dashboardService.getQueryMetricsSQLRequest(startTime, endTime, projectName, cubeName); SQLResponse sqlResponse = queryService.doQueryWithCache(sqlRequest); if (!sqlResponse.getIsException()) { queryMetrics.increase("queryCount", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(0))); queryMetrics.increase("avgQueryLatency", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(1))); queryMetrics.increase("maxQueryLatency", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(2))); queryMetrics.increase("minQueryLatency", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(3))); } return queryMetrics; }
Example 5
Source File: DashboardController.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
@RequestMapping(value = "/metric/job", method = RequestMethod.GET) @ResponseBody public MetricsResponse getJobMetrics(@RequestParam(value = "projectName", required = false) String projectName, @RequestParam(value = "cubeName", required = false) String cubeName, @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) { checkAuthorization(projectName); MetricsResponse jobMetrics = new MetricsResponse(); PrepareSqlRequest sqlRequest = dashboardService.getJobMetricsSQLRequest(startTime, endTime, projectName, cubeName); SQLResponse sqlResponse = queryService.doQueryWithCache(sqlRequest); if (!sqlResponse.getIsException()) { jobMetrics.increase("jobCount", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(0))); jobMetrics.increase("avgJobBuildTime", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(1))); jobMetrics.increase("maxJobBuildTime", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(2))); jobMetrics.increase("minJobBuildTime", dashboardService.getMetricValue(sqlResponse.getResults().get(0).get(3))); } return jobMetrics; }
Example 6
Source File: QueryMetrics2Facade.java From kylin with Apache License 2.0 | 6 votes |
private static void update(String name, SQLResponse sqlResponse) { try { incrQueryCount(name, sqlResponse); incrCacheHitCount(name, sqlResponse); if (!sqlResponse.getIsException()) { metrics.updateTimer(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_DURATION), sqlResponse.getDuration(), TimeUnit.MILLISECONDS); metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_RESULT_ROWCOUNT), sqlResponse.getResults().size()); metrics.updateHistogram(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_SCAN_ROWCOUNT), sqlResponse.getTotalScanCount()); } } catch (Exception e) { logger.error(e.getMessage()); } }
Example 7
Source File: QueryMetricsFacade.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private static void update(QueryMetrics queryMetrics, SQLResponse sqlResponse) { try { incrQueryCount(queryMetrics, sqlResponse); incrCacheHitCount(queryMetrics, sqlResponse); if (!sqlResponse.getIsException()) { queryMetrics.addQueryLatency(sqlResponse.getDuration()); queryMetrics.addScanRowCount(sqlResponse.getTotalScanCount()); queryMetrics.addResultRowCount(sqlResponse.getResults().size()); } } catch (Exception e) { logger.error(e.getMessage()); } }
Example 8
Source File: DashboardService.java From kylin with Apache License 2.0 | 5 votes |
public MetricsResponse transformChartData(SQLResponse sqlResponse) { if (!sqlResponse.getIsException()) { MetricsResponse metrics = new MetricsResponse(); List<List<String>> results = sqlResponse.getResults(); for (List<String> result : results) { String dimension = result.get(0); if (dimension != null && !dimension.isEmpty()) { String metric = result.get(1); metrics.increase(dimension, getMetricValue(metric)); } } return metrics; } return null; }
Example 9
Source File: QueryMetrics2Facade.java From kylin with Apache License 2.0 | 5 votes |
private static void incrQueryCount(String name, SQLResponse sqlResponse) { if (!sqlResponse.isHitExceptionCache() && !sqlResponse.getIsException()) { metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_SUCCESS_COUNT)); } else { metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_FAIL_COUNT)); } metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_COUNT)); }
Example 10
Source File: QueryMetricsFacade.java From kylin with Apache License 2.0 | 5 votes |
private static void update(QueryMetrics queryMetrics, SQLResponse sqlResponse) { try { incrQueryCount(queryMetrics, sqlResponse); incrCacheHitCount(queryMetrics, sqlResponse); if (!sqlResponse.getIsException()) { queryMetrics.addQueryLatency(sqlResponse.getDuration()); queryMetrics.addScanRowCount(sqlResponse.getTotalScanCount()); queryMetrics.addResultRowCount(sqlResponse.getResults().size()); } } catch (Exception e) { logger.error(e.getMessage()); } }
Example 11
Source File: DashboardService.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public MetricsResponse transformChartData(SQLResponse sqlResponse) { if (!sqlResponse.getIsException()) { MetricsResponse metrics = new MetricsResponse(); List<List<String>> results = sqlResponse.getResults(); for (List<String> result : results) { String dimension = result.get(0); if (dimension != null && !dimension.isEmpty()) { String metric = result.get(1); metrics.increase(dimension, getMetricValue(metric)); } } return metrics; } return null; }
Example 12
Source File: QueryMetrics2Facade.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private static void incrQueryCount(String name, SQLResponse sqlResponse) { if (!sqlResponse.isHitExceptionCache() && !sqlResponse.getIsException()) { metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_SUCCESS_COUNT)); } else { metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_FAIL_COUNT)); } metrics.incrementCounter(MetricsNameBuilder.buildMetricName(name, MetricsConstant.QUERY_COUNT)); }
Example 13
Source File: QueryMetricsFacade.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private static void incrQueryCount(QueryMetrics queryMetrics, SQLResponse sqlResponse) { if (!sqlResponse.isHitExceptionCache() && !sqlResponse.getIsException()) { queryMetrics.incrQuerySuccessCount(); } else { queryMetrics.incrQueryFailCount(); } queryMetrics.incrQueryCount(); }
Example 14
Source File: QueryMetricsFacade.java From kylin with Apache License 2.0 | 4 votes |
/** * report query related metrics */ private static void updateMetricsToReservoir(SQLRequest sqlRequest, SQLResponse sqlResponse) { if (!KylinConfig.getInstanceFromEnv().isKylinMetricsReporterForQueryEnabled()) { return; } String user = SecurityContextHolder.getContext().getAuthentication().getName(); if (user == null) { user = "unknown"; } for (QueryContext.RPCStatistics entry : QueryContextFacade.current().getRpcStatisticsList()) { RecordEvent rpcMetricsEvent = new TimedRecordEvent( KylinConfig.getInstanceFromEnv().getKylinMetricsSubjectQueryRpcCall()); setRPCWrapper(rpcMetricsEvent, // norm(sqlRequest.getProject()), entry.getRealizationName(), entry.getRpcServer(), entry.getException()); setRPCStats(rpcMetricsEvent, // entry.getCallTimeMs(), entry.getSkippedRows(), entry.getScannedRows(), entry.getReturnedRows(), entry.getAggregatedRows()); //For update rpc level related metrics MetricsManager.getInstance().update(rpcMetricsEvent); } for (QueryContext.CubeSegmentStatisticsResult contextEntry : sqlResponse.getCubeSegmentStatisticsList()) { RecordEvent queryMetricsEvent = new TimedRecordEvent( KylinConfig.getInstanceFromEnv().getKylinMetricsSubjectQuery()); setQueryWrapper(queryMetricsEvent, // user, sqlRequest.getSql(), sqlResponse.isStorageCacheUsed() ? "CACHE" : contextEntry.getQueryType(), norm(sqlRequest.getProject()), contextEntry.getRealization(), contextEntry.getRealizationType(), sqlResponse.getThrowable()); long totalStorageReturnCount = 0L; if (contextEntry.getQueryType().equalsIgnoreCase(OLAPQuery.EnumeratorTypeEnum.OLAP.name())) { for (Map<String, QueryContext.CubeSegmentStatistics> cubeEntry : contextEntry.getCubeSegmentStatisticsMap() .values()) { for (QueryContext.CubeSegmentStatistics segmentEntry : cubeEntry.values()) { RecordEvent cubeSegmentMetricsEvent = new TimedRecordEvent( KylinConfig.getInstanceFromEnv().getKylinMetricsSubjectQueryCube()); setCubeWrapper(cubeSegmentMetricsEvent, // norm(sqlRequest.getProject()), segmentEntry.getCubeName(), segmentEntry.getSegmentName(), segmentEntry.getSourceCuboidId(), segmentEntry.getTargetCuboidId(), segmentEntry.getFilterMask()); setCubeStats(cubeSegmentMetricsEvent, // segmentEntry.getCallCount(), segmentEntry.getCallTimeSum(), segmentEntry.getCallTimeMax(), segmentEntry.getStorageSkippedRows(), segmentEntry.getStorageScannedRows(), segmentEntry.getStorageReturnedRows(), segmentEntry.getStorageAggregatedRows(), segmentEntry.isIfSuccess(), 1.0 / cubeEntry.size()); totalStorageReturnCount += segmentEntry.getStorageReturnedRows(); //For update cube segment level related query metrics MetricsManager.getInstance().update(cubeSegmentMetricsEvent); } } } else { if (!sqlResponse.getIsException()) { totalStorageReturnCount = sqlResponse.getResults().size(); } } setQueryStats(queryMetricsEvent, // sqlResponse.getDuration(), sqlResponse.getResults() == null ? 0 : sqlResponse.getResults().size(), totalStorageReturnCount); //For update query level metrics MetricsManager.getInstance().update(queryMetricsEvent); } }
Example 15
Source File: QueryController.java From Kylin with Apache License 2.0 | 4 votes |
private void checkQueryAuth(SQLResponse sqlResponse) throws AccessDeniedException { if (!sqlResponse.getIsException() && KylinConfig.getInstanceFromEnv().isQuerySecureEnabled()) { CubeInstance cubeInstance = this.queryService.getCubeManager().getCube(sqlResponse.getCube()); queryService.checkAuthorization(cubeInstance); } }
Example 16
Source File: QueryService.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
public void logQuery(final String queryId, final SQLRequest request, final SQLResponse response) { final String user = aclEvaluate.getCurrentUserName(); final List<String> realizationNames = new LinkedList<>(); final Set<Long> cuboidIds = new HashSet<Long>(); float duration = response.getDuration() / (float) 1000; boolean storageCacheUsed = response.isStorageCacheUsed(); boolean isPushDown = response.isPushDown(); if (!response.isHitExceptionCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { //Some queries do not involve cuboid, e.g. lookup table query cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { realizationNames.add(ctx.realization.getCanonicalName()); } } } if (realizationNames.isEmpty()) { if (!Strings.isNullOrEmpty(response.getCube())) { realizationNames.addAll(Lists.newArrayList(StringUtil.splitByComma(response.getCube()))); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("Query Id: ").append(queryId).append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(response.getTotalScanCount()).append(newLine); stringBuilder.append("Total scan bytes: ").append(response.getTotalScanBytes()).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Exception Cache: ").append(response.isHitExceptionCache()).append(newLine); stringBuilder.append("Storage cache used: ").append(storageCacheUsed).append(newLine); stringBuilder.append("Is Query Push-Down: ").append(isPushDown).append(newLine); stringBuilder.append("Is Prepare: ").append(BackdoorToggles.getPrepareOnly()).append(newLine); stringBuilder.append("Trace URL: ").append(response.getTraceUrl()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); }
Example 17
Source File: QueryService.java From Kylin with Apache License 2.0 | 4 votes |
public void logQuery(final SQLRequest request, final SQLResponse response, final Date startTime, final Date endTime) { final String user = SecurityContextHolder.getContext().getAuthentication().getName(); final Set<String> realizationNames = new HashSet<String>(); final Set<Long> cuboidIds = new HashSet<Long>(); long totalScanCount = 0; float duration = (endTime.getTime() - startTime.getTime()) / (float) 1000; if (!response.isHitCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { //Some queries do not involve cuboid, e.g. lookup table query cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { String realizationName = ctx.realization.getName(); realizationNames.add(realizationName); } totalScanCount += ctx.storageContext.getTotalScanCount(); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } QueryMetrics.getInstance().increase("duration", duration); QueryMetrics.getInstance().increase("totalScanCount", (float) totalScanCount); QueryMetrics.getInstance().increase("count", (float) 1); String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(totalScanCount).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Cache: ").append(response.isHitCache()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); }
Example 18
Source File: QueryService.java From kylin with Apache License 2.0 | 4 votes |
public void logQuery(final String queryId, final SQLRequest request, final SQLResponse response) { final String user = aclEvaluate.getCurrentUserName(); final List<String> realizationNames = new LinkedList<>(); final Set<Long> cuboidIds = new HashSet<Long>(); float duration = response.getDuration() / (float) 1000; boolean storageCacheUsed = response.isStorageCacheUsed(); boolean isPushDown = response.isPushDown(); if (!response.isHitExceptionCache() && null != OLAPContext.getThreadLocalContexts()) { for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) { Cuboid cuboid = ctx.storageContext.getCuboid(); if (cuboid != null) { //Some queries do not involve cuboid, e.g. lookup table query cuboidIds.add(cuboid.getId()); } if (ctx.realization != null) { realizationNames.add(ctx.realization.getCanonicalName()); } } } // if Realization Names is empty, get value from SQLResponse. if (realizationNames.isEmpty()) { if (!Strings.isNullOrEmpty(response.getCube())) { realizationNames.addAll(Lists.newArrayList(StringUtil.splitByComma(response.getCube()))); } } // if Cuboid Ids is empty, get value from SQLResponse. if (cuboidIds.isEmpty()) { List<QueryContext.CubeSegmentStatisticsResult> cubeSegmentStatisticsList = response.getCubeSegmentStatisticsList(); if (CollectionUtils.isNotEmpty(cubeSegmentStatisticsList)) { cubeSegmentStatisticsList.forEach(cubeSegmentStatResult -> { if (MapUtils.isNotEmpty(cubeSegmentStatResult.getCubeSegmentStatisticsMap())) { cubeSegmentStatResult.getCubeSegmentStatisticsMap().values().forEach(cubeSegmentStatMap -> { cubeSegmentStatMap.values().forEach(cubeSegmentStat -> { cuboidIds.add(cubeSegmentStat.getTargetCuboidId()); }); }); } }); } } int resultRowCount = 0; if (!response.getIsException() && response.getResults() != null) { resultRowCount = response.getResults().size(); } String newLine = System.getProperty("line.separator"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); stringBuilder.append("Query Id: ").append(queryId).append(newLine); stringBuilder.append("SQL: ").append(request.getSql()).append(newLine); stringBuilder.append("User: ").append(user).append(newLine); stringBuilder.append("Success: ").append((null == response.getExceptionMessage())).append(newLine); stringBuilder.append("Duration: ").append(duration).append(newLine); stringBuilder.append("Project: ").append(request.getProject()).append(newLine); stringBuilder.append("Realization Names: ").append(realizationNames).append(newLine); stringBuilder.append("Cuboid Ids: ").append(cuboidIds).append(newLine); stringBuilder.append("Total scan count: ").append(response.getTotalScanCount()).append(newLine); stringBuilder.append("Total scan bytes: ").append(response.getTotalScanBytes()).append(newLine); stringBuilder.append("Result row count: ").append(resultRowCount).append(newLine); stringBuilder.append("Accept Partial: ").append(request.isAcceptPartial()).append(newLine); stringBuilder.append("Is Partial Result: ").append(response.isPartial()).append(newLine); stringBuilder.append("Hit Exception Cache: ").append(response.isHitExceptionCache()).append(newLine); stringBuilder.append("Storage cache used: ").append(storageCacheUsed).append(newLine); stringBuilder.append("Is Query Push-Down: ").append(isPushDown).append(newLine); stringBuilder.append("Is Prepare: ").append(BackdoorToggles.getPrepareOnly()).append(newLine); stringBuilder.append("Trace URL: ").append(response.getTraceUrl()).append(newLine); stringBuilder.append("Message: ").append(response.getExceptionMessage()).append(newLine); stringBuilder.append("==========================[QUERY]===============================").append(newLine); logger.info(stringBuilder.toString()); }
Example 19
Source File: QueryMetricsFacade.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
/** * report query related metrics */ private static void updateMetricsToReservoir(SQLRequest sqlRequest, SQLResponse sqlResponse) { if (!KylinConfig.getInstanceFromEnv().isKylinMetricsReporterForQueryEnabled()) { return; } String user = SecurityContextHolder.getContext().getAuthentication().getName(); if (user == null) { user = "unknown"; } for (QueryContext.RPCStatistics entry : QueryContextFacade.current().getRpcStatisticsList()) { RecordEvent rpcMetricsEvent = new TimedRecordEvent( KylinConfig.getInstanceFromEnv().getKylinMetricsSubjectQueryRpcCall()); setRPCWrapper(rpcMetricsEvent, // norm(sqlRequest.getProject()), entry.getRealizationName(), entry.getRpcServer(), entry.getException()); setRPCStats(rpcMetricsEvent, // entry.getCallTimeMs(), entry.getSkippedRows(), entry.getScannedRows(), entry.getReturnedRows(), entry.getAggregatedRows()); //For update rpc level related metrics MetricsManager.getInstance().update(rpcMetricsEvent); } for (QueryContext.CubeSegmentStatisticsResult contextEntry : sqlResponse.getCubeSegmentStatisticsList()) { RecordEvent queryMetricsEvent = new TimedRecordEvent( KylinConfig.getInstanceFromEnv().getKylinMetricsSubjectQuery()); setQueryWrapper(queryMetricsEvent, // user, sqlRequest.getSql(), sqlResponse.isStorageCacheUsed() ? "CACHE" : contextEntry.getQueryType(), norm(sqlRequest.getProject()), contextEntry.getRealization(), contextEntry.getRealizationType(), sqlResponse.getThrowable()); long totalStorageReturnCount = 0L; if (contextEntry.getQueryType().equalsIgnoreCase(OLAPQuery.EnumeratorTypeEnum.OLAP.name())) { for (Map<String, QueryContext.CubeSegmentStatistics> cubeEntry : contextEntry.getCubeSegmentStatisticsMap() .values()) { for (QueryContext.CubeSegmentStatistics segmentEntry : cubeEntry.values()) { RecordEvent cubeSegmentMetricsEvent = new TimedRecordEvent( KylinConfig.getInstanceFromEnv().getKylinMetricsSubjectQueryCube()); setCubeWrapper(cubeSegmentMetricsEvent, // norm(sqlRequest.getProject()), segmentEntry.getCubeName(), segmentEntry.getSegmentName(), segmentEntry.getSourceCuboidId(), segmentEntry.getTargetCuboidId(), segmentEntry.getFilterMask()); setCubeStats(cubeSegmentMetricsEvent, // segmentEntry.getCallCount(), segmentEntry.getCallTimeSum(), segmentEntry.getCallTimeMax(), segmentEntry.getStorageSkippedRows(), segmentEntry.getStorageScannedRows(), segmentEntry.getStorageReturnedRows(), segmentEntry.getStorageAggregatedRows(), segmentEntry.isIfSuccess(), 1.0 / cubeEntry.size()); totalStorageReturnCount += segmentEntry.getStorageReturnedRows(); //For update cube segment level related query metrics MetricsManager.getInstance().update(cubeSegmentMetricsEvent); } } } else { if (!sqlResponse.getIsException()) { totalStorageReturnCount = sqlResponse.getResults().size(); } } setQueryStats(queryMetricsEvent, // sqlResponse.getDuration(), sqlResponse.getResults() == null ? 0 : sqlResponse.getResults().size(), totalStorageReturnCount); //For update query level metrics MetricsManager.getInstance().update(queryMetricsEvent); } }
Example 20
Source File: QueryController.java From Kylin with Apache License 2.0 | 4 votes |
private SQLResponse doQuery(SQLRequest sqlRequest) { String sql = sqlRequest.getSql(); String project = sqlRequest.getProject(); logger.info("Using project: " + project); logger.info("The original query: " + sql); String serverMode = KylinConfig.getInstanceFromEnv().getServerMode(); if (!(Constant.SERVER_MODE_QUERY.equals(serverMode.toLowerCase()) || Constant.SERVER_MODE_ALL.equals(serverMode.toLowerCase()))) { throw new InternalErrorException("Query is not allowed in " + serverMode + " mode."); } if (sql.toLowerCase().contains("select") == false) { logger.debug("Directly return expection as not supported"); throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly("Not Supported SQL.")); } SQLResponse sqlResponse = searchQueryInCache(sqlRequest); try { if (null == sqlResponse) { sqlResponse = queryService.query(sqlRequest); long durationThreshold = KylinConfig.getInstanceFromEnv().getQueryDurationCacheThreshold(); long scancountThreshold = KylinConfig.getInstanceFromEnv().getQueryScanCountCacheThreshold(); if (!sqlResponse.getIsException() && (sqlResponse.getDuration() > durationThreshold || sqlResponse.getTotalScanCount() > scancountThreshold)) { cacheManager.getCache(SUCCESS_QUERY_CACHE).put(new Element(sqlRequest, sqlResponse)); } } checkQueryAuth(sqlResponse); return sqlResponse; } catch (AccessDeniedException ade) { // Access exception is bind with each user, it will not be cached logger.error("Exception when execute sql", ade); throw new ForbiddenException(ade.getLocalizedMessage()); } catch (Throwable e) { // calcite may throw AssertError SQLResponse exceptionRes = new SQLResponse(null, null, 0, true, e.getMessage()); Cache exceptionCache = cacheManager.getCache(EXCEPTION_QUERY_CACHE); exceptionCache.put(new Element(sqlRequest, exceptionRes)); logger.error("Exception when execute sql", e); throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly(e.getLocalizedMessage())); } }