diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 93d0e790da1..f24f0bc95aa 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -200,6 +200,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Add setup option `--force-enable-module-filesets`, that will act as if all filesets have been enabled in a module during setup. {issue}30915[30915] {pull}99999[99999] - Add setup option `--force-enable-module-filesets`, that will act as if all filesets have been enabled in a module during setup. {issue}30915[30915] {pull}36286[36286] - [Azure] Add input metrics to the azure-eventhub input. {pull}35739[35739] +- Reduce HTTPJSON metrics allocations. {pull}36282[36282] *Auditbeat* diff --git a/x-pack/filebeat/input/httpjson/metrics_test.go b/x-pack/filebeat/input/httpjson/metrics_test.go index 59043a8fcf8..1b57bc5edce 100644 --- a/x-pack/filebeat/input/httpjson/metrics_test.go +++ b/x-pack/filebeat/input/httpjson/metrics_test.go @@ -41,7 +41,10 @@ func TestMetrics(t *testing.T) { }, baseConfig: map[string]interface{}{ "interval": time.Millisecond, - "request.method": http.MethodGet, + "request.method": http.MethodPost, + "request.body": map[string]interface{}{ + "field": "value", + }, "response.split": map[string]interface{}{ "target": "body.items", "transforms": []interface{}{ @@ -70,21 +73,20 @@ func TestMetrics(t *testing.T) { }, assertMetrics: func(reg *monitoring.Registry) error { checkHasValue := func(v interface{}) bool { - var c int64 switch t := v.(type) { case int64: - c = t + return t > 0 case map[string]interface{}: h := t["histogram"].(map[string]interface{}) - c = h["count"].(int64) + return h["count"].(int64) > 0 && h["max"].(int64) > 0 } - return c > 0 + return false } snapshot := monitoring.CollectStructSnapshot(reg, monitoring.Full, true) for _, m := range []string{ - "http_request_body_bytes", "http_request_get_total", + "http_request_body_bytes", "http_request_post_total", "http_request_total", "http_response_2xx_total", "http_response_body_bytes", "http_response_total", "http_round_trip_time", "httpjson_interval_execution_time", diff --git a/x-pack/filebeat/input/internal/httplog/roundtripper.go b/x-pack/filebeat/input/internal/httplog/roundtripper.go index 2280dc73d60..d50981e8117 100644 --- a/x-pack/filebeat/input/internal/httplog/roundtripper.go +++ b/x-pack/filebeat/input/internal/httplog/roundtripper.go @@ -327,17 +327,9 @@ func (rt *MetricsRoundTripper) RoundTrip(req *http.Request) (*http.Response, err rt.monitorByMethod(req.Method) - var ( - body []byte - err error - ) - - req.Body, body, err = copyBody(req.Body) - if err != nil { - rt.metrics.reqErrs.Add(1) - } else { - rt.metrics.reqsAccSize.Add(uint64(len(body))) - rt.metrics.reqsSize.Update(int64(len(body))) + if req.ContentLength >= 0 { + rt.metrics.reqsAccSize.Add(uint64(req.ContentLength)) + rt.metrics.reqsSize.Update(req.ContentLength) } reqStart := time.Now() @@ -355,12 +347,9 @@ func (rt *MetricsRoundTripper) RoundTrip(req *http.Request) (*http.Response, err rt.monitorByStatusCode(resp.StatusCode) - resp.Body, body, err = copyBody(resp.Body) - if err != nil { - rt.metrics.respErrs.Add(1) - } else { - rt.metrics.respsAccSize.Add(uint64(len(body))) - rt.metrics.respsSize.Update(int64(len(body))) + if resp.ContentLength >= 0 { + rt.metrics.respsAccSize.Add(uint64(resp.ContentLength)) + rt.metrics.respsSize.Update(resp.ContentLength) } return resp, err