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 support for start and end times in count and histogram aggregate actions #4614

Merged
merged 1 commit into from
Jun 14, 2024

Conversation

kkondaka
Copy link
Collaborator

Description

Add support for start and end times in count and histogram aggregate actions.
Count and Histogram aggregate actions include start and end times based on the real time of aggregation. Adding support to include start and end times based on the times in the event.

Issues Resolved

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • [X ] New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [ X] Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

You appear to have some commits for another PR. See the key-value-processor changes.

@@ -134,6 +135,23 @@ public static long getTimeNanos(final Instant time) {
return currentTimeNanos;
}

public static Instant convertObjectToInstant(Object timeObject) {
Copy link
Member

Choose a reason for hiding this comment

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

This should have a unit test specifically for this.

Also, you can add this as a InstantHelper to the actions package and make it package-protected. That way it doesn't expand much.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I kept it here because this may become useful at aggregate processor level at a later time.

int idx = Arrays.binarySearch(this.buckets, doubleValue);
if (idx < 0) {
idx = -idx-2;
}
Instant eventTime = Instant.now();
Instant eventStartTime = Instant.now();
Copy link
Member

Choose a reason for hiding this comment

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

Let's set these to the exact same value instead of calling Instant.now() multiple times.

Instant eventStartTime = eventTime;
Instant eventEndTime = eventTime;

@@ -81,15 +79,33 @@ public Exemplar createExemplar(final Event event) {
@Override
public AggregateActionResponse handleEvent(final Event event, final AggregateActionInput aggregateActionInput) {
final GroupState groupState = aggregateActionInput.getGroupState();
Instant eventStartTime = Instant.now();
Copy link
Member

Choose a reason for hiding this comment

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

Similar comments as below.

groupState.put(endTimeKey, Instant.now());
Instant groupStartTime = (Instant)groupState.get(startTimeKey);
Instant groupEndTime = (Instant)groupState.get(endTimeKey);
if (eventStartTime.isBefore(groupStartTime))
Copy link
Member

Choose a reason for hiding this comment

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

Are these conditions being tested? Both true and false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes because the test cases assign the times with random delta.

Instant sTime = (i == 0) ? testTime : testTime.plusSeconds(random.nextInt(5));                                                   
            Instant eTime = (i == testCount-1) ? testTime.plusSeconds(100) : testTime.plusSeconds (50+random.nextInt(45));  

Signed-off-by: Krishna Kondaka <[email protected]>
Comment on lines +104 to +107
if (eventStartTime.isBefore(groupStartTime))
groupState.put(startTimeKey, eventStartTime);
if (eventEndTime.isAfter(groupEndTime))
groupState.put(endTimeKey, eventEndTime);
Copy link
Member

Choose a reason for hiding this comment

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

This seems like generic aggregation functionality where we just track the range of times the events have come from for that aggregated event. Is there a way to extend this to all aggregate actions with some common code? Or is it only applicable to count and histogram actions?

@ParameterizedTest
@ValueSource(ints = {10, 20, 50, 100})
void testHistogramAggregateOTelFormatWithStartAndEndTimesInTheEvent(int testCount) throws NoSuchFieldException, IllegalAccessException {
HistogramAggregateActionConfig mockConfig = mock(HistogramAggregateActionConfig.class);
Copy link
Member

Choose a reason for hiding this comment

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

This test is hard to read. Might be worth creating some private functions to make it more readable.

@kkondaka kkondaka merged commit 01ae1dc into opensearch-project:main Jun 14, 2024
43 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants