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

Shorten host property in network statsbeat #2087

Merged
merged 7 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,33 @@ private double getRequestDurationAvg() {

/**
* e.g. endpointUrl 'https://westus-0.in.applicationinsights.azure.com/v2.1/track' host will
* return 'westus-0.in.applicationinsights.azure.com'
* return 'westus-0'
*/
static String getHost(String endpointUrl) {
heyams marked this conversation as resolved.
Show resolved Hide resolved
assert (endpointUrl != null && !endpointUrl.isEmpty());
int start = endpointUrl.indexOf("://");
int index = 0;
if (start != -1) {
int end = endpointUrl.indexOf("/", start + 3);
index = start + 3;
}

start = endpointUrl.indexOf("www.");
if (start != -1) {
index = start + 4;
int end = endpointUrl.indexOf(".", index + 1);
if (end != -1) {
return endpointUrl.substring(start + 3, end);
return endpointUrl.substring(index, end);
}
}

return endpointUrl.substring(start + 3);
int end = endpointUrl.indexOf(".");
if (end != -1) {
return endpointUrl.substring(index, end);
}

int end = endpointUrl.indexOf("/");
end = endpointUrl.indexOf("/", index);
if (end != -1) {
return endpointUrl.substring(0, end);
return endpointUrl.substring(index, end);
}

return endpointUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,28 @@ public void run() {

@Test
public void testGetHost() {
String url = "https://fake-host.applicationinsights.azure.com/v2.1/track";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fake-host.applicationinsights.azure.com");
String url = "https://fakehost-1.example.com/";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost-1");

url = "http://fake-host.example.com/v2/track";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fake-host.example.com");
url = "https://fakehost-2.example.com/";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost-2");

url = "http://www.fake-host.com/v2/track";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("www.fake-host.com");
url = "http://www.fakehost-3.example.com/";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost-3");

url = "www.fake-host.com/";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("www.fake-host.com");
url = "http://www.fakehost.com/v2/track";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost");

url = "http://fake-host.com";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fake-host.com");
url = "www.fakehost0-4.com/";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost0-4");

url = "http://fake-host.com/";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fake-host.com");
url = "http://fakehost.com";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost");

url = "http://fakehost/";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost");

url = "fakehost.example.com";
assertThat(NetworkStatsbeat.getHost(url)).isEqualTo("fakehost");
}
}