Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions test/docker/devconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDevGoldenPath(t *testing.T) {
"MQ_QMGR_NAME=qm1",
},
}
id := runContainer(t, cli, &containerConfig)
id := runContainerWithPorts(t, cli, &containerConfig, []int{9443})
defer cleanContainer(t, cli, id)
waitForReady(t, cli, id)
waitForWebReady(t, cli, id, insecureTLSConfig)
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestDevConfigDisabled(t *testing.T) {
"MQ_DEV=false",
},
}
id := runContainer(t, cli, &containerConfig)
id := runContainerWithPorts(t, cli, &containerConfig, []int{9443})
defer cleanContainer(t, cli, id)
waitForReady(t, cli, id)
waitForWebReady(t, cli, id, insecureTLSConfig)
Expand Down
29 changes: 18 additions & 11 deletions test/docker/docker_api_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ func cleanContainer(t *testing.T, cli *client.Client, ID string) {
}
}

// runContainer creates and starts a container. If no image is specified in
// the container config, then the image name is retrieved from the TEST_IMAGE
// runContainerWithPorts creates and starts a container, exposing the specified ports on the host.
// If no image is specified in the container config, then the image name is retrieved from the TEST_IMAGE
// environment variable.
func runContainer(t *testing.T, cli *client.Client, containerConfig *container.Config) string {
func runContainerWithPorts(t *testing.T, cli *client.Client, containerConfig *container.Config, ports []int) string {
if containerConfig.Image == "" {
containerConfig.Image = imageName()
}
Expand All @@ -228,15 +228,15 @@ func runContainer(t *testing.T, cli *client.Client, containerConfig *container.C
coverageBind(t),
terminationBind(t),
},
// Assign a random port for the web server on the host
// TODO: Don't do this for all tests
PortBindings: nat.PortMap{
"9443/tcp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
},
PortBindings: nat.PortMap{},
}
for _, p := range ports {
port := nat.Port(fmt.Sprintf("%v/tcp", p))
hostConfig.PortBindings[port] = []nat.PortBinding{
{
HostIP: "0.0.0.0",
},
},
}
}
networkingConfig := network.NetworkingConfig{}
t.Logf("Running container (%s)", containerConfig.Image)
Expand All @@ -248,6 +248,13 @@ func runContainer(t *testing.T, cli *client.Client, containerConfig *container.C
return ctr.ID
}

// runContainer creates and starts a container. If no image is specified in
// the container config, then the image name is retrieved from the TEST_IMAGE
// environment variable.
func runContainer(t *testing.T, cli *client.Client, containerConfig *container.Config) string {
return runContainerWithPorts(t, cli, containerConfig, nil)
}

