Skip to content

Commit

Permalink
Add directories to file watcher and also populate kind for AI generat…
Browse files Browse the repository at this point in the history
…ed metrics view (rilldata#4587)

* Update AI metrics view to populate kind

* Add folders to file watcher API
  • Loading branch information
AdityaHegde authored Apr 12, 2024
1 parent 9784fb5 commit 11443a2
Show file tree
Hide file tree
Showing 9 changed files with 973 additions and 949 deletions.
1,885 changes: 947 additions & 938 deletions proto/gen/rill/runtime/v1/api.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions proto/gen/rill/runtime/v1/api.pb.validate.go

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

2 changes: 2 additions & 0 deletions proto/gen/rill/runtime/v1/runtime.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6063,6 +6063,8 @@ definitions:
$ref: '#/definitions/v1FileEvent'
path:
type: string
isDir:
type: boolean
title: Response message for RuntimeService.WatchFiles
v1WatchLogsResponse:
type: object
Expand Down
1 change: 1 addition & 0 deletions proto/rill/runtime/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ message WatchFilesRequest {
message WatchFilesResponse {
FileEvent event = 1;
string path = 2;
bool is_dir = 3;
}

// Request message for RuntimeService.GetFile
Expand Down
3 changes: 3 additions & 0 deletions runtime/server/generate_metrics_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (s *Server) generateMetricsViewYAMLWithAI(ctx context.Context, instanceID,
}

// The AI only generates metrics. We fill in the other properties using the simple logic.
doc.Kind = "metrics_view"
doc.TimeDimension = generateMetricsViewYAMLSimpleTimeDimension(tbl.Schema)
doc.Dimensions = generateMetricsViewYAMLSimpleDimensions(tbl.Schema)
if isModel {
Expand Down Expand Up @@ -307,6 +308,7 @@ Give me up to 10 suggested metrics using the %q SQL dialect based on the table n
// generateMetricsViewYAMLSimple generates a simple metrics view YAML definition from a table schema.
func generateMetricsViewYAMLSimple(connector string, tbl *drivers.Table, isDefaultConnector, isModel bool, schema *runtimev1.StructType) (string, error) {
doc := &metricsViewYAML{
Kind: "metrics_view",
Title: identifierToTitle(tbl.Name),
TimeDimension: generateMetricsViewYAMLSimpleTimeDimension(schema),
Dimensions: generateMetricsViewYAMLSimpleDimensions(schema),
Expand Down Expand Up @@ -385,6 +387,7 @@ func generateMetricsViewYAMLSimpleMeasures(schema *runtimev1.StructType) []*metr
// metricsViewYAML is a struct for generating a metrics view YAML file.
// We do not use the parser's structs since they are not suitable for generating pretty output YAML.
type metricsViewYAML struct {
Kind string `yaml:"kind,omitempty"`
Title string `yaml:"title,omitempty"`
Connector string `yaml:"connector,omitempty"`
Database string `yaml:"database,omitempty"`
Expand Down
18 changes: 9 additions & 9 deletions runtime/server/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ func (s *Server) WatchFiles(req *runtimev1.WatchFilesRequest, ss runtimev1.Runti
defer release()

if req.Replay {
files, err := repo.ListRecursive(ss.Context(), "**", true)
files, err := repo.ListRecursive(ss.Context(), "**", false)
if err != nil {
return err
}
for _, f := range files {
err = ss.Send(&runtimev1.WatchFilesResponse{
Event: runtimev1.FileEvent_FILE_EVENT_WRITE,
Path: f.Path,
IsDir: f.IsDir,
})
if err != nil {
return err
Expand All @@ -87,14 +88,13 @@ func (s *Server) WatchFiles(req *runtimev1.WatchFilesRequest, ss runtimev1.Runti

return repo.Watch(ss.Context(), func(events []drivers.WatchEvent) {
for _, event := range events {
if !event.Dir {
err := ss.Send(&runtimev1.WatchFilesResponse{
Event: event.Type,
Path: event.Path,
})
if err != nil {
s.logger.Info("failed to send watch event", zap.Error(err))
}
err := ss.Send(&runtimev1.WatchFilesResponse{
Event: event.Type,
Path: event.Path,
IsDir: event.Dir,
})
if err != nil {
s.logger.Info("failed to send watch event", zap.Error(err))
}
}
})
Expand Down
6 changes: 6 additions & 0 deletions web-common/src/proto/gen/rill/runtime/v1/api_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,11 @@ export class WatchFilesResponse extends Message<WatchFilesResponse> {
*/
path = "";

/**
* @generated from field: bool is_dir = 3;
*/
isDir = false;

constructor(data?: PartialMessage<WatchFilesResponse>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -1087,6 +1092,7 @@ export class WatchFilesResponse extends Message<WatchFilesResponse> {
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "event", kind: "enum", T: proto3.getEnumType(FileEvent) },
{ no: 2, name: "path", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "is_dir", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): WatchFilesResponse {
Expand Down
4 changes: 2 additions & 2 deletions web-common/src/proto/gen/rill/ui/v1/dashboard_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class DashboardState extends Message<DashboardState> {
chartType?: string;

/**
* *
*
* Pivot related fields
*
* @generated from field: optional bool pivot_is_active = 22;
Expand Down Expand Up @@ -352,7 +352,7 @@ proto3.util.setEnumType(DashboardState_LeaderboardSortDirection, "rill.ui.v1.Das
]);

/**
* *
*
* SortType is used to determine how to sort the leaderboard
* and dimension detail table, as well as where to place the
* sort arrow.
Expand Down
1 change: 1 addition & 0 deletions web-common/src/runtime-client/gen/index.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ export interface V1WatchLogsResponse {
export interface V1WatchFilesResponse {
event?: V1FileEvent;
path?: string;
isDir?: boolean;
}

export interface V1UnpackExampleResponse {
Expand Down

0 comments on commit 11443a2

Please sign in to comment.