-
Notifications
You must be signed in to change notification settings - Fork 48
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
Conversation
da289c9
to
3a7a151
Compare
Codecov Report
@@ 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 |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
3a7a151
to
0c531c7
Compare
@andrlee ptal |
There was a problem hiding this 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
0c531c7
to
4ff0a3f
Compare
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
4ff0a3f
to
ca56cb5
Compare
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