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: narrow generated API types #5735

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
3,568 changes: 1,784 additions & 1,784 deletions proto/gen/rill/runtime/v1/queries.pb.go

Large diffs are not rendered by default.

29 changes: 1 addition & 28 deletions proto/gen/rill/runtime/v1/queries.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2,208 changes: 1,107 additions & 1,101 deletions proto/gen/rill/runtime/v1/resources.pb.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions proto/gen/rill/runtime/v1/runtime.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2886,6 +2886,8 @@ definitions:
uri:
type: string
title: Dimensions are columns to filter and group by
required:
- name
MetricsViewSpecMeasureType:
type: string
enum:
Expand Down Expand Up @@ -2931,6 +2933,9 @@ definitions:
validPercentOfTotal:
type: boolean
title: Measures are aggregated computed values
required:
- name
- expression
MetricsViewSpecMeasureWindow:
type: object
properties:
Expand Down Expand Up @@ -4730,13 +4735,17 @@ definitions:
type: object
properties:
dimensionValue:
type: string
title: Not optional, not null
measureValues:
type: array
items:
type: object
$ref: '#/definitions/v1MetricsViewComparisonValue'
title: Not optional, not null
required:
- dimensionValue
- measureValues
v1MetricsViewComparisonSort:
type: object
properties:
Expand Down Expand Up @@ -4978,6 +4987,9 @@ definitions:
description: |-
Available time zones list preferred time zones using IANA location identifiers.
Deprecated: Now defined in the Explore resource.
required:
- dimensions
- measures
v1MetricsViewState:
type: object
properties:
Expand All @@ -4989,6 +5001,8 @@ definitions:
description: |-
Streaming is true if the underlying data may change without the metrics view's spec/state version changing.
It's set to true if the metrics view is based on an externally managed table.
required:
- validSpec
v1MetricsViewTimeRangeResponse:
type: object
properties:
Expand Down Expand Up @@ -5162,6 +5176,9 @@ definitions:
$ref: '#/definitions/v1MetricsViewSpec'
state:
$ref: '#/definitions/v1MetricsViewState'
required:
- spec
- state
v1Migration:
type: object
properties:
Expand Down
5 changes: 3 additions & 2 deletions proto/rill/runtime/v1/queries.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "rill/runtime/v1/expression.proto";
import "rill/runtime/v1/schema.proto";
import "rill/runtime/v1/time_grain.proto";
import "validate/validate.proto";
import "google/api/field_behavior.proto";

