Skip to content

Conversation

@megha-narayanan
Copy link

Implements various parts of log steaming functionality
Note frontend tests for components do exist but are not included in this PR due to dependencies which require PR3.1 being merged.

@changeset-bot
Copy link

changeset-bot bot commented Jul 22, 2025

⚠️ No Changeset found

Latest commit: bdba176

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@megha-narayanan megha-narayanan marked this pull request as ready for review July 22, 2025 21:31
@megha-narayanan megha-narayanan requested review from a team as code owners July 22, 2025 21:31
Copy link
Member

@svidgen svidgen left a comment

Choose a reason for hiding this comment

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

Ideally, would like to ensure magic numbers are constants with notes indicating why the numbers where chosen. If the reason is, "subjectively tuned" or similar, just note that so we know it's not based on any firm guidance or hard measurements.

More importantly, unless I missed it, let's ensure code that runs on intervals accounts for overlaps. This is especially important for async code that won't naturally force each subsequent interval event to wait for the prior call to finish.

let nextToken: string | undefined = undefined;
let currentLogStreamName = logStreamName;
let lastStreamCheckTime = Date.now();
const STREAM_CHECK_INTERVAL = 30000; // Check for new streams every 30 seconds
Copy link
Member

Choose a reason for hiding this comment

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

Why 30 seconds?

Copy link
Author

Choose a reason for hiding this comment

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

Adding constants and explanation/documentation for each of these.

let lastStreamCheckTime = Date.now();
const STREAM_CHECK_INTERVAL = 30000; // Check for new streams every 30 seconds
let consecutiveEmptyPolls = 0;
let currentInterval = 2000; // Start with 2 seconds
Copy link
Member

Choose a reason for hiding this comment

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

Why 2 seconds?

Copy link
Author

Choose a reason for hiding this comment

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

See above


// Reset consecutive empty polls and speed up polling if needed
consecutiveEmptyPolls = 0;
if (currentInterval > 2000) {
Copy link
Member

Choose a reason for hiding this comment

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

Should use a constant?

if (currentInterval > 2000) {
// Speed up polling if we're getting logs
clearInterval(pollingInterval);
currentInterval = 2000;
Copy link
Member

Choose a reason for hiding this comment

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

Same?

Comment on lines 615 to 620
if (consecutiveEmptyPolls > 3 && currentInterval < 10000) {
// Slow down polling after 3 empty polls
clearInterval(pollingInterval);
currentInterval = Math.min(currentInterval * 1.5, 10000);
pollingInterval = setInterval(fetchLogs, currentInterval);
this.activeLogPollers.set(resourceId, pollingInterval);
Copy link
Member

Choose a reason for hiding this comment

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

Looks like some values that should be constants. Ideally annotated with why those constants were chosen. Whether and/or how they should be tuned.

Also, looks like some repeated logic for killing and re-registering the interval at a new level. Probably better as shared logic to avoid any drift in how the timers are managed.

Copy link
Author

Choose a reason for hiding this comment

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

yep, doing that. and extracting that into a helper function for shared logic!

let currentInterval = 2000; // Start with 2 seconds

const fetchLogs = () => {
void (async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this wrapped in void (async () => {}) instead of const fetchLogs = async () => {}?

Copy link
Author

Choose a reason for hiding this comment

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

I think I did this for lint at some point? anyway fixing that.

let consecutiveEmptyPolls = 0;
let currentInterval = 2000; // Start with 2 seconds

const fetchLogs = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I'm missing it, but this seems to optimistically assume any previous fetchLogs request has finished. But, that won't always be the case.

What happens if fetchLogs requests start to overlap? (Due to network congestion, service degradations, etc.)

Copy link
Author

Choose a reason for hiding this comment

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

Good catch. I think I neglected this because of the delay between requests, but I added a check for that now.

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