Skip to content

Commit

Permalink
Add special migrations to instance status (#7024 pt. 7) (#7565)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yakkomajuri authored Dec 13, 2021
1 parent 763e9f1 commit 33c09ff
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frontend/src/layout/navigation/navigationLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export const navigationLogic = kea<navigationLogicType<WarningType>>({
}

// 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
Expand Down
26 changes: 25 additions & 1 deletion frontend/src/scenes/instance/SystemStatus/OverviewTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -16,15 +27,28 @@ function RenderValue(value: any): JSX.Element | string {
return value.toString()
}

function RenderMetric(metricRow: MetricRow): JSX.Element {
return (
<span>
{metricRow.metric}{' '}
{METRIC_KEY_TO_INTERNAL_LINK[metricRow.key] ? (
<Link to={METRIC_KEY_TO_INTERNAL_LINK[metricRow.key]}>
<IconOpenInNew style={{ verticalAlign: 'middle' }} />
</Link>
) : null}
</span>
)
}

export function OverviewTab(): JSX.Element {
const { overview, systemStatusLoading } = useValues(systemStatusLogic)
const { configOptions, preflightLoading } = useValues(preflightLogic)

const columns = [
{
title: 'Metric',
dataIndex: 'metric',
className: 'metric-column',
render: RenderMetric,
},
{
title: 'Value',
Expand Down
8 changes: 8 additions & 0 deletions posthog/api/instance_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions posthog/special_migrations/status.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 33c09ff

Please sign in to comment.