service QueryService {
// Query runs a SQL query against the instance's OLAP datastore.
Expand Down Expand Up @@ -561,9 +562,9 @@ message MetricsViewComparisonSort {

message MetricsViewComparisonRow {
// Not optional, not null
google.protobuf.Value dimension_value = 1;
string dimension_value = 1 [(google.api.field_behavior) = REQUIRED];
// Not optional, not null
repeated MetricsViewComparisonValue measure_values = 2;
repeated MetricsViewComparisonValue measure_values = 2 [(google.api.field_behavior) = REQUIRED];
}

message MetricsViewComparisonValue {
Expand Down
19 changes: 10 additions & 9 deletions proto/rill/runtime/v1/resources.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "rill/runtime/v1/export_format.proto";
import "rill/runtime/v1/expression.proto";
import "rill/runtime/v1/schema.proto";
import "rill/runtime/v1/time_grain.proto";
import "google/api/field_behavior.proto";

enum ReconcileStatus {
RECONCILE_STATUS_UNSPECIFIED = 0;
Expand Down Expand Up @@ -153,14 +154,14 @@ message ModelState {
}

message MetricsViewV2 {
MetricsViewSpec spec = 1;
MetricsViewState state = 2;
MetricsViewSpec spec = 1 [(google.api.field_behavior) = REQUIRED];
MetricsViewState state = 2 [(google.api.field_behavior) = REQUIRED];
}

message MetricsViewSpec {
// Dimensions are columns to filter and group by
message DimensionV2 {
string name = 1;
string name = 1 [(google.api.field_behavior) = REQUIRED];
string column = 2;
string expression = 6;
string label = 3;
Expand Down Expand Up @@ -192,8 +193,8 @@ message MetricsViewSpec {
}
// Measures are aggregated computed values
message MeasureV2 {
string name = 1;
string expression = 2;
string name = 1 [(google.api.field_behavior) = REQUIRED];
string expression = 2 [(google.api.field_behavior) = REQUIRED];
MeasureType type = 8;
MeasureWindow window = 9;
repeated DimensionSelector per_dimensions = 10;
Expand Down Expand Up @@ -227,9 +228,9 @@ message MetricsViewSpec {
// Expression to evaluate a watermark for the metrics view. If not set, the watermark defaults to max(time_dimension).
string watermark_expression = 20;
// Dimensions in the metrics view
repeated DimensionV2 dimensions = 6;
repeated DimensionV2 dimensions = 6 [(google.api.field_behavior) = REQUIRED];
// Measures in the metrics view
repeated MeasureV2 measures = 7;
repeated MeasureV2 measures = 7 [(google.api.field_behavior) = REQUIRED];
// Security for the metrics view
repeated SecurityRule security_rules = 23;
// ISO 8601 weekday number to use as the base for time aggregations by week. Defaults to 1 (Monday).
Expand Down Expand Up @@ -311,7 +312,7 @@ message SecurityRuleRowFilter {

message MetricsViewState {
// Valid spec is a (potentially previous) version of the spec that is known to currently be valid.
MetricsViewSpec valid_spec = 1;
MetricsViewSpec valid_spec = 1 [(google.api.field_behavior) = REQUIRED];
// Streaming is true if the underlying data may change without the metrics view's spec/state version changing.
// It's set to true if the metrics view is based on an externally managed table.
bool streaming = 2;
Expand Down Expand Up @@ -722,4 +723,4 @@ message ConnectorState {
message ConnectorV2 {
ConnectorSpec spec = 1;
ConnectorState state = 2;
}
}
49 changes: 29 additions & 20 deletions web-admin/src/features/alerts/EditAlert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,39 @@
} from "@rilldata/web-common/components/dialog-v2";
import GuardedDialog from "@rilldata/web-common/components/dialog-v2/GuardedDialog.svelte";
import EditAlertForm from "@rilldata/web-common/features/alerts/EditAlertForm.svelte";
import { useMetricsView } from "@rilldata/web-common/features/dashboards/selectors";
import type { V1AlertSpec } from "@rilldata/web-common/runtime-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import Button from "web-common/src/components/button/Button.svelte";

export let alertSpec: V1AlertSpec;
export let metricsViewName: string;

$: ({ instanceId } = $runtime);
$: metricsViewSpecQuery = useMetricsView(instanceId, metricsViewName);
$: validSpec = $metricsViewSpecQuery.data;
</script>

<GuardedDialog
title="Close without saving?"
description="You haven’t saved changes to this alert yet, so closing this window will lose your work."
confirmLabel="Close"
cancelLabel="Keep editing"
let:onCancel
let:onClose
>
<DialogTrigger asChild let:builder>
<Button type="secondary" builders={[builder]}>Edit</Button>
</DialogTrigger>
<DialogContent class="p-0 m-0 w-[802px] max-w-fit" noClose>
<EditAlertForm
{alertSpec}
on:cancel={onCancel}
on:close={onClose}
{metricsViewName}
/>
</DialogContent>
</GuardedDialog>
{#if validSpec}
<GuardedDialog
title="Close without saving?"
description="You haven’t saved changes to this alert yet, so closing this window will lose your work."
confirmLabel="Close"
cancelLabel="Keep editing"
let:onCancel
let:onClose
>
<DialogTrigger asChild let:builder>
<Button type="secondary" builders={[builder]}>Edit</Button>
</DialogTrigger>
<DialogContent class="p-0 m-0 w-[802px] max-w-fit" noClose>
<EditAlertForm
defaultTimeRange={validSpec.defaultTimeRange}
{alertSpec}
on:cancel={onCancel}
on:close={onClose}
{metricsViewName}
/>
</DialogContent>
</GuardedDialog>
{/if}
9 changes: 7 additions & 2 deletions web-common/src/features/alerts/BaseAlertForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,16 @@
}
currentTabIndex += 1;

if (isEditForm || currentTabIndex !== 2 || $touched.name) {
if (
isEditForm ||
currentTabIndex !== 2 ||
$touched.name ||
!$metricsView.data
) {
return;
}
// if the user came to the delivery tab and name was not changed then auto generate it
const name = generateAlertName($form, $metricsView.data ?? {});
const name = generateAlertName($form, $metricsView.data);
if (!name) return;
$form.name = name;
}
Expand Down
19 changes: 13 additions & 6 deletions web-common/src/features/alerts/CreateAlertForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,30 @@
import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus";
import { runtime } from "../../runtime-client/runtime-store";
import BaseAlertForm from "./BaseAlertForm.svelte";
import { useMetricsView } from "../dashboards/selectors";

const user = createAdminServiceGetCurrentUser();
const createAlert = createAdminServiceCreateAlert();
$: organization = $page.params.organization;
$: project = $page.params.project;

const queryClient = useQueryClient();
const dispatch = createEventDispatcher();

const {
metricsViewName,
dashboardStore,

selectors: {
timeRangeSelectors: { timeControlsState },
},
} = getStateManagers();
const timeControls = get(timeControlsState);

$: ({ organization, project } = $page.params);

$: metricsViewQuery = useMetricsView($runtime.instanceId, $metricsViewName);

$: metricsView = $metricsViewQuery.data;

// Set defaults depending on UI state
// if in TDD take active measure and comparison dimension
// If expanded leaderboard, take first dimension and active dimensions
Expand All @@ -56,14 +63,14 @@
}

// TODO: get metrics view spec
const timeRange = mapTimeRange(timeControls, {});
const comparisonTimeRange = mapComparisonTimeRange(
$: timeRange = mapTimeRange(timeControls, metricsView?.defaultTimeRange);
$: comparisonTimeRange = mapComparisonTimeRange(
$dashboardStore,
timeControls,
timeRange,
);

const formState = createForm<AlertFormValues>({
$: formState = createForm<AlertFormValues>({
initialValues: {
name: "",
measure:
Expand Down Expand Up @@ -158,7 +165,7 @@
},
});

const { form } = formState;
$: form = formState.form;
$: hasSlackNotifier = getHasSlackConnection($runtime.instanceId);
$: if ($hasSlackNotifier.data) {
$form["enableSlackNotification"] = true;
Expand Down
30 changes: 12 additions & 18 deletions web-common/src/features/alerts/EditAlertForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
extractAlertFormValues,
extractAlertNotification,
} from "@rilldata/web-common/features/alerts/extract-alert-form-values";
import {
useMetricsView,
useMetricsViewTimeRange,
} from "@rilldata/web-common/features/dashboards/selectors";
import { useQueryClient } from "@tanstack/svelte-query";
import { useMetricsViewTimeRange } from "@rilldata/web-common/features/dashboards/selectors";
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient";
import { createEventDispatcher } from "svelte";
import { createForm } from "svelte-forms-lib";
import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus";
Expand All @@ -31,25 +28,22 @@

export let alertSpec: V1AlertSpec;
export let metricsViewName: string;
export let defaultTimeRange: string | undefined;

const editAlert = createAdminServiceEditAlert();
const queryClient = useQueryClient();
const dispatch = createEventDispatcher();

$: organization = $page.params.organization;
$: project = $page.params.project;
$: alertName = $page.params.alert;
$: ({ instanceId } = $runtime);

$: ({ project, alert: alertName, organization } = $page.params);
const queryArgsJson = JSON.parse(
(alertSpec.resolverProperties?.query_args_json ??
alertSpec.queryArgsJson) as string,
) as V1MetricsViewAggregationRequest;

$: metricsViewSpec = useMetricsView($runtime?.instanceId, metricsViewName);
$: timeRange = useMetricsViewTimeRange(
$runtime?.instanceId,
metricsViewName,
{ query: { queryClient } },
);
$: timeRange = useMetricsViewTimeRange(instanceId, metricsViewName, {
query: { queryClient },
});

const formState = createForm<AlertFormValues>({
initialValues: {
Expand All @@ -59,7 +53,7 @@
...extractAlertNotification(alertSpec),
...extractAlertFormValues(
queryArgsJson,
$metricsViewSpec?.data ?? {},
defaultTimeRange,
$timeRange?.data ?? {},
),
},
Expand Down Expand Up @@ -112,10 +106,10 @@
},
});
const { form } = formState;
$: if ($metricsViewSpec?.data && $timeRange?.data) {
$: if ($timeRange?.data) {
const formValues = extractAlertFormValues(
queryArgsJson,
$metricsViewSpec.data,
defaultTimeRange,
$timeRange.data,
);
for (const fk in formValues) {
Expand Down
Loading
Loading