ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Pinpoint WebSphere 插件接入指南:配置详解与源码级原理剖析

Pinpoint WebSphere 插件接入指南:配置详解与源码级原理剖析 Pinpoint WebSphere 插件接入指南配置详解与源码级原理剖析【免费下载链接】pinpointAPM, (Application Performance Management) tool for large-scale distributed systems.项目地址: https://gitcode.com/gh_mirrors/pi/pinpoint导读本文以 Pinpoint 仓库中 agent-module/plugins/websphere/README.md 为主体系统讲解 Pinpoint 如何对 IBM WebSphere Application Server 进行 APM 监控从 pinpoint.config 中profiler.websphere.*系列参数的逐项说明到插件在 WebSphere 内部的字节码增强点、请求入口拦截、状态码采集与异步 Servlet 链路传播的实现原理。读完本文你将能够独立完成 WebSphere6.18 版本区间应用服务器的 Pinpoint 接入配置并根据实际场景调优请求参数追踪、URL/HTTP 方法排除、真实 IP 头识别等选项同时理解每一项配置背后的源码落点。WebSphere 插件概述WebSphere 插件是 Pinpoint 众多 Servlet 容器类插件 之一用于在IBM WebSphere Application Server上采集 HTTP 请求的调用链数据。根据官方 README 声明引入版本Pinpoint 1.7.0 起提供支持版本区间[6.1, 8]即 WebSphere Application Server 6.1 至 8.x插件源码位置agent-module/plugins/websphere。该插件在 Pinpoint 服务类型体系中注册了两个ServiceType定义见 WebsphereConstants.javaServiceType 常量类型码说明WEBSPHERE1060WebSphere 应用服务器本身启用RECORD_STATISTICS用于统计WEBSPHERE_METHOD1061WebSphere 内部方法调用如请求入口、异步启动点插件 Maven 坐标与打包方式见 pom.xmlartifactId 为pinpoint-websphere-plugin它依赖pinpoint-bootstrap-core与javax.servlet-api均为provided作用域并依赖pinpoint-common-servlet编译期打入插件 jar 并重定位到com.navercorp.pinpoint.plugin.websphere.common.servlet避免与宿主的类冲突。提示插件对 WebSphere 内部类的引用通过独立的src/main/java-ibm源目录提供由build-helper-maven-plugin在generate-sources阶段加入编译其中以com.ibm.*包名定义了IRequest、IResponse、SRTServletRequest、WCCResponseImpl等接口的占位实现供编译期使用。接入配置pinpoint.configWebSphere 插件的全部开关均位于 agent 的pinpoint.config文件中。官方 README 给出的配置片段在仓库的 release 环境默认配置 中有完整的对应段落profiler.weblogic.*之后的# Websphere段落两者内容一致。启用开关profiler.websphere.enabletrue含义是否启用 WebSphere 插件。默认值true源码中config.readBoolean(profiler.websphere.enable, true)见 WebsphereConfiguration.java。源码行为在 WebspherePlugin.setup() 中若该值为false插件直接返回不做任何字节码注入。应用服务器类型识别# Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported. profiler.websphere.bootstrap.main含义用于识别当前进程是否为 WebSphere的主类名列表多个类名用逗号分隔不支持通配符。默认行为留空时使用内置默认值com.ibm.wsspi.bootstrap.WSPreLauncher见 WebsphereDetector.java。检测机制插件通过MainClassCondition读取 JVM 启动主类bootstrapMainClass与上述列表比对命中后才向 Pinpoint 注册WEBSPHERE(1060)应用类型前提是 WebspherePlugin.java 中context.getConfiguredApplicationType()尚未被其他方式显式指定。请求参数追踪# trace param in request , default value is true profiler.websphere.tracerequestparamtrue含义是否在 Span 中记录 HTTP 请求的查询字符串参数。默认值true。源码行为WebsphereConfiguration通过ServerConfig.isTraceRequestParam(profiler.websphere.tracerequestparam)读取。参数采集的完整链路见 ParameterRecorderFactory.java为false时使用DisableParameterRecorder完全跳过参数提取为true时由 IRequestParameterExtractor.java 解析IRequest.getQueryString()逐个拆分keyvalue对并做 URL 解码单 key/value 截断长度为 64 字符eachLimit64拼接总长度上限 512 字符totalLimit512超限后以...结尾防止超长参数拖垮 Span 数据。ParameterExtractorIRequest parameterExtractor new IRequestParameterExtractor(64, 512);排除 URL# URLs to exclude from tracing. # Support ant style pattern. e.g. /aa/*.html, /??/exclude.html profiler.websphere.excludeurl含义不参与追踪的 URL 列表逗号分隔支持Ant 风格通配例如/aa/*.html匹配/aa/下所有.html页面/??/exclude.html?匹配任意单个字符。默认值空表示不排除任何 URL。源码行为经ServerConfig.getExcludeUrlFilter(profiler.websphere.excludeurl)构造为FilterString在 WebContainerHandleRequestInterceptor 中通过builder.setExcludeURLFilter(...)注入ServletRequestListener命中排除规则的请求不会开启追踪。排除 HTTP 方法# HTTP Request methods to exclude from tracing profiler.websphere.excludemethod含义不参与追踪的 HTTP 方法如GET、POST等逗号分隔。默认值空。源码行为读取为excludeProfileMethodFilter见 WebsphereConfiguration.java。它同时作用于两个层面Span 级不满足过滤条件的方法仍会记录调用链但结合tracerequestparam不记录参数在 MethodFilterExtractor.java 中被排除的方法会返回null从而跳过参数提取。另外 release 配置中还预留了一个与 Servlet 通用机制对齐的扩展项# profiler.websphere.trace.excludemethod它在源码中对应ServerConfig.getTraceExcludeMethodFilter(profiler.websphere.trace.excludemethod)WebsphereConfiguration.java用于在追踪阶段排除特定方法的 Span 记录。隐藏 Pinpoint 请求头# Hide pinpoint headers. profiler.websphere.hidepinpointheadertrue含义是否在getHeaderNames()返回的头部枚举中过滤掉 Pinpoint 内部使用的请求头如Pinpoint-TraceID等见com.navercorp.pinpoint.bootstrap.context.Header。默认值true。源码行为当开启时插件对com.ibm.ws.webcontainer.srt.SRTServletRequest织入 SRTServletRequestAspect将原始getHeaderNames()返回的Enumeration包装为DelegateEnumeration并用Header.FILTER过滤内部头WebspherePlugin.java。该选项主要服务于将请求转发给下游应用时避免把 Pinpoint 内部头暴露给业务代码。原始 IP 地址识别注释示例# original IP address header # https://en.wikipedia.org/wiki/X-Forwarded-For #profiler.websphere.realipheaderX-Forwarded-For # nginx real ip header #profiler.websphere.realipheaderX-Real-IP #profiler.websphere.realipemptyvalueunknown含义profiler.websphere.realipheader指定承载客户端真实 IP 的请求头名称。当 WebSphere 位于 nginx、反向代理或负载均衡之后时getRemoteAddr()拿到的是代理地址配置此头可让 Pinpoint 记录真实客户端 IP。release 配置中还给出了多值头示例X-Forwarded-For, Forwarded对应 RFC 7239 的Forwarded头。profiler.websphere.realipemptyvalue可选参数。当上述头的取值为该配置值如unknown时Pinpoint 会忽略该头值视为无效 IP避免把占位字符串当作客户端地址。默认值realipheader默认按 Pinpoint 全局服务器配置处理这两项在 release 配置中默认注释按需取消注释即可。完整配置清单以下为官方 README 的原始配置块可直接粘贴到pinpoint.config#### Set enable options. profiler.websphere.enabletrue # Classes for detecting application server type. Comma separated list of fully qualified class names. Wildcard not supported. profiler.websphere.bootstrap.main # trace param in request , default value is true profiler.websphere.tracerequestparamtrue # URLs to exclude from tracing. # Support ant style pattern. e.g. /aa/*.html, /??/exclude.html profiler.websphere.excludeurl # HTTP Request methods to exclude from tracing profiler.websphere.excludemethod # Hide pinpoint headers. profiler.websphere.hidepinpointheadertrue # original IP address header # https://en.wikipedia.org/wiki/X-Forwarded-For #profiler.websphere.realipheaderX-Forwarded-For # nginx real ip header #profiler.websphere.realipheaderX-Real-IP #profiler.websphere.realipemptyvalueunknown源码级原理插件如何改造 WebSphere官方 README 只给出了配置项本插件的实际监控能力由 WebspherePlugin.java 中的四处字节码转换Transform完成。理解这四处改造点有助于排查为什么某个环节没有 Span。请求入口WSWebContainer.handleRequest插件对com.ibm.ws.webcontainer.WSWebContainer的handleRequest(IRequest, IResponse)方法注入 WebContainerHandleRequestInterceptorWebspherePlugin.javabefore调用servletRequestListener.initialized(request, WEBSPHERE_METHOD, methodDescriptor)开启新的 Trace/Span作为 WebSphere 请求的入口点after根据响应对象取状态码调用servletRequestListener.destroyed(request, throwable, statusCode)结束 Span 并记录异常与响应码。该拦截器同时负责请求数据适配通过 IRequestAdaptor.java 将 IBM 的IRequest适配为 Pinpoint 的RequestAdaptor提供getRpcName取getRequestURI()、getMethodName、getEndPointhost:port、getRemoteAddress、getAcceptorHost等字段记录请求头与 Cookie分别读取ServerHeaderRecorder.CONFIG_KEY_RECORD_REQ_HEADERS与ServerCookieRecorder.CONFIG_KEY_RECORD_REQ_COOKIES对应的全局配置记录 HTTP 状态码错误通过HttpStatusCodeErrors.of(profilerConfig::readString)读取全局的 HTTP 状态码错误判定配置对应profiler.http.status.code.errors等项。状态码采集WCCResponseImpl.setStatusCodecom.ibm.ws.webcontainer.channel.WCCResponseImpl会被添加StatusCodeAccessor字段StatusCodeAccessor.java用于暂存状态码对setStatusCode(int)注入 WCCResponseImplInterceptor在before中把状态码写入 accessor 字段。之后入口拦截器在after阶段通过StatusCodeAccessor._$PINPOINT$_getStatusCode()读取若响应对象本身是WCCResponseImpl且尚未注入 accessor则回退到getHttpResponse().getStatusCodeAsInt()见 WebContainerHandleRequestInterceptor.java。这样 WebSphere 应用在 Pinpoint 中即可按 HTTP 状态码维度进行错误统计与分析。隐藏头与异步链路SRTServletRequest 与 WSAsyncContextImplcom.ibm.ws.webcontainer.srt.SRTServletRequest如前文所述按hidepinpointheader决定是否织入头部过滤 Aspect同时对其startAsync(ServletRequest, ServletResponse)Servlet 3.0 异步 API注入 WCCRequestImplStartAsyncInterceptor在异步启动成功后创建 WebsphereAsyncListener 并注册到AsyncContext从而把异步线程的执行纳入同一条调用链com.ibm.ws.webcontainer.async.WSAsyncContextImpl添加InitResponseGetterInitResponseGetter.java使异步监听器在onComplete时能够取出初始响应对象的状态码完整记录异步请求的最终 HTTP 结果WebsphereAsyncListener.java。应用类型探测WebsphereDetector插件在启动阶段通过 WebsphereDetector.java 判定当前进程是否为 WebSphere将 JVM 启动主类与profiler.websphere.bootstrap.main默认com.ibm.wsspi.bootstrap.WSPreLauncher比对命中即注册WEBSPHERE(1060)应用类型。因此即使你不配置该参数只要应用确实运行在 WebSphere 上插件也能自动完成类型识别。插件装配与验证装配方式pinpoint-websphere-plugin属于 agent-module/plugins 聚合模块构建 agent 时插件 jar 会被统一打包进 agent 的plugin目录agent 启动时自动加载无需额外安装。配置生效位置所有profiler.websphere.*参数写入 agent 的pinpoint.configrelease 默认配置见 release/pinpoint.configlocal 环境同样内置对应段落。验证方法修改配置后重启应用服务器观察 agent 日志中Detected application type : WEBSPHERE与Adding WebSphere transformers等输出对应 WebspherePlugin.java在 Pinpoint Web 界面确认应用类型显示为 WEBSPHERE并检查 HTTP 请求是否有完整调用链若请求未产生 Span优先核对profiler.websphere.enable、excludeurl/excludemethod是否误配以及启动主类是否与bootstrap.main匹配。小结WebSphere 插件是 Pinpoint 服务器插件体系中典型的 Servlet 容器接入实现其 README 虽短却完整覆盖了接入所需的核心开关。本文在继承官方配置的基础上进一步结合 WebsphereConfiguration.java、WebspherePlugin.java 与 release/pinpoint.config 等源码证据说明了每个配置项的实际生效链路入口拦截、参数提取、URL/方法过滤、状态码采集、真实 IP 识别与 Servlet 3.0 异步链路传播。按本文清单配置并观察 agent 日志即可在 WebSphere 6.18 上完成 Pinpoint 的接入与调优。【免费下载链接】pinpointAPM, (Application Performance Management) tool for large-scale distributed systems.项目地址: https://gitcode.com/gh_mirrors/pi/pinpoint创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表