Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(metrics): default name and attribute lookbacks to 24 hours (#109890)

Frank Hamanda712bbba483a
diff --git a/products/metrics/backend/facade/api.py b/products/metrics/backend/facade/api.py
index 71dee707da8b..731a850365d4 100644
--- a/products/metrics/backend/facade/api.py
+++ b/products/metrics/backend/facade/api.py
@@ -360,7 +360,7 @@ def list_metric_attribute_keys(
recent window supply choices. Datapoint and resource attributes are merged
into one list (filters run with scope 'auto', so the split doesn't matter
to callers); `service_name` is always surfaced when it matches the search.
- The window defaults to the last 7 days. Returns `{"name": str,
+ The window defaults to the last 24 hours. Returns `{"name": str,
"value_count": int}` dicts. Raises `ValueError` for an out-of-range limit
or an inverted window.
"""
@@ -388,7 +388,7 @@ def list_metric_attribute_values(
for the filter bar's value autocomplete.
`service_name`/`service.name` read the first-class column, matching how
- filters on it execute. The window defaults to the last 7 days. Returns
+ filters on it execute. The window defaults to the last 24 hours. Returns
`{"id": str, "name": str, "count": int}` dicts. Raises `ValueError` for an
empty key, an out-of-range limit, or an inverted window.
"""
diff --git a/products/metrics/backend/metric_attributes_query_runner.py b/products/metrics/backend/metric_attributes_query_runner.py
index 2d71e0f3d4ef..468bfcc13fb6 100644
--- a/products/metrics/backend/metric_attributes_query_runner.py
+++ b/products/metrics/backend/metric_attributes_query_runner.py
@@ -31,7 +31,7 @@ _TIME_BUCKET_INTERVAL = dt.timedelta(hours=1)
# Without an explicit window, suggest from recent data only — same lookback the
# metric names picker uses.
-_DEFAULT_LOOKBACK = dt.timedelta(days=7)
+_DEFAULT_LOOKBACK = dt.timedelta(hours=24)
# Autocomplete tolerates partial results, so reads break at the budget instead
# of erroring the way the chart queries do.
diff --git a/products/metrics/backend/metric_names_query_runner.py b/products/metrics/backend/metric_names_query_runner.py
index 8b09afe7b855..d9206d6cf1e2 100644
--- a/products/metrics/backend/metric_names_query_runner.py
+++ b/products/metrics/backend/metric_names_query_runner.py
@@ -81,7 +81,7 @@ class MetricNamesQueryRunner:
*,
search: str = "",
limit: int = 100,
- lookback: dt.timedelta = dt.timedelta(days=7),
+ lookback: dt.timedelta = dt.timedelta(hours=24),
services: Sequence[str] = (),
include_sparklines: bool = True,
names: Sequence[str] = (),
diff --git a/products/metrics/backend/presentation/api.py b/products/metrics/backend/presentation/api.py
index 037fae2c5e38..f2abb77dacdd 100644
--- a/products/metrics/backend/presentation/api.py
+++ b/products/metrics/backend/presentation/api.py
@@ -527,7 +527,7 @@ class _MetricAttributeKeysParamsSerializer(serializers.Serializer):
required=False,
allow_null=True,
default=None,
- help_text="Lower bound (inclusive) of the window keys are suggested from. ISO 8601. Defaults to 7 days ago.",
+ help_text="Lower bound (inclusive) of the window keys are suggested from. ISO 8601. Defaults to 24 hours ago.",
)
dateTo = serializers.DateTimeField(
required=False,
@@ -560,7 +560,7 @@ class _MetricAttributeValuesParamsSerializer(serializers.Serializer):
required=False,
allow_null=True,
default=None,
- help_text="Lower bound (inclusive) of the window values are suggested from. ISO 8601. Defaults to 7 days ago.",
+ help_text="Lower bound (inclusive) of the window values are suggested from. ISO 8601. Defaults to 24 hours ago.",
)
dateTo = serializers.DateTimeField(
required=False,
diff --git a/products/metrics/backend/tests/test_metric_names_query_runner.py b/products/metrics/backend/tests/test_metric_names_query_runner.py
index c7ce705f3b8c..418d73e936a3 100644
--- a/products/metrics/backend/tests/test_metric_names_query_runner.py
+++ b/products/metrics/backend/tests/test_metric_names_query_runner.py
@@ -191,12 +191,12 @@ class TestMetricNamesQueryRunner(ClickhouseTestMixin, APIBaseTest):
self.assertEqual(runner.run(), [])
def test_lookback_excludes_old_data(self):
- old = timezone.now().replace(microsecond=0) - dt.timedelta(days=14)
+ old = timezone.now().replace(microsecond=0) - dt.timedelta(days=2)
recent = timezone.now().replace(microsecond=0) - dt.timedelta(hours=1)
_seed_point(team_id=self.team.id, metric_name="old.metric", value=1.0, timestamp=old)
_seed_point(team_id=self.team.id, metric_name="recent.metric", value=2.0, timestamp=recent)
- runner = MetricNamesQueryRunner(team=self.team, lookback=dt.timedelta(days=7))
+ runner = MetricNamesQueryRunner(team=self.team)
names = [row["name"] for row in runner.run()]
self.assertIn("recent.metric", names)
self.assertNotIn("old.metric", names)
diff --git a/products/metrics/frontend/components/MetricNameFilter.tsx b/products/metrics/frontend/components/MetricNameFilter.tsx
index 37a2e6aabda2..b74fa14b7ee5 100644
--- a/products/metrics/frontend/components/MetricNameFilter.tsx
+++ b/products/metrics/frontend/components/MetricNameFilter.tsx
@@ -134,7 +134,7 @@ function MetricNameFilterInner({
<div className="p-2 text-muted text-center text-xs">Loading metrics…</div>
) : items.length === 0 ? (
<div className="p-2 text-muted text-center text-xs">
- {search ? 'No metrics match this search.' : 'No metrics ingested in the last 7 days.'}
+ {search ? 'No metrics match this search.' : 'No metrics ingested in the last 24 hours.'}
</div>
) : (
<List<OptionRowData>
diff --git a/products/metrics/frontend/generated/api.schemas.ts b/products/metrics/frontend/generated/api.schemas.ts
index 924c18e49ac1..d5a8d2ad8d51 100644
--- a/products/metrics/frontend/generated/api.schemas.ts
+++ b/products/metrics/frontend/generated/api.schemas.ts
@@ -838,7 +838,7 @@ export interface _MetricCatalogValuesParamsApi {
export type MetricsAttributeValuesRetrieveParams = {
/**
- * Lower bound (inclusive) of the window values are suggested from. ISO 8601. Defaults to 7 days ago.
+ * Lower bound (inclusive) of the window values are suggested from. ISO 8601. Defaults to 24 hours ago.
* @nullable
*/
dateFrom?: string | null
@@ -868,7 +868,7 @@ export type MetricsAttributeValuesRetrieveParams = {
export type MetricsAttributesRetrieveParams = {
/**
- * Lower bound (inclusive) of the window keys are suggested from. ISO 8601. Defaults to 7 days ago.
+ * Lower bound (inclusive) of the window keys are suggested from. ISO 8601. Defaults to 24 hours ago.
* @nullable
*/
dateFrom?: string | null
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 6074815b56e4..2b109cbe9661 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -119388,7 +119388,7 @@ export namespace Schemas {
export type MetricsAttributeValuesRetrieveParams = {
/**
- * Lower bound (inclusive) of the window values are suggested from. ISO 8601. Defaults to 7 days ago.
+ * Lower bound (inclusive) of the window values are suggested from. ISO 8601. Defaults to 24 hours ago.
* @nullable
*/
dateFrom?: string | null;
@@ -119418,7 +119418,7 @@ export namespace Schemas {
export type MetricsAttributesRetrieveParams = {
/**
- * Lower bound (inclusive) of the window keys are suggested from. ISO 8601. Defaults to 7 days ago.
+ * Lower bound (inclusive) of the window keys are suggested from. ISO 8601. Defaults to 24 hours ago.
* @nullable
*/
dateFrom?: string | null;