Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding JMX support to e2e tests #1248

Merged
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
5 changes: 5 additions & 0 deletions components/datadog/agent/docker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"fmt"
"strings"

"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
Expand Down Expand Up @@ -127,4 +128,8 @@ func defaultAgentParams(params *dockeragentparams.Params) {
params.ImageTag = defaultAgentImageTag
}
params.FullImagePath = utils.BuildDockerImagePath(params.Repository, params.ImageTag)

if params.JMX {
params.FullImagePath = fmt.Sprintf("%s-jmx", params.FullImagePath)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
version: "3.9"

services:

jmx-test-app:
labels:
com.datadoghq.ad.checks: |
{
"test": {
"init_config": {
"is_jmx": true,
"collect_default_metrics": true,
"new_gc_metrics": true,
"conf": [
{
"include": {
"domain": "dd.test.sample",
"type": "simple",
"attribute": {
"ShouldBe100": {
"metric_type": "gauge",
"alias": "test.e2e.jmxfetch.gauge_100"
},
"ShouldBe200": {
"metric_type": "gauge",
"alias": "test.e2e.jmxfetch.gauge_200"
},
"IncrementCounter": {
"metric_type": "counter",
"alias": "test.e2e.jmxfetch.increment_counter"
},
"ShouldBeCounter": {
"metric_type": "counter",
"alias": "test.e2e.jmxfetch.basic_counter"
},
"SpecialCounter": {
"metric_type": "counter",
"alias": "test.e2e.jmxfetch.special_counter"
}
}
}
}
]
},
"instances": [
{
"host": "%%host%%",
"port": "9010"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
version: "3.9"

services:

jmx-test-app:
labels:
com.datadoghq.ad.checks: |
{
"test": {
"init_config": {
"is_jmx": true,
"collect_default_metrics": true,
"new_gc_metrics": true,
"conf": [
{
"include": {
"domain": "dd.test.sample",
"type": "simple",
"attribute": {
"ShouldBe100": {
"metric_type": "gauge",
"alias": "test.e2e.jmxfetch.gauge_100"
},
"ShouldBe200": {
"metric_type": "gauge",
"alias": "test.e2e.jmxfetch.gauge_200"
},
"IncrementCounter": {
"metric_type": "counter",
"alias": "test.e2e.jmxfetch.increment_counter"
},
"ShouldBeSlowCounter": {
"metric_type": "counter",
"alias": "test.e2e.jmxfetch.basic_counter"
},
"SpecialCounter": {
"metric_type": "counter",
"alias": "test.e2e.jmxfetch.special_counter"
}
}
}
}
]
},
"instances": [
{
"host": "%%host%%",
"port": "9010"
}
]
}
}
18 changes: 17 additions & 1 deletion components/datadog/apps/jmxfetch/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,23 @@ import (
//go:embed docker-compose.yaml
var dockerComposeContent string

//go:embed docker-compose-all-metrics.yaml
var dockerComposeAllMetricsContent string

//go:embed docker-compose-slow-metrics.yaml
var dockerComposeSlowMetricsContent string

var DockerComposeManifest = docker.ComposeInlineManifest{
Name: "jmxfetch-test",
Name: "jmx-test-app",
Content: pulumi.String(dockerComposeContent),
}

var DockerComposeAllMetricsManifest = docker.ComposeInlineManifest{
Name: "jmx-test-all-metrics",
Content: pulumi.String(dockerComposeAllMetricsContent),
}

var DockerComposeSlowMetricsManifest = docker.ComposeInlineManifest{
Name: "jmx-test-slow-metrics",
Content: pulumi.String(dockerComposeSlowMetricsContent),
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
import java.io.IOException;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.net.InetSocketAddress;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.TimeUnit;
import java.util.Hashtable;
import java.util.Random;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

import javax.management.InstanceAlreadyExistsException;
import javax.management.MalformedObjectNameException;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.net.InetSocketAddress;
import java.util.Hashtable;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

class SimpleApp {
public interface SampleMBean {

Integer getShouldBe100();

Double getShouldBe1000();
Double getShouldBe200();

Long getShouldBe1337();

Float getShouldBe1_1();

int getShouldBeCounter();

int getShouldBeSlowCounter();

int incrementAndGet();

int getSpecialCounter();

int incrementSpecialCounter();

int getIncrementCounter();
}

public static class Sample implements SampleMBean {

private final AtomicInteger counter = new AtomicInteger(0);
private final AtomicInteger incrementCounter = new AtomicInteger(0);
private final AtomicInteger specialCounter = new AtomicInteger(0);
private final Random random = new Random();

Expand All @@ -50,7 +54,7 @@ public Integer getShouldBe100() {
}

@Override
public Double getShouldBe1000() {
public Double getShouldBe200() {
return 200.0;
}

Expand All @@ -66,6 +70,11 @@ public Float getShouldBe1_1() {

@Override
public int getShouldBeCounter() {
return this.counter.get();
}

@Override
public int getShouldBeSlowCounter() {
try {
final int seconds = this.random.nextInt(15) + 20;
Thread.sleep(seconds * 1000);
Expand All @@ -81,17 +90,22 @@ public int incrementAndGet() {
}

@Override
public int getSpecialCounter(){
public int getSpecialCounter() {
return this.specialCounter.get();
}

@Override
public int incrementSpecialCounter(){
public int incrementSpecialCounter() {
return this.specialCounter.incrementAndGet();
}

@Override
public int getIncrementCounter() {
return this.incrementCounter.incrementAndGet();
}
}

public static void main(String[] args) throws Exception{
public static void main(String[] args) throws Exception {
System.out.println("Starting sample app...");
try {
final Hashtable<String, String> pairs = new Hashtable<>();
Expand All @@ -113,7 +127,7 @@ public static void main(String[] args) throws Exception{

private static class IncHandler implements HttpHandler {
private final SampleMBean sample;

public IncHandler(final SampleMBean sample) {
this.sample = sample;
}
Expand All @@ -128,10 +142,10 @@ public void handle(HttpExchange t) throws IOException {
os.close();
}
}

private static class TestHandler implements HttpHandler {
private final SampleMBean sample;

public TestHandler(final SampleMBean sample) {
this.sample = sample;
}
Expand Down
25 changes: 20 additions & 5 deletions components/datadog/dockeragentparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Params struct {
ImageTag string
// Repository is the docker repository to use.
Repository string
// JMX is true if the JMX image is needed
JMX bool
// AgentServiceEnvironment is a map of environment variables to set in the docker compose agent service's environment.
AgentServiceEnvironment pulumi.Map
// ExtraComposeManifests is a list of extra docker compose manifests to add beside the agent service.
Expand Down Expand Up @@ -85,6 +87,14 @@ func WithRepository(repository string) func(*Params) error {
}
}

// WithJMX makes the image be the one with Java installed
func WithJMX() func(*Params) error {
return func(p *Params) error {
p.JMX = true
return nil
}
}

func WithFullImagePath(fullImagePath string) func(*Params) error {
return func(p *Params) error {
p.FullImagePath = fullImagePath
Expand Down Expand Up @@ -213,13 +223,18 @@ func WithLogs() func(*Params) error {
return WithAgentServiceEnvVariable("DD_LOGS_ENABLED", pulumi.String("true"))
}

// WithExtraComposeContent adds a cpm
// WithExtraComposeManifest adds a docker.ComposeInlineManifest
func WithExtraComposeManifest(name string, content pulumi.StringInput) func(*Params) error {
return WithExtraComposeInlineManifest(docker.ComposeInlineManifest{
Name: name,
Content: content,
})
}

// WithExtraComposeInlineManifest adds extra docker.ComposeInlineManifest
func WithExtraComposeInlineManifest(cpms ...docker.ComposeInlineManifest) func(*Params) error {
return func(p *Params) error {
p.ExtraComposeManifests = append(p.ExtraComposeManifests, docker.ComposeInlineManifest{
Name: name,
Content: content,
})
p.ExtraComposeManifests = append(p.ExtraComposeManifests, cpms...)
return nil
}
}
Loading