why my integration test trying to connect 172.19.0.2:6565 address and why connection refused

121 views Asked by At

Hello i'm trying to build an integration test for my project and it's been difficult. I'm trying to do it with using docker. Here is my docker-compose.yml and Dockerfile.

version: '2.3'

services:
  k6module:
    build: ./_meta
    ports:
      - 6565
    

FROM grafana/k6:latest


COPY ./script.js /home
EXPOSE 6565
CMD ["run", "/home/script.js"]
ENV K6_BROWSER_ENABLED=true

HEALTHCHECK --interval=1s --retries=90 CMD wget --spider --server-response http://localhost:6565 || exit 1

in my code i'm trying to collect metrics by using restAPI. When code blocks are like this and i runmy integration test i get that problem: Expected 0 error, had 1. [error in http fetch: error making http request: Get "http://172.19.0.2:6565/v1/metrics": dial tcp 172.19.0.2:6565: connect: connection refused]

Here is my integration-test:

package k6metricset

import (
    "testing"

    "github.com/elastic/beats/v7/libbeat/tests/compose"
    mbtest "github.com/elastic/beats/v7/metricbeat/mb/testing"
    "github.com/stretchr/testify/assert"
)

func TestFetch(t *testing.T) {
    service := compose.EnsureUp(t, "k6module")

    f := mbtest.NewReportingMetricSetV2Error(t, getConfig(service.Host()))
    events, errs := mbtest.ReportingFetchV2Error(f)
    if len(errs) > 0 {
        t.Fatalf("Expected 0 error, had %d. %v\n", len(errs), errs)
    }
    assert.NotEmpty(t, events)

    t.Logf("%s/%s event: %+v", f.Module().Name(), f.Name(), events[0])
}

func TestData(t *testing.T) {
    service := compose.EnsureUp(t, "k6module")

    f := mbtest.NewReportingMetricSetV2Error(t, getConfig(service.Host()))
    if err := mbtest.WriteEventsReporterV2Error(f, t, ""); err != nil {
        t.Fatal("write", err)
    }
}

func getConfig(host string) map[string]interface{} {
    return map[string]interface{}{
        "module":     "k6module",
        "metricsets": []string{"k6metricset"},
        "hosts":      []string{host},
    }
}

First of all i don't understand why the 172.19.0.2:6565 address? How can i change this address. It shouldn't try to connect that address. And i can't see the metrics via curl or wget. When i change the docker-compose.yml file to this:

version: '2.3'

services:
  k6module:
    build: ./_meta
    network_mode: "host"

i can see metrics in localhost:6565 address. But my integration-test fails again. And the error is; getting host for k6module: unknown host:port for service.

Please i'm trying to solve this problem for like 2 weeks and i couldn't do it.

I tried to look my container's logs or using inspect command. K6 is running it's okay but the integration test fails everytime.

0

There are 0 answers