Skip to content

Commit a350133

Browse files
committed
set up sns contract tests
1 parent 3ede02e commit a350133

File tree

8 files changed

+493
-35
lines changed

8 files changed

+493
-35
lines changed

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/awssdk/base/AwsSdkBaseTest.java

Lines changed: 186 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.List;
2424
import java.util.Map;
2525
import java.util.Set;
26-
2726
import org.assertj.core.api.ThrowingConsumer;
2827
import org.junit.jupiter.api.AfterAll;
2928
import org.junit.jupiter.api.BeforeAll;
@@ -46,7 +45,8 @@ public abstract class AwsSdkBaseTest extends ContractTestBase {
4645
LocalStackContainer.Service.KINESIS,
4746
LocalStackContainer.Service.SECRETSMANAGER,
4847
LocalStackContainer.Service.IAM,
49-
LocalStackContainer.Service.STEPFUNCTIONS)
48+
LocalStackContainer.Service.STEPFUNCTIONS,
49+
LocalStackContainer.Service.SNS)
5050
.withEnv("DEFAULT_REGION", "us-west-2")
5151
.withNetwork(network)
5252
.withEnv("LOCALSTACK_HOST", "127.0.0.1")
@@ -110,6 +110,8 @@ protected String getApplicationWaitPattern() {
110110

111111
protected abstract String getStepFunctionsSpanNamePrefix();
112112

113+
protected abstract String getSnsSpanNamePrefix();
114+
113115
protected abstract String getS3RpcServiceName();
114116

115117
protected abstract String getDynamoDbRpcServiceName();
@@ -128,6 +130,8 @@ protected String getApplicationWaitPattern() {
128130

129131
protected abstract String getSecretsManagerRpcServiceName();
130132

133+
protected abstract String getSnsRpcServiceName();
134+
131135
protected abstract String getStepFunctionsRpcServiceName();
132136

133137
private String getS3ServiceName() {
@@ -166,7 +170,13 @@ private String getSecretsManagerServiceName() {
166170
return "AWS::SecretsManager";
167171
}
168172

169-
private String getStepFunctionsServiceName() { return "AWS::StepFunctions"; }
173+
private String getStepFunctionsServiceName() {
174+
return "AWS::StepFunctions";
175+
}
176+
177+
protected String getSnsServiceName() {
178+
return "AWS::SNS";
179+
}
170180

171181
private String s3SpanName(String operation) {
172182
return String.format("%s.%s", getS3SpanNamePrefix(), operation);
@@ -208,6 +218,10 @@ private String stepFunctionsSpanName(String operation) {
208218
return String.format("%s.%s", getStepFunctionsSpanNamePrefix(), operation);
209219
}
210220

221+
private String snsSpanName(String operation) {
222+
return String.format("%s.%s", getSnsSpanNamePrefix(), operation);
223+
}
224+
211225
protected ThrowingConsumer<KeyValue> assertAttribute(String key, String value) {
212226
return (attribute) -> {
213227
var actualKey = attribute.getKey();
@@ -3087,4 +3101,173 @@ protected void doTestStepFunctionsFault() throws Exception {
30873101
cloudformationIdentifier,
30883102
0.0);
30893103
}
3104+
3105+
protected void doTestSnsGetTopicAttributes() throws Exception {
3106+
appClient.get("/sns/gettopicattributes/test-topic").aggregate().join();
3107+
var traces = mockCollectorClient.getTraces();
3108+
var metrics =
3109+
mockCollectorClient.getMetrics(
3110+
Set.of(
3111+
AppSignalsConstants.ERROR_METRIC,
3112+
AppSignalsConstants.FAULT_METRIC,
3113+
AppSignalsConstants.LATENCY_METRIC));
3114+
3115+
var localService = getApplicationOtelServiceName();
3116+
var localOperation = "GET /sns/gettopicattributes/:topicId";
3117+
var type = "AWS::SNS::Topic";
3118+
var identifier = "test-topic";
3119+
var cloudformationIdentifier = "arn:aws:sns:us-west-2:000000000000:test-topic";
3120+
3121+
assertSpanClientAttributes(
3122+
traces,
3123+
snsSpanName("GetTopicAttributes"),
3124+
getSnsRpcServiceName(),
3125+
localService,
3126+
localOperation,
3127+
getSnsServiceName(),
3128+
"GetTopicAttributes",
3129+
type,
3130+
identifier,
3131+
cloudformationIdentifier,
3132+
"localstack",
3133+
4566,
3134+
"http://localstack:4566",
3135+
200,
3136+
List.of(
3137+
assertAttribute(
3138+
SemanticConventionsConstants.AWS_TOPIC_ARN,
3139+
"arn:aws:sns:us-west-2:000000000000:test-topic")));
3140+
}
3141+
3142+
protected void doTestSnsError() throws Exception {
3143+
appClient.get("/sns/error").aggregate().join();
3144+
var traces = mockCollectorClient.getTraces();
3145+
var metrics =
3146+
mockCollectorClient.getMetrics(
3147+
Set.of(
3148+
AppSignalsConstants.ERROR_METRIC,
3149+
AppSignalsConstants.FAULT_METRIC,
3150+
AppSignalsConstants.LATENCY_METRIC));
3151+
3152+
var localService = getApplicationOtelServiceName();
3153+
var localOperation = "GET /sns/error";
3154+
assertSpanClientAttributes(
3155+
traces,
3156+
snsSpanName("GetTopicAttributes"),
3157+
getSnsRpcServiceName(),
3158+
localService,
3159+
localOperation,
3160+
getSnsServiceName(),
3161+
"GetTopicAttributes",
3162+
null,
3163+
null,
3164+
null,
3165+
"error.test",
3166+
8080,
3167+
"http://error.test:8080",
3168+
400,
3169+
List.of());
3170+
3171+
assertMetricClientAttributes(
3172+
metrics,
3173+
AppSignalsConstants.LATENCY_METRIC,
3174+
localService,
3175+
localOperation,
3176+
getSnsServiceName(),
3177+
"GetTopicAttributes",
3178+
null,
3179+
null,
3180+
null,
3181+
5000.0);
3182+
3183+
assertMetricClientAttributes(
3184+
metrics,
3185+
AppSignalsConstants.FAULT_METRIC,
3186+
localService,
3187+
localOperation,
3188+
getSnsServiceName(),
3189+
"GetTopicAttributes",
3190+
null,
3191+
null,
3192+
null,
3193+
0.0);
3194+
3195+
assertMetricClientAttributes(
3196+
metrics,
3197+
AppSignalsConstants.ERROR_METRIC,
3198+
localService,
3199+
localOperation,
3200+
getSnsServiceName(),
3201+
"GetTopicAttributes",
3202+
null,
3203+
null,
3204+
null,
3205+
1.0);
3206+
}
3207+
3208+
protected void doTestSnsFault() throws Exception {
3209+
appClient.get("/sns/fault").aggregate().join();
3210+
var traces = mockCollectorClient.getTraces();
3211+
var metrics =
3212+
mockCollectorClient.getMetrics(
3213+
Set.of(
3214+
AppSignalsConstants.ERROR_METRIC,
3215+
AppSignalsConstants.FAULT_METRIC,
3216+
AppSignalsConstants.LATENCY_METRIC));
3217+
3218+
var localService = getApplicationOtelServiceName();
3219+
var localOperation = "GET /sns/fault";
3220+
assertSpanClientAttributes(
3221+
traces,
3222+
snsSpanName("GetTopicAttributes"),
3223+
getSnsRpcServiceName(),
3224+
localService,
3225+
localOperation,
3226+
getSnsServiceName(),
3227+
"GetTopicAttributes",
3228+
null,
3229+
null,
3230+
null,
3231+
"fault.test",
3232+
8080,
3233+
"http://fault.test:8080",
3234+
500,
3235+
List.of());
3236+
3237+
assertMetricClientAttributes(
3238+
metrics,
3239+
AppSignalsConstants.LATENCY_METRIC,
3240+
localService,
3241+
localOperation,
3242+
getSnsServiceName(),
3243+
"GetTopicAttributes",
3244+
null,
3245+
null,
3246+
null,
3247+
5000.0);
3248+
3249+
assertMetricClientAttributes(
3250+
metrics,
3251+
AppSignalsConstants.FAULT_METRIC,
3252+
localService,
3253+
localOperation,
3254+
getSnsServiceName(),
3255+
"GetTopicAttributes",
3256+
null,
3257+
null,
3258+
null,
3259+
1.0);
3260+
3261+
assertMetricClientAttributes(
3262+
metrics,
3263+
AppSignalsConstants.ERROR_METRIC,
3264+
localService,
3265+
localOperation,
3266+
getSnsServiceName(),
3267+
"GetTopicAttributes",
3268+
null,
3269+
null,
3270+
null,
3271+
0.0);
3272+
}
30903273
}

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/awssdk/v1/AwsSdkV1Test.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ protected String getStepFunctionsSpanNamePrefix() {
8686
return "AWSStepFunctions";
8787
}
8888

89+
@Override
90+
protected String getSnsSpanNamePrefix() {
91+
return "SNS";
92+
}
93+
8994
protected String getS3RpcServiceName() {
9095
return "Amazon S3";
9196
}
@@ -110,6 +115,11 @@ protected String getStepFunctionsRpcServiceName() {
110115
return "AWSStepFunctions";
111116
}
112117

118+
@Override
119+
protected String getSnsRpcServiceName() {
120+
return "AmazonSNS";
121+
}
122+
113123
protected String getKinesisRpcServiceName() {
114124
return "AmazonKinesis";
115125
}
@@ -315,4 +325,19 @@ void testStepFunctionsError() throws Exception {
315325
void testStepFunctionsFault() throws Exception {
316326
doTestStepFunctionsFault();
317327
}
328+
329+
@Test
330+
void testSnsGetTopicAttributes() throws Exception {
331+
doTestSnsGetTopicAttributes();
332+
}
333+
334+
@Test
335+
void testSnsError() throws Exception {
336+
doTestStepFunctionsError();
337+
}
338+
339+
@Test
340+
void testSnsFault() throws Exception {
341+
doTestStepFunctionsFault();
342+
}
318343
}

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/awssdk/v2/AwsSdkV2Test.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ protected String getStepFunctionsSpanNamePrefix() {
8585
return "Sfn";
8686
}
8787

88+
@Override
89+
protected String getSnsSpanNamePrefix() {
90+
return "Sns";
91+
}
92+
8893
@Override
8994
protected String getS3RpcServiceName() {
9095
return "S3";
@@ -134,6 +139,11 @@ protected String getStepFunctionsRpcServiceName() {
134139
return "Sfn";
135140
}
136141

142+
@Override
143+
protected String getSnsRpcServiceName() {
144+
return "Sns";
145+
}
146+
137147
@Test
138148
void testS3CreateBucket() throws Exception {
139149
doTestS3CreateBucket();
@@ -318,4 +328,19 @@ void testStepFunctionsError() throws Exception {
318328
void testStepFunctionsFault() throws Exception {
319329
doTestStepFunctionsFault();
320330
}
331+
332+
@Test
333+
void testSnsGetTopicAttributes() throws Exception {
334+
doTestSnsGetTopicAttributes();
335+
}
336+
337+
@Test
338+
void testSnsError() throws Exception {
339+
doTestStepFunctionsError();
340+
}
341+
342+
@Test
343+
void testSnsFault() throws Exception {
344+
doTestStepFunctionsFault();
345+
}
321346
}

appsignals-tests/contract-tests/src/test/java/software/amazon/opentelemetry/appsignals/test/utils/SemanticConventionsConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public class SemanticConventionsConstants {
7373
public static final String AWS_SECRET_ARN = "aws.secretsmanager.secret.arn";
7474
public static final String AWS_STATE_MACHINE_ARN = "aws.stepfunctions.state_machine.arn";
7575
public static final String AWS_ACTIVITY_ARN = "aws.stepfunctions.activity.arn";
76+
public static final String AWS_TOPIC_ARN = "aws.sns.topic.arn";
7677

7778
// kafka
7879
public static final String MESSAGING_CLIENT_ID = "messaging.client_id";

appsignals-tests/images/aws-sdk/aws-sdk-v1/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636
implementation("com.amazonaws:aws-java-sdk-secretsmanager")
3737
implementation("com.amazonaws:aws-java-sdk-iam")
3838
implementation("com.amazonaws:aws-java-sdk-stepfunctions")
39+
implementation("com.amazonaws:aws-java-sdk-sns")
3940
implementation("com.amazonaws:aws-java-sdk-bedrock")
4041
implementation("com.amazonaws:aws-java-sdk-bedrockagent")
4142
implementation("com.amazonaws:aws-java-sdk-bedrockruntime")

0 commit comments

Comments
 (0)