Skip to content

Commit

Permalink
chore: cache the instance status page for 60 seconds (#17539)
Browse files Browse the repository at this point in the history
* chore: cache the instance status page for 60 seconds

* add a note to the system overview tab

* Update UI snapshots for `chromium` (1)

* clear cache between tests

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
pauldambra and github-actions[bot] authored Sep 26, 2023
1 parent fd93ca4 commit 705d877
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions frontend/src/scenes/instance/SystemStatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { systemStatusLogic, InstanceStatusTabName } from './systemStatusLogic'
import { useActions, useValues } from 'kea'
import { PageHeader } from 'lib/components/PageHeader'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { IconOpenInNew } from 'lib/lemon-ui/icons'
import { IconInfo, IconOpenInNew } from 'lib/lemon-ui/icons'
import { OverviewTab } from 'scenes/instance/SystemStatus/OverviewTab'
import { InternalMetricsTab } from 'scenes/instance/SystemStatus/InternalMetricsTab'
import { SceneExport } from 'scenes/sceneTypes'
Expand All @@ -17,6 +17,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { FEATURE_FLAGS } from 'lib/constants'
import { KafkaInspectorTab } from './KafkaInspectorTab'
import { LemonTab, LemonTabs } from 'lib/lemon-ui/LemonTabs'
import { Tooltip } from 'lib/lemon-ui/Tooltip'

export const scene: SceneExport = {
component: SystemStatus,
Expand All @@ -33,7 +34,11 @@ export function SystemStatus(): JSX.Element {
let tabs = [
{
key: 'overview',
label: 'System overview',
label: (
<Tooltip title={<>System overview is cached for 60 seconds</>}>
System overview <IconInfo />
</Tooltip>
),
content: <OverviewTab />,
},
] as LemonTab<InstanceStatusTabName>[]
Expand Down
3 changes: 3 additions & 0 deletions posthog/api/instance_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from django.conf import settings
from django.db import connection
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
Expand Down Expand Up @@ -33,6 +35,7 @@ class InstanceStatusViewSet(viewsets.ViewSet):

permission_classes = [IsAuthenticated, SingleTenancyOrAdmin]

@method_decorator(cache_page(60))
def list(self, request: Request) -> Response:
redis_alive = is_redis_alive()
postgres_alive = is_postgres_alive()
Expand Down
1 change: 1 addition & 0 deletions posthog/settings/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ def add_recorder_js_headers(headers, path, url):
"^/api/organizations/@current/plugins/?$",
"^api/projects/@current/feature_flags/my_flags/?$",
"^/?api/projects/\\d+/query/?$",
"^/?api/instance_status/?$",
]
),
)
Expand Down
2 changes: 2 additions & 0 deletions posthog/test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest
import sqlparse
from django.apps import apps
from django.core.cache import cache
from django.db import connection, connections
from django.db.migrations.executor import MigrationExecutor
from django.test import TestCase, TransactionTestCase, override_settings
Expand Down Expand Up @@ -232,6 +233,7 @@ class APIBaseTest(TestMixin, ErrorResponsesMixin, DRFTestCase):
def setUp(self):
super().setUp()

cache.clear()
TEST_clear_cloud_cache(self.initial_cloud_mode)
TEST_clear_instance_license_cache()

Expand Down

0 comments on commit 705d877

Please sign in to comment.