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.
This commit is contained in:
Vincent Bernat
2023-05-28 09:08:07 +02:00
parent 1c56fd1505
commit 62521e629d
32 changed files with 121 additions and 120 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package http
package httpserver
import (
"bytes"

View File

@@ -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,
})

View File

@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package http
package httpserver
import (
"context"

View File

@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package http
package httpserver
import (
"testing"

View File

@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
package http
package httpserver
import "akvorado/common/reporter"

View File

@@ -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"

View File

@@ -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")

View File

@@ -3,7 +3,7 @@
//go:build !release
package http
package httpserver
import (
"testing"

View File

@@ -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
}

View File

@@ -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),

View File

@@ -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

View File

@@ -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)

View File

@@ -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
}(),

View File

@@ -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)

View File

@@ -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{

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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()))
}))

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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,
})

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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,
})

View File

@@ -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