Skip to content

Commit

Permalink
fix: versions are not numbers, when will I ever learn (#21228)
Browse files Browse the repository at this point in the history
* fix: parsing versions but not stupid

* update tests

* unknown for safety
  • Loading branch information
pauldambra authored Mar 28, 2024
1 parent d929ca9 commit 3b67989
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 15 additions & 5 deletions plugin-server/src/main/ingestion-queues/session-recording/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ function readLibVersionFromHeaders(headers: MessageHeader[] | undefined): string
return typeof libVersionHeader === 'string' ? libVersionHeader : libVersionHeader?.toString()
}

function majorAndMinorVersionFrom(libVersion: string | undefined): number | undefined {
interface LibVersion {
major: number
minor: number
}

function parseVersion(libVersion: string | undefined): LibVersion | undefined {
try {
let majorString: string | undefined = undefined
let minorString: string | undefined = undefined
Expand All @@ -157,7 +162,12 @@ function majorAndMinorVersionFrom(libVersion: string | undefined): number | unde
}
const validMajor = majorString && !isNaN(parseInt(majorString))
const validMinor = minorString && !isNaN(parseInt(minorString))
return validMajor && validMinor ? parseFloat(`${majorString}.${minorString}`) : undefined
return validMajor && validMinor
? {
major: parseInt(majorString as string),
minor: parseInt(minorString as string),
}
: undefined
} catch (e) {
status.warn('⚠️', 'could_not_read_minor_lib_version', { libVersion })
return undefined
Expand Down Expand Up @@ -210,14 +220,14 @@ export const parseKafkaMessage = async (
// this has to be ahead of the payload parsing in case we start dropping traffic from older versions
if (!!ingestionWarningProducer && !!teamIdWithConfig.teamId) {
const libVersion = readLibVersionFromHeaders(message.headers)
const parsedVersion = majorAndMinorVersionFrom(libVersion)
const parsedVersion = parseVersion(libVersion)
/**
* We introduced SVG mutation throttling in version 1.74.0 fix: Recording throttling for SVG-like things (#758)
* and improvements like jitter on retry and better batching in session recording in earlier versions
* So, versions older than 1.75.0 can cause ingestion pressure or incidents
* because they send much more information and more messages for the same recording
*/
if (parsedVersion && parsedVersion <= 1.74) {
if (parsedVersion && parsedVersion.major === 1 && parsedVersion.minor < 75) {
counterLibVersionWarning.inc()

await captureIngestionWarning(
Expand All @@ -228,7 +238,7 @@ export const parseKafkaMessage = async (
libVersion,
parsedVersion,
},
{ key: libVersion || parsedVersion.toString() }
{ key: libVersion || 'unknown' }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ describe('session-recording utils', () => {
],
[
'three-part lib version that is recent enough means no call to capture ingestion warning',
[{ lib_version: '1.75.0' }],
[{ lib_version: '1.116.0' }],
[],
],
[
Expand All @@ -216,7 +216,7 @@ describe('session-recording utils', () => {
messages: [
expectedIngestionWarningMessage({
libVersion: '1.74.0',
parsedVersion: 1.74,
parsedVersion: { major: 1, minor: 74 },
}),
],
topic: 'clickhouse_ingestion_warnings_test',
Expand All @@ -236,7 +236,7 @@ describe('session-recording utils', () => {
messages: [
expectedIngestionWarningMessage({
libVersion: '1.32.0',
parsedVersion: 1.32,
parsedVersion: { major: 1, minor: 32 },
}),
],
topic: 'clickhouse_ingestion_warnings_test',
Expand Down

0 comments on commit 3b67989

Please sign in to comment.