Search in sources :

Example 1 with IMetric

use of com.dtstack.taier.common.metric.batch.IMetric in project Taier by DTStack.

the class BatchServerLogService method parseIncreInfo.

/**
 * 解析增量同步信息
 */
private void parseIncreInfo(final JSONObject info, final String job, final Long tenantId, final String jobId, final long startTime, final long endTime, final String taskParams) {
    if (StringUtils.isEmpty(jobId)) {
        return;
    }
    try {
        final EDeployMode deployModeEnum = TaskParamsUtils.parseDeployTypeByTaskParams(taskParams, ComputeType.BATCH.getType());
        JSONObject flinkJsonObject = Engine2DTOService.getComponentConfig(tenantId, EComponentType.FLINK);
        final String prometheusHost = flinkJsonObject.getJSONObject(deployModeEnum.name()).getString("prometheusHost");
        final String prometheusPort = flinkJsonObject.getJSONObject(deployModeEnum.name()).getString("prometheusPort");
        // prometheus的配置信息 从控制台获取
        final PrometheusMetricQuery prometheusMetricQuery = new PrometheusMetricQuery(String.format("%s:%s", prometheusHost, prometheusPort));
        final IMetric startLocationMetric = MetricBuilder.buildMetric("startLocation", jobId, startTime, endTime, prometheusMetricQuery);
        final IMetric endLocationMetric = MetricBuilder.buildMetric("endLocation", jobId, startTime, endTime, prometheusMetricQuery);
        String startLocation = null;
        String endLocation = null;
        if (startLocationMetric != null) {
            startLocation = String.valueOf(startLocationMetric.getMetric());
        }
        if (Objects.nonNull(endLocationMetric)) {
            endLocation = String.valueOf(endLocationMetric.getMetric());
        }
        if (StringUtils.isBlank(job)) {
            return;
        }
        final JSONObject jobJson = JSON.parseObject(job);
        final String increColumn = (String) JSONPath.eval(jobJson, "$.job.content[0].reader.parameter.increColumn");
        final String table = (String) JSONPath.eval(jobJson, "$.job.content[0].reader.parameter.connection[0].table[0]");
        final StringBuilder increStrBuild = new StringBuilder();
        increStrBuild.append("数据表:  \t").append(table).append("\n");
        increStrBuild.append("增量标识:\t").append(increColumn).append("\n");
        if (StringUtils.isEmpty(endLocation) || endLocation.startsWith("-")) {
            increStrBuild.append("开始位置:\t").append("同步数据条数为0").append("\n");
            info.put("increInfo", increStrBuild.toString());
            return;
        }
        boolean isDateCol = false;
        final JSONArray columns = (JSONArray) JSONPath.eval(jobJson, "$.job.content[0].reader.parameter.column");
        for (final Object column : columns) {
            if (column instanceof JSONObject) {
                final String name = ((JSONObject) column).getString("name");
                if (name != null && name.equals(increColumn)) {
                    final String type = ((JSONObject) column).getString("type");
                    Boolean typeCheck = type != null && (type.matches("(?i)date|datetime|time") || type.toLowerCase().contains("timestamp"));
                    if (typeCheck) {
                        isDateCol = true;
                    }
                }
            }
        }
        if (StringUtils.isEmpty(startLocation)) {
            startLocation = "全量同步";
        }
        if (isDateCol) {
            startLocation = this.formatLongStr(startLocation);
            endLocation = this.formatLongStr(endLocation);
        }
        increStrBuild.append("开始位置:\t").append(startLocation).append("\n");
        increStrBuild.append("结束位置:\t").append(endLocation).append("\n");
        info.put("increInfo", increStrBuild.toString());
    } catch (Exception e) {
        LOGGER.warn("{}", e);
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) IMetric(com.dtstack.taier.common.metric.batch.IMetric) JSONArray(com.alibaba.fastjson.JSONArray) JSONObject(com.alibaba.fastjson.JSONObject) EDeployMode(com.dtstack.taier.pluginapi.enums.EDeployMode) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) PrometheusMetricQuery(com.dtstack.taier.common.metric.prometheus.PrometheusMetricQuery)

Example 2 with IMetric

use of com.dtstack.taier.common.metric.batch.IMetric in project Taier by DTStack.

the class BatchServerLogService method formatPerfLogInfo.

