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

fix: fewer version warnings #26942

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,35 +73,41 @@ describe('versionCheckerLogic', () => {
{ versionCount: 1, expectation: null },
{
versionCount: 11,
expectation: null,
},
{
versionCount: 51,
expectation: {
latestUsedVersion: '1.0.0',
latestAvailableVersion: '1.0.10',
numVersionsBehind: 10,
level: 'info',
latestAvailableVersion: '1.0.50',
numVersionsBehind: 50,
level: 'error',
},
},
{
versionCount: 15,
minorUsedVersion: 40,
versionCount: 1,
expectation: {
latestUsedVersion: '1.0.0',
latestAvailableVersion: '1.0.14',
numVersionsBehind: 14,
level: 'info',
latestAvailableVersion: '1.40.0',
numVersionsBehind: 40,
level: 'warning',
},
},
{
versionCount: 25,
majorUsedVersion: 2,
versionCount: 1,
expectation: {
latestUsedVersion: '1.0.0',
latestAvailableVersion: '1.0.24',
numVersionsBehind: 24,
level: 'error',
latestAvailableVersion: '2.0.0',
numVersionsBehind: 1,
level: 'info',
},
},
])('return a version warning if diff is great enough', async (options) => {
// TODO: How do we clear the persisted value?
const versionsList = Array.from({ length: options.versionCount }, (_, i) => ({
version: `1.0.${i}`,
version: `${options.majorUsedVersion || 1}.${options.minorUsedVersion || 0}.${i}`,
})).reverse()

useMockedVersions(
Expand Down Expand Up @@ -143,13 +149,14 @@ describe('versionCheckerLogic', () => {
},
{
usedVersions: [
{ version: '1.80.0', timestamp: '2023-01-01T12:00:00Z' },
{ version: '1.83.1-beta', timestamp: '2023-01-01T10:00:00Z' },
{ version: '1.84.0-delta', timestamp: '2023-01-01T08:00:00Z' },
{ version: '1.40.0', timestamp: '2023-01-01T12:00:00Z' },
{ version: '1.41.1-beta', timestamp: '2023-01-01T10:00:00Z' },
{ version: '1.42.0', timestamp: '2023-01-01T08:00:00Z' },
{ version: '1.42.0-delta', timestamp: '2023-01-01T08:00:00Z' },
],
expectation: {
latestUsedVersion: '1.84.0-delta',
numVersionsBehind: 1,
latestUsedVersion: '1.42.0',
numVersionsBehind: 42,
latestAvailableVersion: '1.84.0',
level: 'warning',
},
Expand Down
19 changes: 8 additions & 11 deletions frontend/src/lib/components/VersionChecker/versionCheckerLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const versionCheckerLogic = kea<versionCheckerLogicType>([

if (!warning && sdkVersions && latestAvailableVersion) {
const diff = diffVersions(latestAvailableVersion, latestUsedVersion)

if (diff && diff.diff > 0) {
// there's a difference between the latest used version and the latest available version

Expand All @@ -188,18 +189,14 @@ export const versionCheckerLogic = kea<versionCheckerLogicType>([
}

let level: 'warning' | 'info' | 'error' | undefined
if (diff.kind === 'major' || numVersionsBehind >= 20) {
if (diff.kind === 'major') {
level = 'info' // it is desirable to be on the latest major version, but not critical
Copy link
Contributor

Choose a reason for hiding this comment

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

I may be missing some context here, but isn't being a major version behind critical?

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 think not until we start deprecating the old versions... i guess we're very unlikely to increment a major version in web sdk... although more likely in mobile. easy to change if we figure out a better setup :)

} else if (diff.kind === 'minor') {
level = numVersionsBehind >= 40 ? 'warning' : undefined
}

if (level === undefined && numVersionsBehind >= 50) {
level = 'error'
} else if (diff.kind === 'minor' && diff.diff >= 15) {
level = 'warning'
} else if ((diff.kind === 'minor' && diff.diff >= 10) || numVersionsBehind >= 10) {
level = 'info'
} else if (latestUsedVersion.extra) {
// if we have an extra (alpha/beta/rc/etc.) version, we should always show a warning if they aren't on the latest
level = 'warning'
} else {
// don't warn for a small number of patch versions behind
level = undefined
}

// we check if there is a "latest user version string" to avoid returning odd data in unexpected cases
Expand Down
Loading