-
Notifications
You must be signed in to change notification settings - Fork 292
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 |
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.
do you think it is better to have separate endpoint for that ?
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.
@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?
docs/_data/nakadi-event-bus-api.yaml
Outdated
type: object | ||
description: statistics of partition within a subscription context | ||
properties: | ||
partition: |
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.
there's no description for partition
field
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.
throws InconsistentStateException, ServiceTemporarilyUnavailableException { | ||
final List<EventType> eventTypes = getEventTypesForSubscription(subscription); | ||
final List<PartitionEndStatistics> topicPartitions = loadPartitionEndStatistics(eventTypes); |
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.
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.
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.
That is correct, I thought of doing it then forgot to do so. Looks like there will be some more refactoring.
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.
throws SubscriptionNotInitializedException, NakadiRuntimeException { | ||
if (!isSubscriptionCreatedAndInitialized()) { | ||
return Optional.empty(); | ||
} | ||
|
||
return Optional.of(runLocked(() -> new ZkSubscriptionNode( |
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.
Why have you removed running under lock?
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.
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 { |
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 used to put else
on a new line like that but the team told me not to do that :(
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.
@v-stepanov faaee92. What the team wants, the team gets :)
@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; |
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.
maybe you can add @JsonInclude(Include.NON_NULL)
here? Because in other case it will show up for all endpoints where we return subscription.
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.
@@ -34,6 +38,14 @@ public void setCreatedAt(final DateTime createdAt) { | |||
this.createdAt = createdAt; | |||
} | |||
|
|||
public List<SubscriptionEventTypeStats> getStats() { |
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.
probably it should be marked as nullable as it is null in most of the cases
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.
@@ -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()); |
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.
new field show_status
should also be included to pagination link.
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.
@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(); |
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'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)
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.
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()); |
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.
you can actually take streamId from TestStreamingClient and use it here for assertion.
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.
.start(); | ||
waitFor(() -> assertThat(client.getBatches(), hasSize(15))); | ||
|
||
final Response response = when().get("/subscriptions?show_status=true").thenReturn(); |
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.
here it's also possible to have the same problem as I described several lines ago in another test (subscriptions left by other tests).
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.
👍 |
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
👍 |
Implement light subscriptions stats and refactor
Description
subscription data
unchecked ServiceTemporarilyUnavailableException instead
Review