From 62521e629d0b365feb049effef362b2df7470631 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 28 May 2023 09:08:07 +0200 Subject: [PATCH] common/http: rename to common/httpserver This is a preparation to introduce an httpclient common package. And it makes it easier to use http from the standard library. --- cmd/conntrack-fixer.go | 6 ++--- cmd/console.go | 8 +++--- cmd/demo-exporter.go | 8 +++--- cmd/http.go | 4 +-- cmd/inlet.go | 8 +++--- cmd/orchestrator.go | 8 +++--- common/{http => httpserver}/cache.go | 2 +- common/{http => httpserver}/cache_test.go | 26 +++++++++---------- common/{http => httpserver}/config.go | 2 +- common/{http => httpserver}/config_test.go | 2 +- common/{http => httpserver}/metrics.go | 2 +- common/{http => httpserver}/root.go | 4 +-- common/{http => httpserver}/root_test.go | 19 +++++++------- common/{http => httpserver}/tests.go | 2 +- conntrackfixer/root.go | 4 +-- conntrackfixer/root_test.go | 4 +-- console/authentication/handlers_test.go | 30 +++++++++++----------- console/docs_test.go | 4 +-- console/filter_test.go | 10 ++++---- console/root.go | 8 +++--- console/tests.go | 6 ++--- inlet/core/enricher_test.go | 4 +-- inlet/core/root.go | 4 +-- inlet/core/root_test.go | 10 ++++---- inlet/flow/root.go | 8 +++--- inlet/flow/tests.go | 4 +-- orchestrator/clickhouse/http_test.go | 6 ++--- orchestrator/clickhouse/migrations_test.go | 14 +++++----- orchestrator/clickhouse/root.go | 4 +-- orchestrator/clickhouse/source_test.go | 12 ++++----- orchestrator/http_test.go | 4 +-- orchestrator/root.go | 4 +-- 32 files changed, 121 insertions(+), 120 deletions(-) rename common/{http => httpserver}/cache.go (98%) rename common/{http => httpserver}/cache_test.go (88%) rename common/{http => httpserver}/config.go (99%) rename common/{http => httpserver}/config_test.go (94%) rename common/{http => httpserver}/metrics.go (98%) rename common/{http => httpserver}/root.go (98%) rename common/{http => httpserver}/root_test.go (85%) rename common/{http => httpserver}/tests.go (96%) diff --git a/cmd/conntrack-fixer.go b/cmd/conntrack-fixer.go index a7495a81..32d78ea0 100644 --- a/cmd/conntrack-fixer.go +++ b/cmd/conntrack-fixer.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/cobra" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/conntrackfixer" ) @@ -32,9 +32,9 @@ containers started with the label "akvorado.conntrack.fix=1".`, if err != nil { return fmt.Errorf("unable to initialize daemon component: %w", err) } - httpConfiguration := http.DefaultConfiguration() + httpConfiguration := httpserver.DefaultConfiguration() httpConfiguration.Listen = "127.0.0.1:0" // Run inside host network namespace, can't use 8080 - httpComponent, err := http.New(r, httpConfiguration, http.Dependencies{ + httpComponent, err := httpserver.New(r, httpConfiguration, httpserver.Dependencies{ Daemon: daemonComponent, }) if err != nil { diff --git a/cmd/console.go b/cmd/console.go index 0584bece..cc2044c5 100644 --- a/cmd/console.go +++ b/cmd/console.go @@ -10,7 +10,7 @@ import ( "akvorado/common/clickhousedb" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/console" @@ -21,7 +21,7 @@ import ( // ConsoleConfiguration represents the configuration file for the console command. type ConsoleConfiguration struct { Reporting reporter.Configuration - HTTP http.Configuration + HTTP httpserver.Configuration Console console.Configuration `mapstructure:",squash" yaml:",inline"` ClickHouse clickhousedb.Configuration Auth authentication.Configuration @@ -32,7 +32,7 @@ type ConsoleConfiguration struct { // Reset resets the console configuration to its default value. func (c *ConsoleConfiguration) Reset() { *c = ConsoleConfiguration{ - HTTP: http.DefaultConfiguration(), + HTTP: httpserver.DefaultConfiguration(), Reporting: reporter.DefaultConfiguration(), Console: console.DefaultConfiguration(), ClickHouse: clickhousedb.DefaultConfiguration(), @@ -86,7 +86,7 @@ func consoleStart(r *reporter.Reporter, config ConsoleConfiguration, checkOnly b if err != nil { return fmt.Errorf("unable to initialize daemon component: %w", err) } - httpComponent, err := http.New(r, config.HTTP, http.Dependencies{ + httpComponent, err := httpserver.New(r, config.HTTP, httpserver.Dependencies{ Daemon: daemonComponent, }) if err != nil { diff --git a/cmd/demo-exporter.go b/cmd/demo-exporter.go index 71170406..d3ad0b7f 100644 --- a/cmd/demo-exporter.go +++ b/cmd/demo-exporter.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/demoexporter" "akvorado/demoexporter/bmp" @@ -20,7 +20,7 @@ import ( // DemoExporterConfiguration represents the configuration file for the demo exporter command. type DemoExporterConfiguration struct { Reporting reporter.Configuration - HTTP http.Configuration + HTTP httpserver.Configuration DemoExporter demoexporter.Configuration `mapstructure:",squash" yaml:",inline"` SNMP snmp.Configuration BMP bmp.Configuration @@ -30,7 +30,7 @@ type DemoExporterConfiguration struct { // Reset sets the default configuration for the demo exporter command. func (c *DemoExporterConfiguration) Reset() { *c = DemoExporterConfiguration{ - HTTP: http.DefaultConfiguration(), + HTTP: httpserver.DefaultConfiguration(), Reporting: reporter.DefaultConfiguration(), DemoExporter: demoexporter.DefaultConfiguration(), SNMP: snmp.DefaultConfiguration(), @@ -82,7 +82,7 @@ func demoExporterStart(r *reporter.Reporter, config DemoExporterConfiguration, c if err != nil { return fmt.Errorf("unable to initialize daemon component: %w", err) } - httpComponent, err := http.New(r, config.HTTP, http.Dependencies{ + httpComponent, err := httpserver.New(r, config.HTTP, httpserver.Dependencies{ Daemon: daemonComponent, }) if err != nil { diff --git a/cmd/http.go b/cmd/http.go index 310e4594..6fa3e3ab 100644 --- a/cmd/http.go +++ b/cmd/http.go @@ -6,14 +6,14 @@ package cmd import ( "fmt" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" ) // addCommonHTTPHandlers configures various endpoints common to all // services. Each endpoint is registered under `/api/v0` and // `/api/v0/SERVICE` namespaces. -func addCommonHTTPHandlers(r *reporter.Reporter, service string, httpComponent *http.Component) { +func addCommonHTTPHandlers(r *reporter.Reporter, service string, httpComponent *httpserver.Component) { httpComponent.AddHandler(fmt.Sprintf("/api/v0/%s/metrics", service), r.MetricsHTTPHandler()) httpComponent.AddHandler("/api/v0/metrics", r.MetricsHTTPHandler()) httpComponent.GinRouter.GET(fmt.Sprintf("/api/v0/%s/healthcheck", service), r.HealthcheckHTTPHandler) diff --git a/cmd/inlet.go b/cmd/inlet.go index 9485e405..36c53b73 100644 --- a/cmd/inlet.go +++ b/cmd/inlet.go @@ -9,7 +9,7 @@ import ( "github.com/spf13/cobra" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/inlet/bmp" @@ -23,7 +23,7 @@ import ( // InletConfiguration represents the configuration file for the inlet command. type InletConfiguration struct { Reporting reporter.Configuration - HTTP http.Configuration + HTTP httpserver.Configuration Flow flow.Configuration SNMP snmp.Configuration BMP bmp.Configuration @@ -36,7 +36,7 @@ type InletConfiguration struct { // Reset resets the configuration for the inlet command to its default value. func (c *InletConfiguration) Reset() { *c = InletConfiguration{ - HTTP: http.DefaultConfiguration(), + HTTP: httpserver.DefaultConfiguration(), Reporting: reporter.DefaultConfiguration(), Flow: flow.DefaultConfiguration(), SNMP: snmp.DefaultConfiguration(), @@ -92,7 +92,7 @@ func inletStart(r *reporter.Reporter, config InletConfiguration, checkOnly bool) if err != nil { return fmt.Errorf("unable to initialize daemon component: %w", err) } - httpComponent, err := http.New(r, config.HTTP, http.Dependencies{ + httpComponent, err := httpserver.New(r, config.HTTP, httpserver.Dependencies{ Daemon: daemonComponent, }) if err != nil { diff --git a/cmd/orchestrator.go b/cmd/orchestrator.go index 69a1edae..da5c4769 100644 --- a/cmd/orchestrator.go +++ b/cmd/orchestrator.go @@ -10,7 +10,7 @@ import ( "akvorado/common/clickhousedb" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/orchestrator" @@ -21,7 +21,7 @@ import ( // OrchestratorConfiguration represents the configuration file for the orchestrator command. type OrchestratorConfiguration struct { Reporting reporter.Configuration - HTTP http.Configuration + HTTP httpserver.Configuration ClickHouseDB clickhousedb.Configuration `yaml:"-"` ClickHouse clickhouse.Configuration Kafka kafka.Configuration @@ -41,7 +41,7 @@ func (c *OrchestratorConfiguration) Reset() { consoleConfiguration.Reset() *c = OrchestratorConfiguration{ Reporting: reporter.DefaultConfiguration(), - HTTP: http.DefaultConfiguration(), + HTTP: httpserver.DefaultConfiguration(), ClickHouseDB: clickhousedb.DefaultConfiguration(), ClickHouse: clickhouse.DefaultConfiguration(), Kafka: kafka.DefaultConfiguration(), @@ -110,7 +110,7 @@ func orchestratorStart(r *reporter.Reporter, config OrchestratorConfiguration, c if err != nil { return fmt.Errorf("unable to initialize daemon component: %w", err) } - httpComponent, err := http.New(r, config.HTTP, http.Dependencies{ + httpComponent, err := httpserver.New(r, config.HTTP, httpserver.Dependencies{ Daemon: daemonComponent, }) if err != nil { diff --git a/common/http/cache.go b/common/httpserver/cache.go similarity index 98% rename from common/http/cache.go rename to common/httpserver/cache.go index 863b6ef5..00b9690c 100644 --- a/common/http/cache.go +++ b/common/httpserver/cache.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Free Mobile // SPDX-License-Identifier: AGPL-3.0-only -package http +package httpserver import ( "bytes" diff --git a/common/http/cache_test.go b/common/httpserver/cache_test.go similarity index 88% rename from common/http/cache_test.go rename to common/httpserver/cache_test.go index 710c4bfc..fec423b0 100644 --- a/common/http/cache_test.go +++ b/common/httpserver/cache_test.go @@ -1,17 +1,17 @@ // SPDX-FileCopyrightText: 2022 Free Mobile // SPDX-License-Identifier: AGPL-3.0-only -package http_test +package httpserver_test import ( "context" - netHTTP "net/http" + "net/http" "testing" "time" "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "github.com/gin-gonic/gin" @@ -20,14 +20,14 @@ import ( func TestCacheByRequestPath(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) count := 0 h.GinRouter.GET("/api/v0/test", h.CacheByRequestPath(time.Minute), func(c *gin.Context) { count++ - c.JSON(netHTTP.StatusOK, gin.H{ + c.JSON(http.StatusOK, gin.H{ "message": "ping", "count": count, }) @@ -50,7 +50,7 @@ func TestCacheByRequestPath(t *testing.T) { }, }) - gotMetrics := r.GetMetrics("akvorado_common_http_", "requests_", "cache_") + gotMetrics := r.GetMetrics("akvorado_common_httpserver_", "requests_", "cache_") expectedMetrics := map[string]string{ `cache_hit_total{method="GET",path="/api/v0/test"}`: "2", `cache_miss_total{method="GET",path="/api/v0/test"}`: "1", @@ -63,7 +63,7 @@ func TestCacheByRequestPath(t *testing.T) { func TestCacheByRequestBody(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) count := 0 h.GinRouter.POST("/api/v0/test", @@ -74,7 +74,7 @@ func TestCacheByRequestBody(t *testing.T) { if err != nil { t.Fatalf("GetRawData() error:\n%+v", err) } - c.JSON(netHTTP.StatusOK, gin.H{ + c.JSON(http.StatusOK, gin.H{ "message": "ping", "count": count, "body": string(data), @@ -106,7 +106,7 @@ func TestCacheByRequestBody(t *testing.T) { }, }) - gotMetrics := r.GetMetrics("akvorado_common_http_", "requests_", "cache_") + gotMetrics := r.GetMetrics("akvorado_common_httpserver_", "requests_", "cache_") expectedMetrics := map[string]string{ `cache_hit_total{method="POST",path="/api/v0/test"}`: "2", `cache_miss_total{method="POST",path="/api/v0/test"}`: "2", @@ -131,14 +131,14 @@ func TestRedis(t *testing.T) { r := reporter.NewMock(t) // HTTP with Redis - config := http.DefaultConfiguration() + config := httpserver.DefaultConfiguration() config.Listen = "127.0.0.1:0" - config.Cache.Config = http.RedisCacheConfiguration{ + config.Cache.Config = httpserver.RedisCacheConfiguration{ Protocol: "tcp", Server: server, DB: 10, } - h, err := http.New(r, config, http.Dependencies{Daemon: daemon.NewMock(t)}) + h, err := httpserver.New(r, config, httpserver.Dependencies{Daemon: daemon.NewMock(t)}) if err != nil { t.Fatalf("New() error:\n%+v", err) } @@ -149,7 +149,7 @@ func TestRedis(t *testing.T) { h.CacheByRequestPath(time.Minute), func(c *gin.Context) { count++ - c.JSON(netHTTP.StatusOK, gin.H{ + c.JSON(http.StatusOK, gin.H{ "message": "ping", "count": count, }) diff --git a/common/http/config.go b/common/httpserver/config.go similarity index 99% rename from common/http/config.go rename to common/httpserver/config.go index a2afdcbc..4cc3cfc3 100644 --- a/common/http/config.go +++ b/common/httpserver/config.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Free Mobile // SPDX-License-Identifier: AGPL-3.0-only -package http +package httpserver import ( "context" diff --git a/common/http/config_test.go b/common/httpserver/config_test.go similarity index 94% rename from common/http/config_test.go rename to common/httpserver/config_test.go index 52047c07..7f1e5f36 100644 --- a/common/http/config_test.go +++ b/common/httpserver/config_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Free Mobile // SPDX-License-Identifier: AGPL-3.0-only -package http +package httpserver import ( "testing" diff --git a/common/http/metrics.go b/common/httpserver/metrics.go similarity index 98% rename from common/http/metrics.go rename to common/httpserver/metrics.go index 54771b46..8338d8dc 100644 --- a/common/http/metrics.go +++ b/common/httpserver/metrics.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2022 Free Mobile // SPDX-License-Identifier: AGPL-3.0-only -package http +package httpserver import "akvorado/common/reporter" diff --git a/common/http/root.go b/common/httpserver/root.go similarity index 98% rename from common/http/root.go rename to common/httpserver/root.go index b4b67f50..30b25ec6 100644 --- a/common/http/root.go +++ b/common/httpserver/root.go @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2022 Free Mobile // SPDX-License-Identifier: AGPL-3.0-only -// Package http handles the internal web server for akvorado. -package http +// Package httpserver handles the internal web server for akvorado. +package httpserver import ( "context" diff --git a/common/http/root_test.go b/common/httpserver/root_test.go similarity index 85% rename from common/http/root_test.go rename to common/httpserver/root_test.go index 11f69e69..dca77a15 100644 --- a/common/http/root_test.go +++ b/common/httpserver/root_test.go @@ -1,15 +1,15 @@ // SPDX-FileCopyrightText: 2022 Free Mobile // SPDX-License-Identifier: AGPL-3.0-only -package http_test +package httpserver_test import ( "fmt" - netHTTP "net/http" + "net/http" "testing" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "github.com/gin-gonic/gin" @@ -17,10 +17,10 @@ import ( func TestHandler(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) h.AddHandler("/test", - netHTTP.HandlerFunc(func(w netHTTP.ResponseWriter, r *netHTTP.Request) { + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello !") })) @@ -33,7 +33,8 @@ func TestHandler(t *testing.T) { }, }) - gotMetrics := r.GetMetrics("akvorado_common_http_", "inflight_", "requests_total", "response_size") + gotMetrics := r.GetMetrics("akvorado_common_httpserver_", + "inflight_", "requests_total", "response_size") expectedMetrics := map[string]string{ `inflight_requests`: "0", `requests_total{code="200",handler="/test",method="get"}`: "1", @@ -53,10 +54,10 @@ func TestHandler(t *testing.T) { func TestGinRouter(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) h.GinRouter.GET("/api/v0/test", func(c *gin.Context) { - c.JSON(netHTTP.StatusOK, gin.H{ + c.JSON(http.StatusOK, gin.H{ "message": "ping", }) }) @@ -75,7 +76,7 @@ func TestGinRouter(t *testing.T) { func TestGinRouterPanic(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) h.GinRouter.GET("/api/v0/test", func(c *gin.Context) { panic("heeeelp") diff --git a/common/http/tests.go b/common/httpserver/tests.go similarity index 96% rename from common/http/tests.go rename to common/httpserver/tests.go index e8b8fca2..bc072220 100644 --- a/common/http/tests.go +++ b/common/httpserver/tests.go @@ -3,7 +3,7 @@ //go:build !release -package http +package httpserver import ( "testing" diff --git a/conntrackfixer/root.go b/conntrackfixer/root.go index ea320f9d..cc74e328 100644 --- a/conntrackfixer/root.go +++ b/conntrackfixer/root.go @@ -14,7 +14,7 @@ import ( "time" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "github.com/docker/docker/api/types" @@ -45,7 +45,7 @@ type Component struct { // Dependencies define the dependencies of the broker. type Dependencies struct { - HTTP *http.Component + HTTP *httpserver.Component Daemon daemon.Component } diff --git a/conntrackfixer/root_test.go b/conntrackfixer/root_test.go index 91f1e416..edf180e5 100644 --- a/conntrackfixer/root_test.go +++ b/conntrackfixer/root_test.go @@ -19,14 +19,14 @@ import ( "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/conntrackfixer/mocks" ) func TestRoot(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) c, err := New(r, Dependencies{ HTTP: h, Daemon: daemon.NewMock(t), diff --git a/console/authentication/handlers_test.go b/console/authentication/handlers_test.go index 4a1bb3d6..5721a839 100644 --- a/console/authentication/handlers_test.go +++ b/console/authentication/handlers_test.go @@ -4,11 +4,11 @@ package authentication import ( - netHTTP "net/http" + "net/http" "testing" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "github.com/gin-gonic/gin" @@ -16,7 +16,7 @@ import ( func TestUserHandler(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) c, err := New(r, DefaultConfiguration()) if err != nil { t.Fatalf("New() error:\n%+v", err) @@ -37,8 +37,8 @@ func TestUserHandler(t *testing.T) { }, { Description: "user info, minimal user logged in", URL: "/api/v0/console/user/info", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") return headers }(), @@ -49,8 +49,8 @@ func TestUserHandler(t *testing.T) { }, { Description: "user info, complete user logged in", URL: "/api/v0/console/user/info", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") headers.Add("Remote-Name", "Alfred Pennyworth") headers.Add("Remote-Email", "alfred@batman.com") @@ -67,8 +67,8 @@ func TestUserHandler(t *testing.T) { }, { Description: "user info, invalid user logged in", URL: "/api/v0/console/user/info", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") headers.Add("Remote-Email", "alfrednooo") return headers @@ -83,8 +83,8 @@ func TestUserHandler(t *testing.T) { }, { Description: "avatar, simple user", URL: "/api/v0/console/user/avatar", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") return headers }(), @@ -93,8 +93,8 @@ func TestUserHandler(t *testing.T) { }, { Description: "avatar, simple user, etag", URL: "/api/v0/console/user/avatar", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") headers.Add("If-None-Match", `"b2e72a535032fa89"`) return headers @@ -115,8 +115,8 @@ func TestUserHandler(t *testing.T) { }, { Description: "user info, invalid user logged in", URL: "/api/v0/console/user/info", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") headers.Add("Remote-Email", "alfrednooo") return headers diff --git a/console/docs_test.go b/console/docs_test.go index 5591e71f..a7bd4c60 100644 --- a/console/docs_test.go +++ b/console/docs_test.go @@ -6,7 +6,7 @@ package console import ( "fmt" "io/ioutil" - netHTTP "net/http" + "net/http" "strings" "testing" ) @@ -30,7 +30,7 @@ func TestServeDocs(t *testing.T) { conf.ServeLiveFS = live _, h, _, _ := NewMock(t, conf) - resp, err := netHTTP.Get(fmt.Sprintf("http://%s/api/v0/console/docs/%s", + resp, err := http.Get(fmt.Sprintf("http://%s/api/v0/console/docs/%s", h.LocalAddr(), tc.Path)) if err != nil { t.Fatalf("GET /api/v0/console/docs/%s:\n%+v", tc.Path, err) diff --git a/console/filter_test.go b/console/filter_test.go index 7c1a32b2..6852ff87 100644 --- a/console/filter_test.go +++ b/console/filter_test.go @@ -4,7 +4,7 @@ package console import ( - netHTTP "net/http" + "net/http" "testing" "github.com/gin-gonic/gin" @@ -331,8 +331,8 @@ LIMIT 20`, "6540"). { Description: "list stored filters as another user", URL: "/api/v0/console/filter/saved", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") return headers }(), @@ -342,8 +342,8 @@ LIMIT 20`, "6540"). Description: "delete stored filter as another user", Method: "DELETE", URL: "/api/v0/console/filter/saved/1", - Header: func() netHTTP.Header { - headers := make(netHTTP.Header) + Header: func() http.Header { + headers := make(http.Header) headers.Add("Remote-User", "alfred") return headers }(), diff --git a/console/root.go b/console/root.go index 051211a7..c8c3eb80 100644 --- a/console/root.go +++ b/console/root.go @@ -6,7 +6,7 @@ package console import ( "io/fs" - netHTTP "net/http" + "net/http" "os" "path" "path/filepath" @@ -19,7 +19,7 @@ import ( "akvorado/common/clickhousedb" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/console/authentication" @@ -45,7 +45,7 @@ type Component struct { // Dependencies define the dependencies of the console component. type Dependencies struct { Daemon daemon.Component - HTTP *http.Component + HTTP *httpserver.Component ClickHouseDB *clickhousedb.Component Clock clock.Clock Auth *authentication.Component @@ -83,7 +83,7 @@ func New(r *reporter.Reporter, config Configuration, dependencies Dependencies) func (c *Component) Start() error { c.r.Info().Msg("starting console component") - c.d.HTTP.AddHandler("/", netHTTP.HandlerFunc(c.assetsHandlerFunc)) + c.d.HTTP.AddHandler("/", http.HandlerFunc(c.assetsHandlerFunc)) endpoint := c.d.HTTP.GinRouter.Group("/api/v0/console", c.d.Auth.UserAuthentication()) endpoint.GET("/configuration", c.configHandlerFunc) endpoint.GET("/docs/:name", c.docsHandlerFunc) diff --git a/console/tests.go b/console/tests.go index eb40efad..f0192f64 100644 --- a/console/tests.go +++ b/console/tests.go @@ -14,7 +14,7 @@ import ( "akvorado/common/clickhousedb/mocks" "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/console/authentication" @@ -22,10 +22,10 @@ import ( ) // NewMock instantiantes a new authentication component -func NewMock(t *testing.T, config Configuration) (*Component, *http.Component, *mocks.MockConn, *clock.Mock) { +func NewMock(t *testing.T, config Configuration) (*Component, *httpserver.Component, *mocks.MockConn, *clock.Mock) { t.Helper() r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) ch, mockConn := clickhousedb.NewMock(t, r) mockClock := clock.NewMock() c, err := New(r, config, Dependencies{ diff --git a/inlet/core/enricher_test.go b/inlet/core/enricher_test.go index 501645e1..0f19081a 100644 --- a/inlet/core/enricher_test.go +++ b/inlet/core/enricher_test.go @@ -15,7 +15,7 @@ import ( "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/inlet/bmp" @@ -502,7 +502,7 @@ ClassifyProviderRegex(Interface.Description, "^Transit: ([^ ]+)", "$1")`, flowComponent := flow.NewMock(t, r, flow.DefaultConfiguration()) geoipComponent := geoip.NewMock(t, r) kafkaComponent, kafkaProducer := kafka.NewMock(t, r, kafka.DefaultConfiguration()) - httpComponent := http.NewMock(t, r) + httpComponent := httpserver.NewMock(t, r) bmpComponent, _ := bmp.NewMock(t, r, bmp.DefaultConfiguration()) bmpComponent.PopulateRIB(t) diff --git a/inlet/core/root.go b/inlet/core/root.go index 97c55525..acdef93b 100644 --- a/inlet/core/root.go +++ b/inlet/core/root.go @@ -13,7 +13,7 @@ import ( "akvorado/common/daemon" "akvorado/common/helpers/cache" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/inlet/bmp" @@ -50,7 +50,7 @@ type Dependencies struct { BMP *bmp.Component GeoIP *geoip.Component Kafka *kafka.Component - HTTP *http.Component + HTTP *httpserver.Component Schema *schema.Component } diff --git a/inlet/core/root_test.go b/inlet/core/root_test.go index c44098c3..d1a3fa07 100644 --- a/inlet/core/root_test.go +++ b/inlet/core/root_test.go @@ -12,7 +12,7 @@ import ( "fmt" "io" "net" - netHTTP "net/http" + "net/http" "testing" "time" @@ -21,7 +21,7 @@ import ( "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/inlet/bmp" @@ -40,7 +40,7 @@ func TestCore(t *testing.T) { flowComponent := flow.NewMock(t, r, flow.DefaultConfiguration()) geoipComponent := geoip.NewMock(t, r) kafkaComponent, kafkaProducer := kafka.NewMock(t, r, kafka.DefaultConfiguration()) - httpComponent := http.NewMock(t, r) + httpComponent := httpserver.NewMock(t, r) bmpComponent, _ := bmp.NewMock(t, r, bmp.DefaultConfiguration()) bmpComponent.PopulateRIB(t) @@ -209,7 +209,7 @@ func TestCore(t *testing.T) { t.Run("http flows", func(t *testing.T) { c.httpFlowFlushDelay = 20 * time.Millisecond - resp, err := netHTTP.Get(fmt.Sprintf("http://%s/api/v0/inlet/flows", c.d.HTTP.LocalAddr())) + resp, err := http.Get(fmt.Sprintf("http://%s/api/v0/inlet/flows", c.d.HTTP.LocalAddr())) if err != nil { t.Fatalf("GET /api/v0/inlet/flows:\n%+v", err) } @@ -282,7 +282,7 @@ func TestCore(t *testing.T) { // Test HTTP flow clients with a limit time.Sleep(10 * time.Millisecond) t.Run("http flows with limit", func(t *testing.T) { - resp, err := netHTTP.Get(fmt.Sprintf("http://%s/api/v0/inlet/flows?limit=4", c.d.HTTP.LocalAddr())) + resp, err := http.Get(fmt.Sprintf("http://%s/api/v0/inlet/flows?limit=4", c.d.HTTP.LocalAddr())) if err != nil { t.Fatalf("GET /api/v0/inlet/flows:\n%+v", err) } diff --git a/inlet/flow/root.go b/inlet/flow/root.go index 706069f4..1c0a3d1c 100644 --- a/inlet/flow/root.go +++ b/inlet/flow/root.go @@ -7,13 +7,13 @@ package flow import ( "errors" "fmt" - netHTTP "net/http" + "net/http" "net/netip" "gopkg.in/tomb.v2" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/inlet/flow/decoder" @@ -45,7 +45,7 @@ type Component struct { // Dependencies are the dependencies of the flow component. type Dependencies struct { Daemon daemon.Component - HTTP *http.Component + HTTP *httpserver.Component Schema *schema.Component } @@ -110,7 +110,7 @@ func New(r *reporter.Reporter, configuration Configuration, dependencies Depende c.d.Daemon.Track(&c.t, "inlet/flow") c.d.HTTP.AddHandler("/api/v0/inlet/flow/schema.proto", - netHTTP.HandlerFunc(func(w netHTTP.ResponseWriter, r *netHTTP.Request) { + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain") w.Write([]byte(c.d.Schema.ProtobufDefinition())) })) diff --git a/inlet/flow/tests.go b/inlet/flow/tests.go index c8d85a60..86085b96 100644 --- a/inlet/flow/tests.go +++ b/inlet/flow/tests.go @@ -10,7 +10,7 @@ import ( "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" "akvorado/inlet/flow/input/udp" @@ -33,7 +33,7 @@ func NewMock(t *testing.T, r *reporter.Reporter, config Configuration) *Componen } c, err := New(r, config, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: schema.NewMock(t), }) if err != nil { diff --git a/orchestrator/clickhouse/http_test.go b/orchestrator/clickhouse/http_test.go index f4d8b2e7..49435b61 100644 --- a/orchestrator/clickhouse/http_test.go +++ b/orchestrator/clickhouse/http_test.go @@ -9,7 +9,7 @@ import ( "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" ) @@ -23,7 +23,7 @@ func TestHTTPEndpoints(t *testing.T) { }) c, err := New(r, config, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: schema.NewMock(t), }) if err != nil { @@ -80,7 +80,7 @@ func TestAdditionalASNs(t *testing.T) { } c, err := New(r, config, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: schema.NewMock(t), }) if err != nil { diff --git a/orchestrator/clickhouse/migrations_test.go b/orchestrator/clickhouse/migrations_test.go index 914e37d6..98b4fc5e 100644 --- a/orchestrator/clickhouse/migrations_test.go +++ b/orchestrator/clickhouse/migrations_test.go @@ -20,7 +20,7 @@ import ( "akvorado/common/clickhousedb" "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/kafka" "akvorado/common/reporter" "akvorado/common/schema" @@ -155,7 +155,7 @@ func waitMigrations(t *testing.T, ch *Component) { func TestGetHTTPBaseURL(t *testing.T) { r := reporter.NewMock(t) - http := http.NewMock(t, r) + http := httpserver.NewMock(t, r) c, err := New(r, DefaultConfiguration(), Dependencies{ Daemon: daemon.NewMock(t), HTTP: http, @@ -207,7 +207,7 @@ func TestMigration(t *testing.T) { configuration.Kafka.Configuration = kafka.DefaultConfiguration() ch, err := New(r, configuration, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: schema.NewMock(t), ClickHouse: chComponent, }) @@ -295,7 +295,7 @@ LIMIT 1`) configuration.Kafka.Configuration = kafka.DefaultConfiguration() ch, err := New(r, configuration, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: schema.NewMock(t), ClickHouse: chComponent, }) @@ -331,7 +331,7 @@ LIMIT 1`) configuration.Kafka.Configuration = kafka.DefaultConfiguration() ch, err := New(r, configuration, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: schema.NewMock(t).EnableAllColumns(), ClickHouse: chComponent, }) @@ -372,7 +372,7 @@ LIMIT 1`) configuration.Kafka.Configuration = kafka.DefaultConfiguration() ch, err := New(r, configuration, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: sch, ClickHouse: chComponent, }) @@ -407,7 +407,7 @@ LIMIT 1`) configuration.Kafka.Configuration = kafka.DefaultConfiguration() ch, err := New(r, configuration, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: sch, ClickHouse: chComponent, }) diff --git a/orchestrator/clickhouse/root.go b/orchestrator/clickhouse/root.go index a551812a..d0ca91b0 100644 --- a/orchestrator/clickhouse/root.go +++ b/orchestrator/clickhouse/root.go @@ -16,7 +16,7 @@ import ( "akvorado/common/clickhousedb" "akvorado/common/daemon" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" ) @@ -39,7 +39,7 @@ type Component struct { // Dependencies define the dependencies of the ClickHouse configurator. type Dependencies struct { Daemon daemon.Component - HTTP *http.Component + HTTP *httpserver.Component ClickHouse *clickhousedb.Component Schema *schema.Component } diff --git a/orchestrator/clickhouse/source_test.go b/orchestrator/clickhouse/source_test.go index 944386ba..8306b97c 100644 --- a/orchestrator/clickhouse/source_test.go +++ b/orchestrator/clickhouse/source_test.go @@ -7,13 +7,13 @@ import ( "context" "fmt" "net" - netHTTP "net/http" + "net/http" "testing" "time" "akvorado/common/daemon" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" "akvorado/common/schema" ) @@ -21,8 +21,8 @@ import ( func TestNetworkSources(t *testing.T) { // Mux to answer requests ready := make(chan bool) - mux := netHTTP.NewServeMux() - mux.Handle("/amazon.json", netHTTP.HandlerFunc(func(w netHTTP.ResponseWriter, r *netHTTP.Request) { + mux := http.NewServeMux() + mux.Handle("/amazon.json", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { select { case <-ready: default: @@ -66,7 +66,7 @@ func TestNetworkSources(t *testing.T) { if err != nil { t.Fatalf("Listen() error:\n%+v", err) } - server := &netHTTP.Server{ + server := &http.Server{ Addr: listener.Addr().String(), Handler: mux, } @@ -95,7 +95,7 @@ func TestNetworkSources(t *testing.T) { } c, err := New(r, config, Dependencies{ Daemon: daemon.NewMock(t), - HTTP: http.NewMock(t, r), + HTTP: httpserver.NewMock(t, r), Schema: schema.NewMock(t), }) if err != nil { diff --git a/orchestrator/http_test.go b/orchestrator/http_test.go index af1b22fd..afdb09e8 100644 --- a/orchestrator/http_test.go +++ b/orchestrator/http_test.go @@ -7,13 +7,13 @@ import ( "testing" "akvorado/common/helpers" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" ) func TestConfigurationEndpoint(t *testing.T) { r := reporter.NewMock(t) - h := http.NewMock(t, r) + h := httpserver.NewMock(t, r) c, err := New(r, DefaultConfiguration(), Dependencies{ HTTP: h, }) diff --git a/orchestrator/root.go b/orchestrator/root.go index 892aebf7..90dd67aa 100644 --- a/orchestrator/root.go +++ b/orchestrator/root.go @@ -7,7 +7,7 @@ package orchestrator import ( "sync" - "akvorado/common/http" + "akvorado/common/httpserver" "akvorado/common/reporter" ) @@ -23,7 +23,7 @@ type Component struct { // Dependencies define the dependencies of the broker. type Dependencies struct { - HTTP *http.Component + HTTP *httpserver.Component } // ServiceType describes the different internal services