Skip to content

Commit 7df489c

Browse files
authored
add datadog it support (#37517)
* add datadog it support * add used undeclared artifacts * address check style issues * add jar * address gemini comments * remove unused helper * spotless * fix imports
1 parent 195cc59 commit 7df489c

15 files changed

Lines changed: 1184 additions & 0 deletions

it/datadog/build.gradle

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
plugins { id 'org.apache.beam.module' }
20+
applyJavaNature(
21+
automaticModuleName: 'org.apache.beam.it.datadog',
22+
)
23+
24+
description = "Apache Beam :: IT :: Datadog"
25+
ext.summary = "Integration test utilities for Datadog."
26+
27+
dependencies {
28+
implementation project(path: ":it:common")
29+
implementation project(path: ":it:testcontainers")
30+
implementation project(path: ":it:truthmatchers")
31+
implementation project(path: ":it:conditions")
32+
implementation "org.testcontainers:mockserver:1.19.7"
33+
implementation "org.testcontainers:testcontainers:1.19.7"
34+
implementation "org.mock-server:mockserver-client-java:5.10.0"
35+
implementation "org.mock-server:mockserver-core:5.10.0"
36+
37+
implementation "org.apache.httpcomponents:httpclient:4.5.13"
38+
implementation "org.apache.httpcomponents:httpcore:4.4.14"
39+
implementation library.java.google_code_gson
40+
41+
implementation library.java.vendored_guava_32_1_2_jre
42+
implementation "org.slf4j:slf4j-api:2.0.16"
43+
compileOnly library.java.auto_value_annotations
44+
45+
testImplementation(library.java.truth) {
46+
exclude group: 'com.google.guava', module: 'guava'
47+
}
48+
testImplementation library.java.junit
49+
testImplementation library.java.mockito_inline
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.beam.it.datadog;
19+
20+
import org.apache.http.impl.client.CloseableHttpClient;
21+
import org.apache.http.impl.client.HttpClientBuilder;
22+
import org.mockserver.client.MockServerClient;
23+
24+
/** Datadog Driver Factory class. */
25+
class DatadogClientFactory {
26+
DatadogClientFactory() {}
27+
28+
/**
29+
* Returns an HTTP client that is used to send HTTP messages to Datadog API.
30+
*
31+
* @return An HTTP client for sending HTTP messages to Datadog API.
32+
*/
33+
CloseableHttpClient getHttpClient() {
34+
return HttpClientBuilder.create().disableContentCompression().build();
35+
}
36+
37+
/**
38+
* Returns a {@link MockServerClient} for sending requests to a MockServer instance.
39+
*
40+
* @param host the service host.
41+
* @param port the service port.
42+
* @return A {@link MockServerClient} to retrieve messages from a MockServer instance.
43+
*/
44+
MockServerClient getServiceClient(String host, int port) {
45+
return new MockServerClient(host, port);
46+
}
47+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.beam.it.datadog;
19+
20+
import static org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions.checkNotNull;
21+
22+
import com.google.auto.value.AutoValue;
23+
import javax.annotation.Nullable;
24+
25+
/** A class for Datadog log entries, copy of DatadogEvent. */
26+
@AutoValue
27+
public abstract class DatadogLogEntry {
28+
29+
public static Builder newBuilder() {
30+
return new AutoValue_DatadogLogEntry.Builder();
31+
}
32+
33+
@Nullable
34+
public abstract String ddsource();
35+
36+
@Nullable
37+
public abstract String ddtags();
38+
39+
@Nullable
40+
public abstract String hostname();
41+
42+
@Nullable
43+
public abstract String service();
44+
45+
@Nullable
46+
public abstract String message();
47+
48+
/** A builder class for creating {@link DatadogLogEntry} objects. */
49+
@AutoValue.Builder
50+
public abstract static class Builder {
51+
52+
abstract Builder setDdsource(String source);
53+
54+
abstract Builder setDdtags(String tags);
55+
56+
abstract Builder setHostname(String hostname);
57+
58+
abstract Builder setService(String service);
59+
60+
abstract Builder setMessage(String message);
61+
62+
abstract String message();
63+
64+
abstract DatadogLogEntry autoBuild();
65+
66+
public Builder withSource(String source) {
67+
checkNotNull(source, "withSource(source) called with null input.");
68+
69+
return setDdsource(source);
70+
}
71+
72+
public Builder withTags(String tags) {
73+
checkNotNull(tags, "withTags(tags) called with null input.");
74+
75+
return setDdtags(tags);
76+
}
77+
78+
public Builder withHostname(String hostname) {
79+
checkNotNull(hostname, "withHostname(hostname) called with null input.");
80+
81+
return setHostname(hostname);
82+
}
83+
84+
public Builder withService(String service) {
85+
checkNotNull(service, "withService(service) called with null input.");
86+
87+
return setService(service);
88+
}
89+
90+
public Builder withMessage(String message) {
91+
checkNotNull(message, "withMessage(message) called with null input.");
92+
93+
return setMessage(message);
94+
}
95+
96+
public DatadogLogEntry build() {
97+
checkNotNull(message(), "Message is required.");
98+
99+
return autoBuild();
100+
}
101+
}
102+
}

0 commit comments

Comments
 (0)