-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modifying instrumentation to send other attrs
- Loading branch information
Showing
24 changed files
with
735 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...umentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/DestinationData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.newrelic.utils; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
|
||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
class DestinationData { | ||
private final String region; | ||
private final String accountId; | ||
private final String queueName; | ||
|
||
private static final DestinationData UNKNOWN = new DestinationData(null, null, "unknown"); | ||
private static final Pattern QUEUE_URL_PATTERN = Pattern.compile( | ||
"https://sqs.(?<region>[^.]+).amazonaws.com/(?<accountId>[^/]+)/(?<queueName>.*)"); | ||
private static final Map<String, DestinationData> CACHE = AgentBridge.collectionFactory | ||
.createConcurrentTimeBasedEvictionMap(3600 * 8); // 8 hours | ||
|
||
private DestinationData(String region, String accountId, String queueName) { | ||
this.region = region; | ||
this.accountId = accountId; | ||
this.queueName = queueName; | ||
} | ||
|
||
public String getRegion() { | ||
return region; | ||
} | ||
|
||
public String getAccountId() { | ||
return accountId; | ||
} | ||
|
||
public String getQueueName() { | ||
return queueName; | ||
} | ||
|
||
public static DestinationData parse(String queueUrl) { | ||
return CACHE.computeIfAbsent(queueUrl, DestinationData::doParse); | ||
} | ||
|
||
private static DestinationData doParse(String queueUrl) { | ||
Matcher matcher = QUEUE_URL_PATTERN.matcher(queueUrl); | ||
if (matcher.matches()) { | ||
return new DestinationData( | ||
matcher.group("region"), | ||
matcher.group("accountId"), | ||
matcher.group("queueName") | ||
); | ||
} else { | ||
int index = queueUrl.lastIndexOf('/'); | ||
if (index <= 0) { | ||
return UNKNOWN; | ||
} | ||
String queueName = queueUrl.substring(index + 1); | ||
return new DestinationData(null, null, queueName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
instrumentation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/Util.java
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
instrumentation/aws-java-sdk-sqs-1.10.44/src/test/java/UtilTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...tation/aws-java-sdk-sqs-1.10.44/src/test/java/com/newrelic/utils/DestinationDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* | ||
* * Copyright 2024 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.newrelic.utils; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class DestinationDataTest { | ||
|
||
@Test | ||
public void parse() { | ||
DestinationData data = DestinationData.parse("https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue"); | ||
|
||
assertNotNull(data); | ||
assertEquals("us-east-2", data.getRegion()); | ||
assertEquals("123456789012", data.getAccountId()); | ||
assertEquals("MyQueue", data.getQueueName()); | ||
} | ||
|
||
@Test | ||
public void parse_bogus() { | ||
DestinationData data = DestinationData.parse("bogus"); | ||
|
||
assertNotNull(data); | ||
assertNull(data.getRegion()); | ||
assertNull(data.getAccountId()); | ||
assertEquals("unknown", data.getQueueName()); | ||
} | ||
|
||
@Test | ||
public void parse_nonMatchingUrl() { | ||
DestinationData data = DestinationData.parse("https://not-sqs.us-east-2.amazonaws.com/123456789012/MyQueue"); | ||
|
||
assertNotNull(data); | ||
assertNull(data.getRegion()); | ||
assertNull(data.getAccountId()); | ||
assertEquals("MyQueue", data.getQueueName()); | ||
} | ||
|
||
} |
Oops, something went wrong.