func runContainerOneShot(t *testing.T, cli *client.Client, command ...string) (int64, string) {
containerConfig := container.Config{
Entrypoint: command,
Expand Down
187 changes: 31 additions & 156 deletions test/docker/mqmetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"testing"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
)

Expand All @@ -30,85 +29,40 @@ func TestGoldenPathMetric(t *testing.T) {
if err != nil {
t.Fatal(err)
}

containerConfig := container.Config{
Env: []string{
"LICENSE=accept",
"MQ_QMGR_NAME=qm1",
"MQ_ENABLE_METRICS=true",
},
}
id := runContainer(t, cli, &containerConfig)
id := runContainerWithPorts(t, cli, metricsContainerConfig(), []int{defaultMetricPort})
defer cleanContainer(t, cli, id)

hostname := getIPAddress(t, cli, id)
port := defaultMetricPort

// hostname := getIPAddress(t, cli, id)
port := getMetricPort(t, cli, id)
// Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port)

waitForMetricReady(t, port)
// Call once as mq_prometheus 'ignores' the first call and will not return any metrics
_, err = getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

getMetrics(t, port)
time.Sleep(15 * time.Second)
metrics, err := getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

metrics := getMetrics(t, port)
if len(metrics) <= 0 {
t.Log("Expected some metrics to be returned but had none...")
t.Fail()
}

// Stop the container cleanly
stopContainer(t, cli, id)
}

func TestMetricNames(t *testing.T) {
t.Parallel()

approvedSuffixes := []string{"bytes", "seconds", "percentage", "count", "total"}
cli, err := client.NewEnvClient()
if err != nil {
t.Fatal(err)
}

containerConfig := container.Config{
Env: []string{
"LICENSE=accept",
"MQ_QMGR_NAME=qm1",
"MQ_ENABLE_METRICS=true",
},
}
id := runContainer(t, cli, &containerConfig)
id := runContainerWithPorts(t, cli, metricsContainerConfig(), []int{defaultMetricPort})
defer cleanContainer(t, cli, id)

hostname := getIPAddress(t, cli, id)
port := defaultMetricPort

port := getMetricPort(t, cli, id)
// Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port)

waitForMetricReady(t, port)
// Call once as mq_prometheus 'ignores' the first call
_, err = getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

getMetrics(t, port)
time.Sleep(15 * time.Second)
metrics, err := getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

metrics := getMetrics(t, port)
if len(metrics) <= 0 {
t.Log("Expected some metrics to be returned but had none...")
t.Fail()
Expand Down Expand Up @@ -141,46 +95,22 @@ func TestMetricNames(t *testing.T) {

func TestMetricLabels(t *testing.T) {
t.Parallel()

requiredLabels := []string{"qmgr"}
cli, err := client.NewEnvClient()
if err != nil {
t.Fatal(err)
}

containerConfig := container.Config{
Env: []string{
"LICENSE=accept",
"MQ_QMGR_NAME=qm1",
"MQ_ENABLE_METRICS=true",
},
}
id := runContainer(t, cli, &containerConfig)
id := runContainerWithPorts(t, cli, metricsContainerConfig(), []int{defaultMetricPort})
defer cleanContainer(t, cli, id)

hostname := getIPAddress(t, cli, id)
port := defaultMetricPort

port := getMetricPort(t, cli, id)
// Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port)

waitForMetricReady(t, port)
// Call once as mq_prometheus 'ignores' the first call
_, err = getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

getMetrics(t, port)
time.Sleep(15 * time.Second)
metrics, err := getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

metrics := getMetrics(t, port)
if len(metrics) <= 0 {
t.Log("Expected some metrics to be returned but had none...")
t.Fail()
t.Error("Expected some metrics to be returned but had none")
}

for _, metric := range metrics {
Expand All @@ -198,118 +128,63 @@ func TestMetricLabels(t *testing.T) {
}

if !found {
t.Logf("Metric '%s' with labels %s does not have one or more required labels - %s", metric.Key, metric.Labels, requiredLabels)
t.Fail()
t.Errorf("Metric '%s' with labels %s does not have one or more required labels - %s", metric.Key, metric.Labels, requiredLabels)
}
}

// Stop the container cleanly
stopContainer(t, cli, id)
}

func TestRapidFirePrometheus(t *testing.T) {
t.Parallel()

cli, err := client.NewEnvClient()
if err != nil {
t.Fatal(err)
}

containerConfig := container.Config{
Env: []string{
"LICENSE=accept",
"MQ_QMGR_NAME=qm1",
"MQ_ENABLE_METRICS=true",
},
}
id := runContainer(t, cli, &containerConfig)
id := runContainerWithPorts(t, cli, metricsContainerConfig(), []int{defaultMetricPort})
defer cleanContainer(t, cli, id)

hostname := getIPAddress(t, cli, id)
port := defaultMetricPort

port := getMetricPort(t, cli, id)
// Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port)

waitForMetricReady(t, port)
// Call once as mq_prometheus 'ignores' the first call and will not return any metrics
_, err = getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

getMetrics(t, port)
// Rapid fire it then check we're still happy
for i := 0; i < 30; i++ {
_, err := getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}
getMetrics(t, port)
time.Sleep(1 * time.Second)
}

time.Sleep(11 * time.Second)

metrics, err := getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}
metrics := getMetrics(t, port)
if len(metrics) <= 0 {
t.Log("Expected some metrics to be returned but had none...")
t.Fail()
t.Error("Expected some metrics to be returned but had none")
}

// Stop the container cleanly
stopContainer(t, cli, id)
}

func TestSlowPrometheus(t *testing.T) {
t.Parallel()

cli, err := client.NewEnvClient()
if err != nil {
t.Fatal(err)
}

containerConfig := container.Config{
Env: []string{
"LICENSE=accept",
"MQ_QMGR_NAME=qm1",
"MQ_ENABLE_METRICS=true",
},
}
id := runContainer(t, cli, &containerConfig)
id := runContainerWithPorts(t, cli, metricsContainerConfig(), []int{defaultMetricPort})
defer cleanContainer(t, cli, id)

hostname := getIPAddress(t, cli, id)
port := defaultMetricPort

port := getMetricPort(t, cli, id)
// Now the container is ready we prod the prometheus endpoint until it's up.
waitForMetricReady(hostname, port)

waitForMetricReady(t, port)
// Call once as mq_prometheus 'ignores' the first call and will not return any metrics
_, err = getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}

getMetrics(t, port)
// Send a request twice over a long period and check we're still happy
for i := 0; i < 2; i++ {
time.Sleep(30 * time.Second)
metrics, err := getMetricsFromEndpoint(hostname, port)
if err != nil {
t.Logf("Failed to call metric endpoint - %v", err)
t.FailNow()
}
metrics := getMetrics(t, port)
if len(metrics) <= 0 {
t.Log("Expected some metrics to be returned but had none...")
t.Log("Expected some metrics to be returned but had none")
t.Fail()
}

}

// Stop the container cleanly
stopContainer(t, cli, id)
}
Loading