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

Add public api to change baseUrl for telemetry #420

Merged
merged 1 commit into from
Aug 1, 2019

Conversation

korshaknn
Copy link
Contributor

@korshaknn korshaknn commented Jul 25, 2019

Problem
Vision team need to change telemetry url at runtime depending on a current country.

Solution
Was decided to add a public API to mapbox-events-android lib change telemetry url dynamically.

Test
Unit tests were added to check if a new url is valid and a telemetry client receives setting with a new base url.

closes 1336

@codecov
Copy link

codecov bot commented Jul 25, 2019

Codecov Report

Merging #420 into master will increase coverage by 0.04%.
The diff coverage is 100%.

@@             Coverage Diff              @@
##             master     #420      +/-   ##
============================================
+ Coverage      68.2%   68.25%   +0.04%     
- Complexity      381      382       +1     
============================================
  Files            68       68              
  Lines          2076     2079       +3     
  Branches        163      163              
============================================
+ Hits           1416     1419       +3     
  Misses          570      570              
  Partials         90       90

Copy link
Contributor

@andrlee andrlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@korshaknn LGTM, i highly suggest to test client with malformed url and valid url pointing to the staging environment.

Also would be nice if we'd make PR a little more descriptive for others to provide useful feedback. Link to style guide: https://github.com/mapbox/mobile-telemetry/blob/master/docs/commit-pr-style.md

I know we should probably add PR template to the repo.
cc: @alfwatt

@@ -257,6 +257,20 @@ public void checksDebugLoggingEnabledAttachment() throws Exception {
.debug(eq("TelemetryClient"), contains(" with 1 event(s) (user agent: anyUserAgent) with payload:"));
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder what happens if we pass malformed url? should we handle and implement a unit test for it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a regex to check if entered url is valid. Will it be ok?

private static final String COM_EVENTS_HOST = "events.mapbox.com";
private static final String CHINA_EVENTS_HOST = "events.mapbox.cn";
@SuppressWarnings("WeakerAccess")
public static final String DEFAULT_STAGING_EVENTS_HOST = "api-events-staging.tilestream.net";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest not to expose constants of the package private class publicly, https://github.com/mapbox/mapbox-events-android/blob/master/libtelemetry/src/main/java/com/mapbox/android/telemetry/MapboxTelemetryConstants.java is a better home for them.

@@ -67,6 +70,10 @@ HttpUrl getBaseUrl() {
return baseUrl;
}

void setBaseUrl(String eventsHost) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way we could achieve the same with the builder? it feels like this breaks immutability of the TelemetryClientSettings class.

@@ -476,4 +476,13 @@ public Thread newThread(Runnable runnable) {
};
}
}

@SuppressWarnings("WeakerAccess")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder why are we suppressing this lint warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint says that access can be package-private. But we need to call it from outside, so make it public and suppress warning

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now since this is a new public api, i've few questions:

  • what happens if this method is called from the main thread?
  • what happens if this method is called while the network request is in flight?
  • what happens if this method is called from multiple threads at the same time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think nothing happens if we call it from the main thread.
It won't affect if the request in flight, it will affect the next request.
It's not atomic, so logic could be broken if method is called from multiple threads, but maybe it's an edge case and there is no need to handle it?

or make the method synchronized?
looks like other teams don't need that method, so it will be used only by vision team.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, let's make it at the very east synchronized

@@ -170,4 +170,8 @@ private RequestBody reverseMultiForm(MultipartBody.Builder builder) {

return builder.build();
}

void setBaseUrl(String eventsHost) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suggest to look into how this can be accomplished with the builder.

@korshaknn
Copy link
Contributor Author

@andrlee ptal

Copy link
Contributor

@yunikkk yunikkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok from my side, please update field as synchronized as discussed

Copy link
Contributor

@andrlee andrlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! A minor nitpick

}
}

private boolean isValidUrl(String eventsHost) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this method be static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is used in a single non-static method, so no need to make it static.

@korshaknn korshaknn merged commit 64f8f94 into master Aug 1, 2019
@korshaknn korshaknn deleted the knn-change-url-public-api branch August 1, 2019 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants