From 33c09ff8b9c340e61d887525f3995663d25b6213 Mon Sep 17 00:00:00 2001 From: Yakko Majuri <38760734+yakkomajuri@users.noreply.github.com> Date: Mon, 13 Dec 2021 19:05:59 +0000 Subject: [PATCH] Add special migrations to instance status (#7024 pt. 7) (#7565) * add special migration definition and example * types * special migrations runner * fix tests * fix tests 2 * add clickhouse runner * add temp fix for tests * wip * add special migrations api (#7448) * wip new structure * update example sourcing * Update .gitignore * yet another wip structure * code quality * cypress * test docker image build * implement resumable ops * code quality * add comments * add warning * add conditional requirements for migration * add comment on is_required * add dependency map * wip dependencies and run migration on startup * code quality * fix bugs * fix more bugs * format * types * remove api from this branch * types * types * update clickhouse script * add is_migration_in_range util * fix type * Add special migrations API * fix api * update api with new columns * fix runner * add AUTO_START_SPECIAL_MIGRATIONS env var * reset migration on start * Special migrations UI (#7054 pt. 6) (#7493) * update UI with new cols * fix UI * new UI statuses * cleanup * wip per op rollback * add refresh button * wip tests * prevent accidental status rollback * finish api tests * Update bin/tests * add utils and definition test * update example with rollback per op * wip test special migration * add first runner tests * add runner tests * add util for code paths * fix test * fix types * fix types again * cleanup * cleanup * add periodic healthcheck task tests * remove unused imports * safer row updates * fix coalescing none checks * code quality * add handling for non-staff users * Add special migrations to instance status * add docstrings * fix * fix deploys issue * update scripts * add delay * address reviews * address review comments * address review comments * address final comments * fix import error * fix tests * remove unused imports * fix tests * fix task test * remove unused return value * remove unused special migrations code from migrate_clickhouse * tweaks to support fresh deployments * make instance first user staff * fix import --- .../src/layout/navigation/navigationLogic.ts | 2 +- .../instance/SystemStatus/OverviewTab.tsx | 26 ++++++++++++++++++- posthog/api/instance_status.py | 8 ++++++ posthog/special_migrations/status.py | 15 +++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 posthog/special_migrations/status.py diff --git a/frontend/src/layout/navigation/navigationLogic.ts b/frontend/src/layout/navigation/navigationLogic.ts index 609e0aa927ef6..21f9886fd1740 100644 --- a/frontend/src/layout/navigation/navigationLogic.ts +++ b/frontend/src/layout/navigation/navigationLogic.ts @@ -132,7 +132,7 @@ export const navigationLogic = kea>({ } // if you have status metrics these three must have `value: true` - const aliveMetrics = ['redis_alive', 'db_alive', 'plugin_sever_alive'] + const aliveMetrics = ['redis_alive', 'db_alive', 'plugin_sever_alive', 'special_migrations_ok'] const aliveSignals = statusMetrics .filter((sm) => sm.key && aliveMetrics.includes(sm.key)) .filter((sm) => sm.value).length diff --git a/frontend/src/scenes/instance/SystemStatus/OverviewTab.tsx b/frontend/src/scenes/instance/SystemStatus/OverviewTab.tsx index 90752742d362b..6994bb31ab80e 100644 --- a/frontend/src/scenes/instance/SystemStatus/OverviewTab.tsx +++ b/frontend/src/scenes/instance/SystemStatus/OverviewTab.tsx @@ -5,6 +5,17 @@ import { useValues } from 'kea' import { SystemStatusSubrows } from '~/types' import { preflightLogic } from 'scenes/PreflightCheck/logic' import { IconOpenInNew } from 'lib/components/icons' +import { Link } from 'lib/components/Link' + +interface MetricRow { + metric: string + key: string + value: any +} + +const METRIC_KEY_TO_INTERNAL_LINK = { + special_migrations_ok: '/instance/special_migrations', +} function RenderValue(value: any): JSX.Element | string { if (typeof value === 'boolean') { @@ -16,6 +27,19 @@ function RenderValue(value: any): JSX.Element | string { return value.toString() } +function RenderMetric(metricRow: MetricRow): JSX.Element { + return ( + + {metricRow.metric}{' '} + {METRIC_KEY_TO_INTERNAL_LINK[metricRow.key] ? ( + + + + ) : null} + + ) +} + export function OverviewTab(): JSX.Element { const { overview, systemStatusLoading } = useValues(systemStatusLogic) const { configOptions, preflightLoading } = useValues(preflightLogic) @@ -23,8 +47,8 @@ export function OverviewTab(): JSX.Element { const columns = [ { title: 'Metric', - dataIndex: 'metric', className: 'metric-column', + render: RenderMetric, }, { title: 'Value', diff --git a/posthog/api/instance_status.py b/posthog/api/instance_status.py index 2a0b4c6c30ad7..3e482b5bf8bb9 100644 --- a/posthog/api/instance_status.py +++ b/posthog/api/instance_status.py @@ -11,6 +11,7 @@ from posthog.internal_metrics.team import get_internal_metrics_dashboards from posthog.models import Element, Event, SessionRecordingEvent from posthog.permissions import OrganizationAdminAnyPermissions, SingleTenancyOrAdmin +from posthog.special_migrations.status import special_migrations_ok from posthog.utils import ( dict_from_cursor_fetchall, get_helm_info_env, @@ -122,6 +123,13 @@ def list(self, request: Request) -> Response: "value": f"{session_recording_event_table_count} rows (~{session_recording_event_table_size})", } ) + metrics.append( + { + "key": "special_migrations_ok", + "metric": "Special migrations up-to-date", + "value": special_migrations_ok(), + } + ) if is_clickhouse_enabled(): from ee.clickhouse.system_status import system_status diff --git a/posthog/special_migrations/status.py b/posthog/special_migrations/status.py new file mode 100644 index 0000000000000..9407c3601535b --- /dev/null +++ b/posthog/special_migrations/status.py @@ -0,0 +1,15 @@ +def special_migrations_ok() -> bool: + from posthog.models.special_migration import MigrationStatus, SpecialMigration + from posthog.special_migrations.runner import is_posthog_version_compatible + + for migration in SpecialMigration.objects.all(): + migration_completed_or_running = migration.status in [ + MigrationStatus.CompletedSuccessfully, + MigrationStatus.Running, + ] + migration_in_range = is_posthog_version_compatible(migration.posthog_min_version, migration.posthog_max_version) + + if not migration_completed_or_running and migration_in_range: + return False + + return True