|
|
@@ -213,12 +213,45 @@ func (c *Container) onL7RequestApm(pid uint32, fd uint64, timestamp uint64, r *l
|
|
|
*/
|
|
|
if r.Protocol == l7.ProtocolHTTP {
|
|
|
if c.l7Attach && c.valuableTrace(r.TraceId) {
|
|
|
- method, requestURI, sn, sport := l7.ParseHttpHost(r.Payload, r.IsTls)
|
|
|
- apmTrace, err := c.getOrInitTrace(r.TraceId)
|
|
|
- //fmt.Println("ProtocolHTTP-----", r.TraceId, err)
|
|
|
- if err == nil {
|
|
|
- apmTrace.HttpTraceRequestEvent(method, requestURI, sn, sport, r)
|
|
|
- c.SendEvent(apmTrace, r.TraceId)
|
|
|
+ // 检查是否启用 Elasticsearch 检测
|
|
|
+ if *flags.EnableElasticsearchDetection {
|
|
|
+ // 解析 User-Agent 以检测 Elasticsearch 请求
|
|
|
+ method, requestURI, sn, sport, userAgent := l7.ParseHttpHostWithUserAgent(r.Payload, r.IsTls)
|
|
|
+ // 检查是否是 Elasticsearch 请求(通过 User-Agent)
|
|
|
+ isElasticsearch := strings.Contains(strings.ToLower(userAgent), "elasticsearch")
|
|
|
+ apmTrace, err := c.getOrInitTrace(r.TraceId)
|
|
|
+ //fmt.Println("ProtocolHTTP-----", r.TraceId, err)
|
|
|
+ if err == nil {
|
|
|
+ if isElasticsearch {
|
|
|
+ r.Protocol = l7.ProtocolES
|
|
|
+ // Elasticsearch 请求,按照 NoSQL 方式处理
|
|
|
+ query := l7.ParseElasticsearch(r.Payload)
|
|
|
+ if c.AppInfo.AppName != "" {
|
|
|
+ klog.Debugf("[%s] ->>>>> Elasticsearch -> %s:%d Query:[%s]", c.AppInfo.AppName, sn, sport, query)
|
|
|
+ }
|
|
|
+ conn := c.connectionsByPidFd[PidFd{Pid: pid, Fd: fd}]
|
|
|
+ if conn == nil {
|
|
|
+ conn = &ActiveConnection{
|
|
|
+ Dest: r.ComponentDAddr,
|
|
|
+ ActualDest: r.ComponentDAddr,
|
|
|
+ Timestamp: timestamp,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ apmTrace.NoSQLTraceQueryEvent(r.Protocol, semconv.DBSystemElasticsearch, method, query, r, conn.Src, conn.ActualDest)
|
|
|
+ } else {
|
|
|
+ // 普通 HTTP 请求
|
|
|
+ apmTrace.HttpTraceRequestEvent(method, requestURI, sn, sport, r)
|
|
|
+ }
|
|
|
+ c.SendEvent(apmTrace, r.TraceId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // Elasticsearch 检测未启用,使用普通 HTTP 处理
|
|
|
+ method, requestURI, sn, sport := l7.ParseHttpHost(r.Payload, r.IsTls)
|
|
|
+ apmTrace, err := c.getOrInitTrace(r.TraceId)
|
|
|
+ if err == nil {
|
|
|
+ apmTrace.HttpTraceRequestEvent(method, requestURI, sn, sport, r)
|
|
|
+ c.SendEvent(apmTrace, r.TraceId)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
//return nil
|