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

Logs: switch to an agnostic primary/secondary backend paradigm #1908

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

Page-
Copy link
Contributor

@Page- Page- commented Dec 18, 2024

Change-type: minor

@Page- Page- force-pushed the logs-agnostic-secondary-primary branch from 449ccce to c96184c Compare December 18, 2024 16:06
@Page- Page- requested a review from a team December 19, 2024 10:32
@Page- Page- force-pushed the logs-agnostic-secondary-primary branch 2 times, most recently from dca59d9 to 2cb3db3 Compare December 19, 2024 12:44
@Page- Page- marked this pull request as ready for review December 19, 2024 12:44
const timestamp = new loki.Timestamp();
timestamp.setSeconds(Math.floor(Number(log.nanoTimestamp / 1000000000n)));
timestamp.setNanos(Number(log.nanoTimestamp % 1000000000n));
// store log line as JSON
const logJson = JSON.stringify(log, omitNanoTimestamp);
const logJson = JSON.stringify(
{ ...log, version: VERSION },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is to not mutate the log, it isn't a problem when loki is the secondary but when it's the primary it can cause problems for the secondary as they're getting a loki versioned log which they don't expect

@flowzone-app flowzone-app bot enabled auto-merge December 19, 2024 12:56
src/lib/config.ts Outdated Show resolved Hide resolved
@Page- Page- force-pushed the logs-agnostic-secondary-primary branch from 2cb3db3 to 5a985c6 Compare December 19, 2024 15:12
@Page- Page- requested review from otaviojacobi and a team December 19, 2024 15:12
@Page- Page- force-pushed the logs-agnostic-secondary-primary branch from 5a985c6 to 3f04276 Compare December 19, 2024 15:50
? secondaryBackend?.publish(ctx, buffer).catch((err) => {
captureException(
err,
`Failed to publish logs to ${LOGS_PRIMARY_BACKEND === 'loki' ? 'redis' : 'loki'}`,
Copy link
Member

Choose a reason for hiding this comment

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

NIT

Suggested change
`Failed to publish logs to ${LOGS_PRIMARY_BACKEND === 'loki' ? 'redis' : 'loki'}`,
`Failed to publish logs to ${LOGS_SECONDARY_BACKEND}`,

export const getSecondaryBackend = _.once(
async (): Promise<DeviceLogsBackend> => {
if (LOGS_SECONDARY_BACKEND_ENABLED === false) {
throw new Error('Secondary backend is not enabled');
Copy link
Member

Choose a reason for hiding this comment

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

NIT How about just returning undefined here when LOGS_SECONDARY_BACKEND_ENABLED is false, so that we don't need to do LOGS_SECONDARY_BACKEND_ENABLED ? getSecondaryBackend() : undefined? This way we encapsulate everything in here and we don't have to check LOGS_SECONDARY_BACKEND_ENABLED both right before calling this fn & inside it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doing the throw helps avoid accidental mistakes and also makes it simpler in the case of reading, in the case of writing we need both backends permanently available though (and cannot fetch them on demand because we can't have async boundaries) hence that one needing to be special cased and that's why I went with a throw rather than an implicit == null -> disabled

@flowzone-app flowzone-app bot merged commit fddfe1c into master Dec 19, 2024
54 checks passed
@flowzone-app flowzone-app bot deleted the logs-agnostic-secondary-primary branch December 19, 2024 16:04
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