From 155757dd74dcee96874bb59936337f8f95e709b6 Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Mon, 12 Dec 2022 09:14:29 -0800 Subject: [PATCH] Removes tail size (#1981) * Removes tail size * Removes tail from analytics --- README.md | 2 -- analytics/types.go | 1 - docker/client.go | 6 +++--- docker/client_test.go | 6 +++--- main.go | 3 --- web/logs.go | 2 +- web/routes.go | 1 - web/routes_test.go | 32 ++++++++++++++++---------------- 8 files changed, 23 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 5f3c824d..cceea572 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,6 @@ Dozzle follows the [12-factor](https://12factor.net/) model. Configurations can | `--addr` | `DOZZLE_ADDR` | `:8080` | | `--base` | `DOZZLE_BASE` | `/` | | `--level` | `DOZZLE_LEVEL` | `info` | -| n/a | `DOCKER_API_VERSION` | not set | -| `--tailSize` | `DOZZLE_TAILSIZE` | `300` | | `--filter` | `DOZZLE_FILTER` | `""` | | `--username` | `DOZZLE_USERNAME` | `""` | | `--password` | `DOZZLE_PASSWORD` | `""` | diff --git a/analytics/types.go b/analytics/types.go index cc0eae82..ca16627c 100644 --- a/analytics/types.go +++ b/analytics/types.go @@ -6,6 +6,5 @@ type StartEvent struct { FilterLength int `json:"filterLength"` CustomAddress bool `json:"customAddress"` CustomBase bool `json:"customBase"` - TailSize int `json:"tailSize"` Protected bool `json:"protected"` } diff --git a/docker/client.go b/docker/client.go index 4216b97a..ae326e6d 100644 --- a/docker/client.go +++ b/docker/client.go @@ -35,7 +35,7 @@ type dockerProxy interface { type Client interface { ListContainers() ([]Container, error) FindContainer(string) (Container, error) - ContainerLogs(context.Context, string, int, string) (io.ReadCloser, error) + ContainerLogs(context.Context, string, string) (io.ReadCloser, error) Events(context.Context) (<-chan ContainerEvent, <-chan error) ContainerLogsBetweenDates(context.Context, string, time.Time, time.Time) (io.ReadCloser, error) ContainerStats(context.Context, string, chan<- ContainerStat) error @@ -169,7 +169,7 @@ func (d *dockerClient) ContainerStats(ctx context.Context, id string, stats chan return nil } -func (d *dockerClient) ContainerLogs(ctx context.Context, id string, tailSize int, since string) (io.ReadCloser, error) { +func (d *dockerClient) ContainerLogs(ctx context.Context, id string, since string) (io.ReadCloser, error) { log.WithField("id", id).WithField("since", since).Debug("streaming logs for container") if since != "" { @@ -184,7 +184,7 @@ func (d *dockerClient) ContainerLogs(ctx context.Context, id string, tailSize in ShowStdout: true, ShowStderr: true, Follow: true, - Tail: strconv.Itoa(tailSize), + Tail: "300", Timestamps: true, Since: since, } diff --git a/docker/client_test.go b/docker/client_test.go index 4833dee2..7041a53e 100644 --- a/docker/client_test.go +++ b/docker/client_test.go @@ -133,7 +133,7 @@ func Test_dockerClient_ContainerLogs_happy(t *testing.T) { proxy.On("ContainerInspect", mock.Anything, id).Return(json, nil) client := &dockerClient{proxy, filters.NewArgs()} - logReader, _ := client.ContainerLogs(context.Background(), id, 300, "since") + logReader, _ := client.ContainerLogs(context.Background(), id, "since") actual, _ := ioutil.ReadAll(logReader) assert.Equal(t, expected, string(actual), "message doesn't match expected") @@ -154,7 +154,7 @@ func Test_dockerClient_ContainerLogs_happy_with_tty(t *testing.T) { proxy.On("ContainerInspect", mock.Anything, id).Return(json, nil) client := &dockerClient{proxy, filters.NewArgs()} - logReader, _ := client.ContainerLogs(context.Background(), id, 300, "") + logReader, _ := client.ContainerLogs(context.Background(), id, "") actual, _ := ioutil.ReadAll(logReader) assert.Equal(t, expected, string(actual), "message doesn't match expected") @@ -170,7 +170,7 @@ func Test_dockerClient_ContainerLogs_error(t *testing.T) { client := &dockerClient{proxy, filters.NewArgs()} - reader, err := client.ContainerLogs(context.Background(), id, 300, "") + reader, err := client.ContainerLogs(context.Background(), id, "") assert.Nil(t, reader, "reader should be nil") assert.Error(t, err, "error should have been returned") diff --git a/main.go b/main.go index 2860a466..5a86f144 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,6 @@ type args struct { Addr string `arg:"env:DOZZLE_ADDR" default:":8080" help:"sets host:port to bind for server. This is rarely needed inside a docker container."` Base string `arg:"env:DOZZLE_BASE" default:"/" help:"sets the base for http router."` Level string `arg:"env:DOZZLE_LEVEL" default:"info" help:"set Dozzle log level. Use debug for more logging."` - TailSize int `arg:"env:DOZZLE_TAILSIZE" default:"300" help:"update the initial tail size when fetching logs."` Username string `arg:"env:DOZZLE_USERNAME" help:"sets the username for auth."` Password string `arg:"env:DOZZLE_PASSWORD" help:"sets password for auth"` UsernameFile *DockerSecret `arg:"env:DOZZLE_USERNAME_FILE" help:"sets the secret path read username for auth."` @@ -123,7 +122,6 @@ func main() { Addr: args.Addr, Base: args.Base, Version: version, - TailSize: args.TailSize, Username: args.Username, Password: args.Password, } @@ -175,7 +173,6 @@ func doStartEvent(arg args) { FilterLength: len(arg.Filter), CustomAddress: arg.Addr != ":8080", CustomBase: arg.Base != "/", - TailSize: arg.TailSize, Protected: arg.Username != "", } diff --git a/web/logs.go b/web/logs.go index 87cb5862..22407af4 100644 --- a/web/logs.go +++ b/web/logs.go @@ -137,7 +137,7 @@ func (h *handler) streamLogs(w http.ResponseWriter, r *http.Request) { lastEventId = r.URL.Query().Get("lastEventId") } - reader, err := h.client.ContainerLogs(r.Context(), container.ID, h.config.TailSize, lastEventId) + reader, err := h.client.ContainerLogs(r.Context(), container.ID, lastEventId) if err != nil { if err == io.EOF { fmt.Fprintf(w, "event: container-stopped\ndata: end of stream\n\n") diff --git a/web/routes.go b/web/routes.go index 4c2d94ee..aa73d0b8 100644 --- a/web/routes.go +++ b/web/routes.go @@ -19,7 +19,6 @@ type Config struct { Base string Addr string Version string - TailSize int Username string Password string } diff --git a/web/routes_test.go b/web/routes_test.go index 5646497c..c9308a6b 100644 --- a/web/routes_test.go +++ b/web/routes_test.go @@ -41,8 +41,8 @@ func (m *MockedClient) ListContainers() ([]docker.Container, error) { return args.Get(0).([]docker.Container), args.Error(1) } -func (m *MockedClient) ContainerLogs(ctx context.Context, id string, tailSize int, since string) (io.ReadCloser, error) { - args := m.Called(ctx, id, tailSize) +func (m *MockedClient) ContainerLogs(ctx context.Context, id string, since string) (io.ReadCloser, error) { + args := m.Called(ctx, id, since) return args.Get(0).(io.ReadCloser), args.Error(1) } @@ -75,9 +75,9 @@ func Test_handler_streamLogs_happy(t *testing.T) { mockedClient := new(MockedClient) reader := ioutil.NopCloser(strings.NewReader("INFO Testing logs...")) mockedClient.On("FindContainer", id).Return(docker.Container{ID: id}, nil) - mockedClient.On("ContainerLogs", mock.Anything, mock.Anything, 300).Return(reader, nil) + mockedClient.On("ContainerLogs", mock.Anything, mock.Anything, "").Return(reader, nil) - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamLogs) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -96,9 +96,9 @@ func Test_handler_streamLogs_happy_with_id(t *testing.T) { mockedClient := new(MockedClient) reader := ioutil.NopCloser(strings.NewReader("2020-05-13T18:55:37.772853839Z INFO Testing logs...")) mockedClient.On("FindContainer", id).Return(docker.Container{ID: id}, nil) - mockedClient.On("ContainerLogs", mock.Anything, mock.Anything, 300).Return(reader, nil) + mockedClient.On("ContainerLogs", mock.Anything, mock.Anything, "").Return(reader, nil) - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamLogs) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -116,9 +116,9 @@ func Test_handler_streamLogs_happy_container_stopped(t *testing.T) { mockedClient := new(MockedClient) mockedClient.On("FindContainer", id).Return(docker.Container{ID: id}, nil) - mockedClient.On("ContainerLogs", mock.Anything, id, 300).Return(ioutil.NopCloser(strings.NewReader("")), io.EOF) + mockedClient.On("ContainerLogs", mock.Anything, id, "").Return(ioutil.NopCloser(strings.NewReader("")), io.EOF) - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamLogs) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -137,7 +137,7 @@ func Test_handler_streamLogs_error_finding_container(t *testing.T) { mockedClient := new(MockedClient) mockedClient.On("FindContainer", id).Return(docker.Container{}, errors.New("error finding container")) - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamLogs) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -155,9 +155,9 @@ func Test_handler_streamLogs_error_reading(t *testing.T) { mockedClient := new(MockedClient) mockedClient.On("FindContainer", id).Return(docker.Container{ID: id}, nil) - mockedClient.On("ContainerLogs", mock.Anything, id, 300).Return(ioutil.NopCloser(strings.NewReader("")), errors.New("test error")) + mockedClient.On("ContainerLogs", mock.Anything, id, "").Return(ioutil.NopCloser(strings.NewReader("")), errors.New("test error")) - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamLogs) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -186,7 +186,7 @@ func Test_handler_streamEvents_happy(t *testing.T) { close(messages) }() - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamEvents) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -208,7 +208,7 @@ func Test_handler_streamEvents_error(t *testing.T) { close(messages) }() - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamEvents) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -234,7 +234,7 @@ func Test_handler_streamEvents_error_request(t *testing.T) { cancel() }() - h := handler{client: mockedClient, config: &Config{TailSize: 300}} + h := handler{client: mockedClient, config: &Config{}} handler := http.HandlerFunc(h.streamEvents) rr := httptest.NewRecorder() handler.ServeHTTP(rr, req) @@ -397,7 +397,7 @@ func Test_createRoutes_username_password_login_failed(t *testing.T) { func Test_createRoutes_username_password_valid_session(t *testing.T) { mockedClient := new(MockedClient) mockedClient.On("FindContainer", "123").Return(docker.Container{ID: "123"}, nil) - mockedClient.On("ContainerLogs", mock.Anything, "123", 0).Return(ioutil.NopCloser(strings.NewReader("test data")), io.EOF) + mockedClient.On("ContainerLogs", mock.Anything, "123", "").Return(ioutil.NopCloser(strings.NewReader("test data")), io.EOF) handler := createHandler(mockedClient, nil, Config{Base: "/", Username: "amir", Password: "password"}) // Get cookie first @@ -421,7 +421,7 @@ func Test_createRoutes_username_password_valid_session(t *testing.T) { func Test_createRoutes_username_password_invalid_session(t *testing.T) { mockedClient := new(MockedClient) mockedClient.On("FindContainer", "123").Return(docker.Container{ID: "123"}, nil) - mockedClient.On("ContainerLogs", mock.Anything, "123", 0).Return(ioutil.NopCloser(strings.NewReader("test data")), io.EOF) + mockedClient.On("ContainerLogs", mock.Anything, "since").Return(ioutil.NopCloser(strings.NewReader("test data")), io.EOF) handler := createHandler(mockedClient, nil, Config{Base: "/", Username: "amir", Password: "password"}) req, err := http.NewRequest("GET", "/api/logs/stream?id=123", nil) require.NoError(t, err, "NewRequest should not return an error.")