Skip to content

Commit 11194a3

Browse files
committed
set up sns contract tests
1 parent eb1574f commit 11194a3

File tree

8 files changed

+406
-3
lines changed

8 files changed

+406
-3
lines changed

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

Lines changed: 180 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public abstract class AwsSdkBaseTest extends ContractTestBase {
4545
LocalStackContainer.Service.KINESIS,
4646
LocalStackContainer.Service.SECRETSMANAGER,
4747
LocalStackContainer.Service.IAM,
48-
LocalStackContainer.Service.STEPFUNCTIONS)
48+
LocalStackContainer.Service.STEPFUNCTIONS,
49+
LocalStackContainer.Service.SNS)
4950
.withEnv("DEFAULT_REGION", "us-west-2")
5051
.withNetwork(network)
5152
.withEnv("LOCALSTACK_HOST", "127.0.0.1")
@@ -109,6 +110,8 @@ protected String getApplicationWaitPattern() {
109110

110111
protected abstract String getStepFunctionsSpanNamePrefix();
111112

113+
protected abstract String getSnsSpanNamePrefix();
114+
112115
protected abstract String getS3RpcServiceName();
113116

114117
protected abstract String getDynamoDbRpcServiceName();
@@ -127,6 +130,8 @@ protected String getApplicationWaitPattern() {
127130

128131
protected abstract String getSecretsManagerRpcServiceName();
129132

133+
protected abstract String getSnsRpcServiceName();
134+
130135
protected abstract String getStepFunctionsRpcServiceName();
131136

132137
private String getS3ServiceName() {
@@ -169,6 +174,10 @@ private String getStepFunctionsServiceName() {
169174
return "AWS::StepFunctions";
170175
}
171176

177+
protected String getSnsServiceName() {
178+
return "AWS::SNS";
179+
}
180+
172181
private String s3SpanName(String operation) {
173182
return String.format("%s.%s", getS3SpanNamePrefix(), operation);
174183
}
@@ -209,6 +218,10 @@ private String stepFunctionsSpanName(String operation) {
209218
return String.format("%s.%s", getStepFunctionsSpanNamePrefix(), operation);
210219
}
211220

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

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

Lines changed: 24 additions & 1 deletion
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
}
@@ -316,5 +326,18 @@ void testStepFunctionsFault() throws Exception {
316326
doTestStepFunctionsFault();
317327
}
318328

319-
// TODO: Set up SNS tests
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+
}
320343
}

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

Lines changed: 24 additions & 1 deletion
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();
@@ -319,5 +329,18 @@ void testStepFunctionsFault() throws Exception {
319329
doTestStepFunctionsFault();
320330
}
321331

322-
// TODO: Set up SNS tests
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+
}
323346
}

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)