如何为每个flink作业分隔日志信息?

时间:2019-08-15 12:19:15

标签: java apache-flink flink-sql

我在纱线会话模式下在纱线簇上运行一些flink-streaming作业, 实际上,我想将每个作业日志分开进行调试或其他目的。 现在,我使用Aspectj和Log4j MDC处理一些日志,例如下面的日志信息,它可以正常工作

@model IEnumerable<WebApplication6.Controllers.Employee>

@{
    ViewData["Title"] = "Employees";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>Employees</h1>

<p>
    <a asp-action="Create">Create New</a>
</p>
<table class="table">
    <thead>
        <tr>
            <th>
                @Html.DisplayNameFor(model => model.EmployeeID)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.EmployeeName)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Address)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Email)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.ContactNo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Gender)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Birthday)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Status)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Position)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Department)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @if (Model == null)
        {
            <tr>
                <td colspan="7" class="text-center">No Model Data</td>
            </tr>
        }
        else
        {
            foreach (var list in Model)
             {
                 <tr>
                     <td>@Html.DisplayFor(Model => list.EmployeeID)</td>
                     <td>@Html.DisplayFor(Model => list.EmployeeName)</td>
                     <td>@Html.DisplayFor(Model => list.Address)</td>
                     <td>@Html.DisplayFor(Model => list.Email)</td>
                     <td>@Html.DisplayFor(Model => list.ContactNo)</td>
                     <td>@Html.DisplayFor(Model => list.Gender)</td>
                     <td>@Html.DisplayFor(Model => list.Birthday)</td>
                     <td>@Html.DisplayFor(Model => list.Status)</td>
                     <td>@Html.DisplayFor(Model => list.Position)</td>
                     <td>@Html.DisplayFor(Model => list.Department)</td>
                     <td>
                         <button class="btn-default" asp-action="Update" asp-route-id="@list.EmployeeID">Edit</button>
                     </td>
                     <td>
                         <form asp-action="Delete" method="post" asp-route-id="@list.EmployeeID">
                             <button class="btn-danger">Delete</button>
                         </form>
                     </td>
                 </tr>
             }
        }
    </tbody>
</table>

但是其他人似乎很难分开

[JobId-gamenews_push_readaction_c941c1dffe1450ec74ce6973cdb44961]-[2019-08-15 19:43:39] [ERROR][cn.migu.bi.flink.jobs.stream.gamenews.hot.IgniteReadSink][invoke][95]-> 处理数据发生异常:org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT INTO readaction ( deviceId, userId, readedId, synTime ) VALUES ( ?, ?, ?, ? ) ]; Duplicate key during INSERT [key=SQL_PUBLIC_READACTION_abc3d77d_dbbe_45a7_8077_93b758c739ea_KEY [idHash=687625062, hash=223752637, DEVICEID=60c9e2f0a9d34c9f, READEDID=2000814]]; nested exception is java.sql.SQLException: Duplicate key during INSERT [key=SQL_PUBLIC_READACTION_abc3d77d_dbbe_45a7_8077_93b758c739ea_KEY [idHash=687625062, hash=223752637, DEVICEID=60c9e2f0a9d34c9f, READEDID=2000814]],发送脏数据:{"synTime":1565860801359,"readedArray":[2000814,2003419,2007497],"deviceId":"60c9e2f0a9d34c9f"}

我尝试了其他方法,例如更改flink的源代码,添加了一些代码,例如MDC.put(“”,“”),它在我运行时可以在IDE上运行,但是在纱线群集上失败

那么,是否还有其他方法可以解决此问题?

public aspect Log {

    private Logger log = LoggerFactory.getLogger(Log.class);

    private pointcut executionJoinPoints():  execution (* cn.migu.bi.flink..*.open(..));
    before(): executionJoinPoints(){
        if (thisJoinPoint.getTarget() instanceof RichAsyncFunction) {
            RichAsyncFunction target = (RichAsyncFunction) thisJoinPoint.getTarget();
            Log4jUtils.initFlinkLog(target.getRuntimeContext().getMetricGroup());
        } else if (thisJoinPoint.getTarget() instanceof RichSinkFunction) {
            RichSinkFunction target = (RichSinkFunction) thisJoinPoint.getTarget();
            Log4jUtils.initFlinkLog(target.getRuntimeContext().getMetricGroup());
        }
    }


}

0 个答案:

没有答案