Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- rabbitmq/queue - Change the mapping type of `rabbitmq.queue.consumers.utilisation.pct` to `scaled_float` from `long` because the values fall within the range of `[0.0, 1.0]`. Previously, conversion to integer resulted in reporting either `0` or `1`.
- Fix timeout caused by the retrival of which indices are hidden {pull}39165[39165]
- Fix Azure Monitor support for multiple aggregation types {issue}39192[39192] {pull}39204[39204]
- Fix http server helper SSL config. {pull}39405[39405]

*Osquerybeat*

Expand Down
16 changes: 9 additions & 7 deletions metricbeat/helper/server/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package http

import (
"context"
"io/ioutil"
"io"
"net"
"net/http"
"strconv"
"time"

"github.com/elastic/beats/v7/metricbeat/helper/server"
"github.com/elastic/beats/v7/metricbeat/mb"
Expand Down Expand Up @@ -73,10 +74,11 @@ func getDefaultHttpServer(mb mb.BaseMetricSet) (*HttpServer, error) {
}

httpServer := &http.Server{
Addr: net.JoinHostPort(config.Host, strconv.Itoa(int(config.Port))),
Addr: net.JoinHostPort(config.Host, strconv.Itoa(config.Port)),
ReadHeaderTimeout: 10 * time.Second,
}
if tlsConfig != nil {
httpServer.TLSConfig = tlsConfig.BuildModuleClientConfig(config.Host)
httpServer.TLSConfig = tlsConfig.BuildServerConfig(config.Host)
}
h.server = httpServer
return h, nil
Expand Down Expand Up @@ -126,7 +128,7 @@ func (h *HttpServer) Start() error {
func (h *HttpServer) Stop() {
close(h.done)
h.stop()
h.server.Shutdown(h.ctx)
_ = h.server.Shutdown(h.ctx)
close(h.eventQueue)
}

Expand All @@ -147,7 +149,7 @@ func (h *HttpServer) handleFunc(writer http.ResponseWriter, req *http.Request) {
meta["Content-Type"] = contentType
}

body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
if err != nil {
logp.Err("Error reading body: %v", err)
http.Error(writer, "Unexpected error reading request payload", http.StatusBadRequest)
Expand All @@ -168,9 +170,9 @@ func (h *HttpServer) handleFunc(writer http.ResponseWriter, req *http.Request) {
case "GET":
writer.WriteHeader(http.StatusOK)
if req.TLS != nil {
writer.Write([]byte("HTTPS Server accepts data via POST"))
_, _ = writer.Write([]byte("HTTPS Server accepts data via POST"))
} else {
writer.Write([]byte("HTTP Server accepts data via POST"))
_, _ = writer.Write([]byte("HTTP Server accepts data via POST"))
}

}
Expand Down
4 changes: 2 additions & 2 deletions metricbeat/helper/server/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"strconv"
Expand Down Expand Up @@ -230,7 +230,7 @@ func writeToServer(t *testing.T, message, host string, port int, connectionMetho

if connectionMethod == "GET" {
if resp.StatusCode == http.StatusOK {
bodyBytes, err2 := ioutil.ReadAll(resp.Body)
bodyBytes, err2 := io.ReadAll(resp.Body)
if err2 != nil {
t.Error(err)
t.FailNow()
Expand Down