public String formatPerfLogInfo(final String engineJobId, final String jobId, final long startTime, final long endTime, final Long tenantId) {
    final ScheduleJob job = scheduleJobService.getByJobId(jobId);
    if (Objects.isNull(job)) {
        LOGGER.info("can not find job by id:{}.", jobId);
        throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_JOB);
    }
    if (job.getTaskId() == null || job.getTaskId() == -1) {
        throw new RdosDefineException(ErrorCode.CAN_NOT_FIND_TASK);
    }
    BatchTask batchTaskById = batchTaskService.getBatchTaskById(job.getTaskId());
    // prometheus的配置信息 从控制台获取
    final Pair<String, String> prometheusHostAndPort = this.getPrometheusHostAndPort(tenantId, batchTaskById.getTaskParams());
    if (prometheusHostAndPort == null) {
        return "promethues配置为空";
    }
    final PrometheusMetricQuery prometheusMetricQuery = new PrometheusMetricQuery(String.format("%s:%s", prometheusHostAndPort.getKey(), prometheusHostAndPort.getValue()));
    // 之后查询是可以直接获取最后一条记录的方法
    // 防止数据同步执行时间太长 查询prometheus的时候返回exceeded maximum resolution of 11,000 points per timeseries
    final long maxGapTime = 60 * 1000 * 60 * (long) 8;
    long gapStartTime = startTime;
    if (endTime - startTime >= maxGapTime) {
        // 超过11,000 points 查询1小时间隔内
        gapStartTime = endTime - 60 * 1000 * 60;
    }
    final IMetric numReadMetric = MetricBuilder.buildMetric("numRead", engineJobId, gapStartTime, endTime, prometheusMetricQuery);
    final IMetric byteReadMetric = MetricBuilder.buildMetric("byteRead", engineJobId, gapStartTime, endTime, prometheusMetricQuery);
    final IMetric readDurationMetric = MetricBuilder.buildMetric("readDuration", engineJobId, gapStartTime, endTime, prometheusMetricQuery);
    final IMetric numWriteMetric = MetricBuilder.buildMetric("numWrite", engineJobId, gapStartTime, endTime, prometheusMetricQuery);
    final IMetric byteWriteMetric = MetricBuilder.buildMetric("byteWrite", engineJobId, gapStartTime, endTime, prometheusMetricQuery);
    final IMetric writeDurationMetric = MetricBuilder.buildMetric("writeDuration", engineJobId, gapStartTime, endTime, prometheusMetricQuery);
    final IMetric numErrorMetric = MetricBuilder.buildMetric("nErrors", engineJobId, gapStartTime, endTime, prometheusMetricQuery);
    final SyncStatusLogInfoVO formatPerfLogInfo = this.getFormatPerfLogInfo(numReadMetric, byteReadMetric, readDurationMetric, numWriteMetric, byteWriteMetric, writeDurationMetric, numErrorMetric);
    return formatPerfLogInfo.buildReadableLog();
}
Also used : ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) BatchTask(com.dtstack.taier.dao.domain.BatchTask) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IMetric(com.dtstack.taier.common.metric.batch.IMetric) SyncStatusLogInfoVO(com.dtstack.taier.develop.dto.devlop.SyncStatusLogInfoVO) PrometheusMetricQuery(com.dtstack.taier.common.metric.prometheus.PrometheusMetricQuery)

Example 3 with IMetric

use of com.dtstack.taier.common.metric.batch.IMetric in project Taier by DTStack.

the class SyncOperatorPipeline method queryLastLocation.

