Implement light subscriptions stats and refactor #861
Conversation
- light subscription stats in /subscriptions endpoint - refactor Zk subscription client to not acquire locks to read subscription data - remove ServiceUnavailableException from the project, preferring the unchecked ServiceTemporarilyUnavailableException instead - update the swagger definition
Codecov Report
@@ Coverage Diff @@
## master #861 +/- ##
============================================
- Coverage 53.59% 53.56% -0.04%
- Complexity 1680 1691 +11
============================================
Files 310 309 -1
Lines 9327 9359 +32
Branches 837 841 +4
============================================
+ Hits 4999 5013 +14
- Misses 4029 4046 +17
- Partials 299 300 +1
Continue to review full report at Codecov.
|
@@ -964,6 +964,11 @@ paths: | |||
required: false | |||
default: 0 | |||
minimum: 0 | |||
- name: show_status |
adyach
Apr 16, 2018
Member
do you think it is better to have separate endpoint for that ?
do you think it is better to have separate endpoint for that ?
lmontrieux
Apr 16, 2018
•
Author
Member
@adyach I followed the requirements in our internal ticket:
GET /subscriptions endpoint should have additional parameter show_status = true/false (false by default).
To be honest I don't really have a preference one way or another. Do you think it would be better as a separate endpoint?
@adyach I followed the requirements in our internal ticket:
GET /subscriptions endpoint should have additional parameter show_status = true/false (false by default).
To be honest I don't really have a preference one way or another. Do you think it would be better as a separate endpoint?
type: object | ||
description: statistics of partition within a subscription context | ||
properties: | ||
partition: |
v-stepanov
Apr 16, 2018
Contributor
there's no description for partition
field
there's no description for partition
field
throws InconsistentStateException, ServiceTemporarilyUnavailableException { | ||
final List<EventType> eventTypes = getEventTypesForSubscription(subscription); | ||
final List<PartitionEndStatistics> topicPartitions = loadPartitionEndStatistics(eventTypes); |
v-stepanov
Apr 16, 2018
Contributor
As I see we do this call not looking at includeDistance
value. But this method will actually go to Kafka and do this expensive seek
operation. I thought that in case of light-stats we will not check the offsets in Kafka.
As I see we do this call not looking at includeDistance
value. But this method will actually go to Kafka and do this expensive seek
operation. I thought that in case of light-stats we will not check the offsets in Kafka.
lmontrieux
Apr 16, 2018
Author
Member
That is correct, I thought of doing it then forgot to do so. Looks like there will be some more refactoring.
That is correct, I thought of doing it then forgot to do so. Looks like there will be some more refactoring.
throws SubscriptionNotInitializedException, NakadiRuntimeException { | ||
if (!isSubscriptionCreatedAndInitialized()) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(runLocked(() -> new ZkSubscriptionNode( |
v-stepanov
Apr 16, 2018
Contributor
Why have you removed running under lock?
Why have you removed running under lock?
lmontrieux
Apr 16, 2018
Author
Member
Because it isn't necessary anymore, since we migrated to new zk subscription format (I double checked with @antban )
Because it isn't necessary anymore, since we migrated to new zk subscription format (I double checked with @antban )
if (includeDistance) { | ||
return loadStats(eventTypes, zkSubscriptionNode, subscriptionClient); | ||
} | ||
else { |
v-stepanov
Apr 17, 2018
Contributor
I used to put else
on a new line like that but the team told me not to do that :(
I used to put else
on a new line like that but the team told me not to do that :(
@lmontrieux code looks good for me now. |
deploy validation please |
@@ -18,6 +20,8 @@ public Subscription(final String id, final DateTime createdAt, final Subscriptio | |||
|
|||
private DateTime createdAt; | |||
|
|||
private List<SubscriptionEventTypeStats> stats; |
v-stepanov
Apr 19, 2018
Contributor
maybe you can add @JsonInclude(Include.NON_NULL)
here? Because in other case it will show up for all endpoints where we return subscription.
maybe you can add @JsonInclude(Include.NON_NULL)
here? Because in other case it will show up for all endpoints where we return subscription.
@@ -34,6 +38,14 @@ public void setCreatedAt(final DateTime createdAt) { | |||
this.createdAt = createdAt; | |||
} | |||
|
|||
public List<SubscriptionEventTypeStats> getStats() { |
v-stepanov
Apr 19, 2018
Contributor
probably it should be marked as nullable as it is null in most of the cases
probably it should be marked as nullable as it is null in most of the cases
@@ -157,10 +157,16 @@ public Result listSubscriptions(@Nullable final String owningApplication, @Nulla | |||
subscriptionRepository.listSubscriptions(eventTypesFilter, owningAppOption, offset, limit); | |||
final PaginationLinks paginationLinks = SubscriptionsUriHelper.createSubscriptionPaginationLinks( | |||
owningAppOption, eventTypesFilter, offset, limit, subscriptions.size()); |
v-stepanov
Apr 19, 2018
Contributor
new field show_status
should also be included to pagination link.
new field show_status
should also be included to pagination link.
@v-stepanov there are 2 acceptance tests in 2ffeb20 |
|
public void whenLightStatsOnNotInitializedSubscriptionThenCorrectResponse() throws IOException { | ||
final String et = createEventType().getName(); | ||
final Subscription s = createSubscriptionForEventType(et); | ||
final Response response = when().get("/subscriptions?show_status=true").thenReturn(); |
v-stepanov
Apr 19, 2018
Contributor
it's an acceptance test, what if there will be other subscriptions created by other tests? I think it's better to differ the subscription you created (e.g. by owning_application)
it's an acceptance test, what if there will be other subscriptions created by other tests? I think it's better to differ the subscription you created (e.g. by owning_application)
if (subscription.getId().equals(s.getId())) { | ||
Assert.assertNotNull(subscription.getStats()); | ||
Assert.assertEquals("assigned", subscription.getStats().get(0).getPartitions().get(0).getState()); | ||
Assert.assertNotEquals("", subscription.getStats().get(0).getPartitions().get(0).getStreamId()); |
v-stepanov
Apr 19, 2018
Contributor
you can actually take streamId from TestStreamingClient and use it here for assertion.
you can actually take streamId from TestStreamingClient and use it here for assertion.
.start(); | ||
waitFor(() -> assertThat(client.getBatches(), hasSize(15))); | ||
|
||
final Response response = when().get("/subscriptions?show_status=true").thenReturn(); |
v-stepanov
Apr 19, 2018
•
Contributor
here it's also possible to have the same problem as I described several lines ago in another test (subscriptions left by other tests).
here it's also possible to have the same problem as I described several lines ago in another test (subscriptions left by other tests).
|
1 similar comment
|
Deploy validation please |
This is to avoid confusion, since the flag is called show_status, and the result is the status of the subscription, not some stats
|
|
1 similar comment
|
deploy validation please |
…stats # Conflicts: # CHANGELOG.md
|
1 similar comment
|
f56de8a
into
master
Implement light subscriptions stats and refactor
Description
subscription data
unchecked ServiceTemporarilyUnavailableException instead
Review