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

Review debug reaction #155

Open
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

ruokun-niu
Copy link
Contributor

@ruokun-niu ruokun-niu commented Feb 19, 2025

Description

  • Use React instead of Blazor to build the frontend
  • Updated the code to use the Reaction SDK
  • Updated the raw event stream to update automatically when a new event is received
  • Updated the reaction provider with frontend and backend pod configs

Type of change

  • This pull request is a minor refactor, code cleanup, test improvement, or other maintenance task and doesn't change the functionality of Drasi (issue link optional).

Fixes: #issue_number

@ruokun-niu ruokun-niu marked this pull request as ready for review February 19, 2025 03:21
@ruokun-niu ruokun-niu requested a review from a team as a code owner February 19, 2025 03:21
@ruokun-niu ruokun-niu marked this pull request as draft February 19, 2025 18:38

[ApiController]
[Route("query")]
public class QueryController : ControllerBase
Copy link
Contributor

Choose a reason for hiding this comment

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

We should follow RESTful conventions. Having a queries and a query route is confusing.
eg.
GET / PUT / DELETE /query/<id>

Copy link
Contributor Author

@ruokun-niu ruokun-niu Feb 20, 2025

Choose a reason for hiding this comment

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

Planning to implement the followings:

queries

  • used for retrieving a list of queries that the reaction is subscribed to

queries/{queryId}

  • for retrieving the current result set of a query. This is used when the page loads up and when the user clicks the reinitialize query cache button

queries/{queryId}/debug-information

  • for debug info like query host, status and etc.

@ruokun-niu ruokun-niu marked this pull request as ready for review February 21, 2025 04:07
}


private async Task<QueryResult> InitResult(string queryId)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if this method is invoked for the same query twice, before the first one completes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I did some searches online and it seems like one promising approach is to store/cache Task using a ConcurrentDicitionary. That way concurrent invocation to this method will share the same result. Any thoughts on this approach @danielgerlag ?


const fetchStream = async () => {
try {
const url = "http://localhost:5195/stream";
Copy link
Contributor

Choose a reason for hiding this comment

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

If the front end and back end run in separate pods, how would localhost reach the backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we are still relying on port-forwarding both the frontend and the backend pods. I haven't looked into intra-cluster communication using k8s services yet, but I'll spend some time during this iteration

Copy link
Contributor

Choose a reason for hiding this comment

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

You could serve the front-end app content from the / route of the backend, and it could connect to the /api/* routes for the same address. That way, we don't need two containers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me give it a try

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was able to get it working! Just need to clean up a few things



var port = Environment.GetEnvironmentVariable("PORT") ?? "8080";
server.Urls.Add($"http://0.0.0.0:{port}");

Check warning

Code scanning / devskim

An HTTP-based URL without TLS was detected. Warning

Insecure URL
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",

Check warning

Code scanning / devskim

An HTTP-based URL without TLS was detected. Warning

Insecure URL
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:30442",

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7230;http://localhost:5195",

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7230;http://localhost:5195",

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
@ruokun-niu ruokun-niu requested a review from danielgerlag March 4, 2025 23:00
…/drasi-platform into review-debug-reaction

* 'review-debug-reaction' of https://github.com/ruokun-niu/drasi-platform:
  Transition to Native Multi-Platform Builds for Docker Images (drasi-project#161)
  Bump jinja2 from 3.1.4 to 3.1.5 in /reactions/sdk/python (drasi-project#135)
  Bump vite in /reactions/signalr/signalr-reaction/clients/vue (drasi-project#142)
  Bump nanoid in /reactions/signalr/signalr-reaction/clients/react/example (drasi-project#131)
  Bump openssl from 0.10.66 to 0.10.71 in /query-container (drasi-project#160)
  Bump golang.org/x/crypto from 0.26.0 to 0.31.0 in /cli (drasi-project#132)
  Bump nanoid in /reactions/signalr/signalr-reaction/clients/vue/example (drasi-project#130)
  Bump openssl from 0.10.68 to 0.10.71 in /sources/sdk/rust/example/proxy (drasi-project#158)
  Bump io.undertow:undertow-core from 2.3.15.Final to 2.3.17.Final in /sources/sdk/java (drasi-project#127)
  Bump esbuild from 0.16.17 to 0.25.0 in /dev-tools/vscode/drasi (drasi-project#151)
  Bump openssl from 0.10.66 to 0.10.70 in /control-planes/mgmt_api (drasi-project#148)
  Remove Fixed Dapr Version Constraint (drasi-project#147)
  Gremlin Reaction hotfix (drasi-project#149)

private readonly ILogger<QueryDebugService> _logger;

private readonly ConcurrentDictionary<string, Task<QueryResult>> _activeQueries = new();
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are moving the query result state to the client, why do we need it keep it here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I implemented this dictionary for storing the task of initilializing the query results. This dictionary is only used in the InitResult method, which uses the ResultViewClient to get the initial result for a query.

Let us say that we have a query called query1 that is trying to initialize. In the first invocation, the method will check the dictionary. query1 is not present in the dict, it will execute lambda function and store the Task in the dictionary. If there is a second invocation (before the first one completes), it will wait and return the same Task that is in progress.

The downside is that data might have changed in between the two invocations, but the second invocation will not reflect the new changes. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

What if we did not store the result set on this tier at all, the front end could invoke a route that proxies a request for the initial query result through to the view service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Let me update this


private readonly ConcurrentDictionary<string, Task<QueryResult>> _activeQueries = new();

private readonly LinkedList<JsonElement> _rawEvents = new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to keep this data here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

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.

2 participants