public String queryLastLocation(Long tenantId, String engineJobId, long startTime, long endTime, EDeployMode deployMode, String jobId, String componentVersion) {
    endTime = endTime + 1000 * 60;
    List<Component> components = componentService.listComponentsByComponentType(tenantId, EComponentType.FLINK.getTypeCode());
    if (CollectionUtils.isEmpty(components)) {
        return null;
    }
    Optional<Component> componentOptional = components.stream().filter(c -> c.getVersionValue().equals(componentVersion)).findFirst();
    if (!componentOptional.isPresent()) {
        return null;
    }
    Map<String, Object> componentConfigToMap = componentConfigService.convertComponentConfigToMap(componentOptional.get().getId(), true);
    Map<String, Object> flinkConfig = (Map<String, Object>) componentConfigToMap.get(deployMode.getMode());
    String prometheusHost = (String) flinkConfig.get("prometheusHost");
    String prometheusPort = (String) flinkConfig.get("prometheusPort");
    LOGGER.info("last job {} deployMode {} prometheus host {} port {}", jobId, deployMode.getType(), prometheusHost, prometheusPort);
    // prometheus的配置信息 从控制台获取
    PrometheusMetricQuery prometheusMetricQuery = new PrometheusMetricQuery(String.format("%s:%s", prometheusHost, prometheusPort));
    IMetric numReadMetric = MetricBuilder.buildMetric("endLocation", engineJobId, startTime, endTime, prometheusMetricQuery);
    if (numReadMetric != null) {
        String startLocation = String.valueOf(numReadMetric.getMetric());
        LOGGER.info("job {} deployMode {} startLocation [{}]", jobId, deployMode.getType(), startLocation);
        if (StringUtils.isEmpty(startLocation) || "0".equalsIgnoreCase(startLocation)) {
            return null;
        }
        return String.valueOf(numReadMetric.getMetric());
    }
    return null;
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) TaskParamsUtils(com.dtstack.taier.common.util.TaskParamsUtils) ScheduleJob(com.dtstack.taier.dao.domain.ScheduleJob) EDeployMode(com.dtstack.taier.pluginapi.enums.EDeployMode) LoggerFactory(org.slf4j.LoggerFactory) LocalDateTime(java.time.LocalDateTime) EnvironmentContext(com.dtstack.taier.common.env.EnvironmentContext) IPipeline(com.dtstack.taier.scheduler.server.pipeline.IPipeline) Autowired(org.springframework.beans.factory.annotation.Autowired) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) JSONPath(com.alibaba.fastjson.JSONPath) BooleanUtils(org.apache.commons.lang.BooleanUtils) PrometheusMetricQuery(com.dtstack.taier.common.metric.prometheus.PrometheusMetricQuery) ScheduleTaskParamShade(com.dtstack.taier.dao.dto.ScheduleTaskParamShade) IMetric(com.dtstack.taier.common.metric.batch.IMetric) ComponentService(com.dtstack.taier.scheduler.service.ComponentService) ByteArrayInputStream(java.io.ByteArrayInputStream) Component(com.dtstack.taier.dao.domain.Component) ClusterService(com.dtstack.taier.scheduler.service.ClusterService) Splitter(com.google.common.base.Splitter) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) DateTimeFormat(org.joda.time.format.DateTimeFormat) Charsets(com.google.common.base.Charsets) Cluster(com.dtstack.taier.dao.domain.Cluster) ScheduleTaskShade(com.dtstack.taier.dao.domain.ScheduleTaskShade) Logger(org.slf4j.Logger) ScheduleJobMapper(com.dtstack.taier.dao.mapper.ScheduleJobMapper) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) ExceptionUtil(com.dtstack.taier.pluginapi.exception.ExceptionUtil) JobParamReplace(com.dtstack.taier.scheduler.server.pipeline.JobParamReplace) Timestamp(java.sql.Timestamp) EScheduleType(com.dtstack.taier.common.enums.EScheduleType) CommonConstant(com.dtstack.taier.common.constant.CommonConstant) EComponentType(com.dtstack.taier.common.enums.EComponentType) MetricBuilder(com.dtstack.taier.common.metric.batch.MetricBuilder) DataSourceType(com.dtstack.taier.common.enums.DataSourceType) RetryUtil(com.dtstack.taier.pluginapi.util.RetryUtil) URLEncoder(java.net.URLEncoder) CollectionUtils(org.springframework.util.CollectionUtils) WorkerOperator(com.dtstack.taier.scheduler.WorkerOperator) ConfigConstant(com.dtstack.taier.pluginapi.constrant.ConfigConstant) JSONObject(com.alibaba.fastjson.JSONObject) ComponentConfigService(com.dtstack.taier.scheduler.service.ComponentConfigService) Joiner(com.google.common.base.Joiner) IMetric(com.dtstack.taier.common.metric.batch.IMetric) JSONObject(com.alibaba.fastjson.JSONObject) Component(com.dtstack.taier.dao.domain.Component) PrometheusMetricQuery(com.dtstack.taier.common.metric.prometheus.PrometheusMetricQuery)

Aggregations

RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 IMetric (com.dtstack.taier.common.metric.batch.IMetric)3 PrometheusMetricQuery (com.dtstack.taier.common.metric.prometheus.PrometheusMetricQuery)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ScheduleJob (com.dtstack.taier.dao.domain.ScheduleJob)2 EDeployMode (com.dtstack.taier.pluginapi.enums.EDeployMode)2 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONPath (com.alibaba.fastjson.JSONPath)1 CommonConstant (com.dtstack.taier.common.constant.CommonConstant)1 DataSourceType (com.dtstack.taier.common.enums.DataSourceType)1 EComponentType (com.dtstack.taier.common.enums.EComponentType)1 EScheduleType (com.dtstack.taier.common.enums.EScheduleType)1 EnvironmentContext (com.dtstack.taier.common.env.EnvironmentContext)1 MetricBuilder (com.dtstack.taier.common.metric.batch.MetricBuilder)1 TaskParamsUtils (com.dtstack.taier.common.util.TaskParamsUtils)1 BatchTask (com.dtstack.taier.dao.domain.BatchTask)1 Cluster (com.dtstack.taier.dao.domain.Cluster)1 Component (com.dtstack.taier.dao.domain.Component)1 ScheduleTaskShade (com.dtstack.taier.dao.domain.ScheduleTaskShade)1 ScheduleTaskParamShade (com.dtstack.taier.dao.dto.ScheduleTaskParamShade)1