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

RavenDB-22176 Exposing notifications via GET endpoint #18318

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

maciejaszyk
Copy link
Member

Issue link

https://issues.hibernatingrhinos.com/issue/RavenDB-22176

Additional description

Type of change

  • Bug fix
  • Regression bug fix
  • Optimization
  • New feature

How risky is the change?

  • Low
  • Moderate
  • High
  • Not relevant

Backward compatibility

  • Non breaking change
  • Ensured. Please explain how has it been implemented?
  • Breaking change
  • Not relevant

Is it platform specific issue?

  • Yes. Please list the affected platforms.
  • No

Documentation update

  • This change requires a documentation update. Please mark the issue on YouTrack using Documentation Required tag.
  • No documentation update is needed

Testing by Contributor

  • Tests have been added that prove the fix is effective or that the feature works
  • Internal classes added to the test class (e.g. entity or index definition classes) have the lowest possible access modifier (preferable private)
  • It has been verified by manual testing

Testing by RavenDB QA team

  • This change requires a special QA testing due to possible performance or resources usage implications (CPU, memory, IO). Please mark the issue on YouTrack using QA Required tag.
  • No special testing by RavenDB QA team is needed

Is there any existing behavior change of other features due to this change?

  • Yes. Please list the affected features/subsystems and provide appropriate explanation
  • No

UI work

  • It requires further work in the Studio. Please mark the issue on YouTrack using Studio Required tag.
  • No UI work is needed

@maciejaszyk maciejaszyk requested a review from Lwiel April 2, 2024 14:41
@github-actions github-actions bot added the v5.4 label Apr 2, 2024

namespace Raven.Server.NotificationCenter.Handlers
{
public class DatabaseNotificationCenterHandler : DatabaseRequestHandler
{
[RavenAction("/databases/*/notification-center/get", "GET", AuthorizationStatus.ValidUser, EndpointType.Read, SkipUsagesCount = true)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change the path to /databases/*/notification-center/notifications or something similar

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like it

Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand /get matches other paths in this handler, so maybe it should stay like this

Copy link
Member

Choose a reason for hiding this comment

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

GET /databases/notifications

public class RavenDB_22176 : RavenDB_17068
{
[RavenFact(RavenTestCategory.Indexes)]
public async Task GetCurrentNotificationsAsJson()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something like TestGetNotificationsEndpoint would be more descriptive

Copy link
Member Author

Choose a reason for hiding this comment

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

done


namespace Raven.Server.NotificationCenter.Handlers
{
public class DatabaseNotificationCenterHandler : DatabaseRequestHandler
{
[RavenAction("/databases/*/notification-center/get", "GET", AuthorizationStatus.ValidUser, EndpointType.Read, SkipUsagesCount = true)]
public async Task GetNotifications()
{
Copy link
Member

Choose a reason for hiding this comment

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

Please provide parameter to determine type of notifications to get (alerts, performance hints)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

{
var postponed = GetBoolValueQueryString("postponed", required: false) ?? true;
var type = GetStringQueryString("type", false);
var shouldFilter = type != null && Enum.TryParse(typeof(NotificationType), type, out _);
Copy link
Member

Choose a reason for hiding this comment

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

If we cannot parse we should throw instead of silently ignoring that

Copy link
Member Author

Choose a reason for hiding this comment

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

done


namespace Raven.Server.NotificationCenter.Handlers
{
public class DatabaseNotificationCenterHandler : DatabaseRequestHandler
{
[RavenAction("/databases/*/notification-center/get", "GET", AuthorizationStatus.ValidUser, EndpointType.Read, SkipUsagesCount = true)]
Copy link
Member

Choose a reason for hiding this comment

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

GET /databases/notifications

{
public RavenDB_17068(ITestOutputHelper output) : base(output)
public RavenDb17068(ITestOutputHelper output) : base(output)
Copy link
Member

Choose a reason for hiding this comment

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

:(

@@ -18,9 +18,9 @@

namespace SlowTests.Issues;

public class RavenDB_17068: RavenTestBase
public sealed class RavenDb17068: RavenDB_17068_Base
Copy link
Member

Choose a reason for hiding this comment

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

can you fix the name, revert it

Copy link
Member

Choose a reason for hiding this comment

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

this will mess up with test history on CI

Copy link
Member Author

Choose a reason for hiding this comment

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

Unintentional, sorry!

isFirst = false;
}

writer.WriteEndArray();
Copy link
Member

Choose a reason for hiding this comment

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

I'm missing paging, would love to have sth like TotalCount or TotalResults and even in-memory paging here with optimization that pageSize=0 will just return count, like we have for regular queries

Copy link
Member Author

Choose a reason for hiding this comment

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

Done :)

var pageSize = GetIntValueQueryString("pageSize", required: false) ?? int.MaxValue;

var shouldFilter = type != null;
if (shouldFilter && Enum.TryParse(typeof(NotificationType), type, out _) == false)
Copy link
Member

Choose a reason for hiding this comment

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

NotificationType enum is quite big:

public enum NotificationType
{
None,
AlertRaised,
OperationChanged,
DatabaseChanged,
NotificationUpdated,
RecentError, // used in studio
PerformanceHint,
DatabaseStatsChanged,
ClusterTopologyChanged

And the only relevant values here are AlertRaised and PerformanceHint, right? (because only those are persisted). I wonder if we should use this enum. Maybe better to have support for type=[alert|performance-hint]? @ppekrol?

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to go with enum, but you are correct, this one is not good. Can we introduce a new one? Maybe even with [Flags] attribute, so we can pick multiple ones?

…s for `RavenDB_17068` and `RavenDB_22176` tests to avoid repeating tests.
…persist test history in CI | Added the ability to retrieve notifications in a paging fashion.
@arekpalinski arekpalinski merged commit 26ded91 into ravendb:v5.4 Apr 11, 2024
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants