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

Refactor title and label to display_name #5928

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions admin/auth_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type IssueMagicAuthTokenOptions struct {
FilterJSON string
Fields []string
State string
Title string
DisplayName string
}

// IssueMagicAuthToken generates and persists a new magic auth token for a project.
Expand All @@ -202,7 +202,7 @@ func (s *Service) IssueMagicAuthToken(ctx context.Context, opts *IssueMagicAuthT
FilterJSON: opts.FilterJSON,
Fields: opts.Fields,
State: opts.State,
Title: opts.Title,
DisplayName: opts.DisplayName,
})
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ type MagicAuthToken struct {
FilterJSON string `db:"filter_json"`
Fields []string `db:"fields"`
State string `db:"state"`
Title string `db:"title"`
DisplayName string `db:"display_name"`
}

// MagicAuthTokenWithUser is a MagicAuthToken with additional information about the user who created it.
Expand All @@ -659,7 +659,7 @@ type InsertMagicAuthTokenOptions struct {
FilterJSON string
Fields []string
State string
Title string
DisplayName string
}

// AuthClient is a client that requests and consumes auth tokens.
Expand Down
1 change: 1 addition & 0 deletions admin/database/postgres/migrations/0049.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE magic_auth_tokens RENAME COLUMN title TO display_name;
4 changes: 2 additions & 2 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,9 +1168,9 @@ func (c *connection) InsertMagicAuthToken(ctx context.Context, opts *database.In

res := &magicAuthTokenDTO{}
err = c.getDB(ctx).QueryRowxContext(ctx, `
INSERT INTO magic_auth_tokens (id, secret_hash, secret, secret_encryption_key_id, project_id, expires_on, created_by_user_id, attributes, resource_type, resource_name, filter_json, fields, state, title)
INSERT INTO magic_auth_tokens (id, secret_hash, secret, secret_encryption_key_id, project_id, expires_on, created_by_user_id, attributes, resource_type, resource_name, filter_json, fields, state, display_name)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *`,
opts.ID, opts.SecretHash, encSecret, encKeyID, opts.ProjectID, opts.ExpiresOn, opts.CreatedByUserID, opts.Attributes, opts.ResourceType, opts.ResourceName, opts.FilterJSON, opts.Fields, opts.State, opts.Title,
opts.ID, opts.SecretHash, encSecret, encKeyID, opts.ProjectID, opts.ExpiresOn, opts.CreatedByUserID, opts.Attributes, opts.ResourceType, opts.ResourceName, opts.FilterJSON, opts.Fields, opts.State, opts.DisplayName,
).StructScan(res)
if err != nil {
return nil, parseErr("magic auth token", err)
Expand Down
27 changes: 14 additions & 13 deletions admin/server/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (s *Server) CreateAlert(ctx context.Context, req *adminv1.CreateAlertReques
return nil, status.Error(codes.InvalidArgument, err.Error())
}

name, err := s.generateAlertName(ctx, depl, req.Options.Title)
name, err := s.generateAlertName(ctx, depl, req.Options.DisplayName)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
Expand Down Expand Up @@ -443,7 +443,7 @@ func (s *Server) yamlForManagedAlert(opts *adminv1.AlertOptions, ownerUserID str
res.Type = "alert"
// Trigger the alert when the metrics view refreshes.
res.Refs = []string{fmt.Sprintf("MetricsView/%s", opts.MetricsViewName)}
res.Title = opts.Title
res.DisplayName = opts.DisplayName
res.Watermark = "inherit"
res.Intervals.Duration = opts.IntervalDuration
if opts.Resolver != "" {
Expand Down Expand Up @@ -485,7 +485,7 @@ func (s *Server) yamlForCommittedAlert(opts *adminv1.AlertOptions) ([]byte, erro
res.Type = "alert"
// Trigger the alert when the metrics view refreshes.
res.Refs = []string{fmt.Sprintf("MetricsView/%s", opts.MetricsViewName)}
res.Title = opts.Title
res.DisplayName = opts.DisplayName
res.Watermark = "inherit"
res.Intervals.Duration = opts.IntervalDuration
if opts.Resolver != "" {
Expand All @@ -507,12 +507,12 @@ func (s *Server) yamlForCommittedAlert(opts *adminv1.AlertOptions) ([]byte, erro
return yaml.Marshal(res)
}

// generateAlertName generates a random alert name with the title as a seed.
// generateAlertName generates a random alert name with the display name as a seed.
// Example: "My alert!" -> "my-alert-5b3f7e1a".
// It verifies that the name is not taken (the random component makes any collision unlikely, but we check to be sure).
func (s *Server) generateAlertName(ctx context.Context, depl *database.Deployment, title string) (string, error) {
func (s *Server) generateAlertName(ctx context.Context, depl *database.Deployment, displayName string) (string, error) {
for i := 0; i < 5; i++ {
name := randomAlertName(title)
name := randomAlertName(displayName)

_, err := s.admin.LookupAlert(ctx, depl, name)
if err != nil {
Expand All @@ -532,8 +532,8 @@ var alertNameToDashCharsRegexp = regexp.MustCompile(`[ _]+`)

var alertNameExcludeCharsRegexp = regexp.MustCompile(`[^a-zA-Z0-9-]+`)

func randomAlertName(title string) string {
name := alertNameToDashCharsRegexp.ReplaceAllString(title, "-")
func randomAlertName(displayName string) string {
name := alertNameToDashCharsRegexp.ReplaceAllString(displayName, "-")
name = alertNameExcludeCharsRegexp.ReplaceAllString(name, "")
name = strings.ToLower(name)
name = strings.Trim(name, "-")
Expand All @@ -547,11 +547,12 @@ func randomAlertName(title string) string {

// alertYAML is derived from rillv1.AlertYAML, but adapted for generating (as opposed to parsing) the alert YAML.
type alertYAML struct {
Type string `yaml:"type"`
Refs []string `yaml:"refs"`
Title string `yaml:"title"`
Watermark string `yaml:"watermark"`
Intervals struct {
Type string `yaml:"type"`
Refs []string `yaml:"refs"`
DisplayName string `yaml:"display_name"`
Title string `yaml:"title,omitempty"` // Deprecated: replaced by display_name, but preserved for backwards compatibility
Watermark string `yaml:"watermark"`
Intervals struct {
Duration string `yaml:"duration"`
} `yaml:"intervals"`
Data map[string]any `yaml:"data,omitempty"`
Expand Down
5 changes: 3 additions & 2 deletions admin/server/magic_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (s *Server) IssueMagicAuthToken(ctx context.Context, req *adminv1.IssueMagi
observability.AddRequestAttributes(ctx,
attribute.String("args.organization", req.Organization),
attribute.String("args.project", req.Project),
attribute.String("args.display_name", req.DisplayName),
attribute.String("args.resource_type", req.ResourceType),
attribute.String("args.resource_name", req.ResourceName),
)
Expand All @@ -54,7 +55,7 @@ func (s *Server) IssueMagicAuthToken(ctx context.Context, req *adminv1.IssueMagi
ResourceName: req.ResourceName,
Fields: req.Fields,
State: req.State,
Title: req.Title,
DisplayName: req.DisplayName,
}

if req.TtlMinutes != 0 {
Expand Down Expand Up @@ -288,7 +289,7 @@ func (s *Server) magicAuthTokenToPB(tkn *database.MagicAuthTokenWithUser, org *d
Filter: filter,
Fields: tkn.Fields,
State: tkn.State,
Title: tkn.Title,
DisplayName: tkn.DisplayName,
}
if tkn.ExpiresOn != nil {
res.ExpiresOn = timestamppb.New(*tkn.ExpiresOn)
Expand Down
25 changes: 13 additions & 12 deletions admin/server/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *Server) CreateReport(ctx context.Context, req *adminv1.CreateReportRequ
return nil, status.Error(codes.InvalidArgument, err.Error())
}

name, err := s.generateReportName(ctx, depl, req.Options.Title)
name, err := s.generateReportName(ctx, depl, req.Options.DisplayName)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
Expand Down Expand Up @@ -417,7 +417,7 @@ func (s *Server) GenerateReportYAML(ctx context.Context, req *adminv1.GenerateRe
func (s *Server) yamlForManagedReport(opts *adminv1.ReportOptions, ownerUserID string) ([]byte, error) {
res := reportYAML{}
res.Type = "report"
res.Title = opts.Title
res.DisplayName = opts.DisplayName
res.Refresh.Cron = opts.RefreshCron
res.Refresh.TimeZone = opts.RefreshTimeZone
res.Watermark = "inherit"
Expand Down Expand Up @@ -463,7 +463,7 @@ func (s *Server) yamlForCommittedReport(opts *adminv1.ReportOptions) ([]byte, er

res := reportYAML{}
res.Type = "report"
res.Title = opts.Title
res.DisplayName = opts.DisplayName
res.Refresh.Cron = opts.RefreshCron
res.Refresh.TimeZone = opts.RefreshTimeZone
res.Watermark = "inherit"
Expand All @@ -481,12 +481,12 @@ func (s *Server) yamlForCommittedReport(opts *adminv1.ReportOptions) ([]byte, er
return yaml.Marshal(res)
}

// generateReportName generates a random report name with the title as a seed.
// generateReportName generates a random report name with the display name as a seed.
// Example: "My report!" -> "my-report-5b3f7e1a".
// It verifies that the name is not taken (the random component makes any collision unlikely, but we check to be sure).
func (s *Server) generateReportName(ctx context.Context, depl *database.Deployment, title string) (string, error) {
func (s *Server) generateReportName(ctx context.Context, depl *database.Deployment, displayName string) (string, error) {
for i := 0; i < 5; i++ {
name := randomReportName(title)
name := randomReportName(displayName)

_, err := s.admin.LookupReport(ctx, depl, name)
if err != nil {
Expand All @@ -506,8 +506,8 @@ var reportNameToDashCharsRegexp = regexp.MustCompile(`[ _]+`)

var reportNameExcludeCharsRegexp = regexp.MustCompile(`[^a-zA-Z0-9-]+`)

func randomReportName(title string) string {
name := reportNameToDashCharsRegexp.ReplaceAllString(title, "-")
func randomReportName(displayName string) string {
name := reportNameToDashCharsRegexp.ReplaceAllString(displayName, "-")
name = reportNameExcludeCharsRegexp.ReplaceAllString(name, "")
name = strings.ToLower(name)
name = strings.Trim(name, "-")
Expand All @@ -523,7 +523,7 @@ func recreateReportOptionsFromSpec(spec *runtimev1.ReportSpec) (*adminv1.ReportO
annotations := parseReportAnnotations(spec.Annotations)

opts := &adminv1.ReportOptions{}
opts.Title = spec.Title
opts.DisplayName = spec.DisplayName
if spec.RefreshSchedule != nil && spec.RefreshSchedule.Cron != "" {
opts.RefreshCron = spec.RefreshSchedule.Cron
opts.RefreshTimeZone = spec.RefreshSchedule.TimeZone
Expand Down Expand Up @@ -556,9 +556,10 @@ func recreateReportOptionsFromSpec(spec *runtimev1.ReportSpec) (*adminv1.ReportO

// reportYAML is derived from rillv1.ReportYAML, but adapted for generating (as opposed to parsing) the report YAML.
type reportYAML struct {
Type string `yaml:"type"`
Title string `yaml:"title"`
Refresh struct {
Type string `yaml:"type"`
DisplayName string `yaml:"display_name"`
Title string `yaml:"title,omitempty"` // Deprecated: replaced by display_name, but kept for backwards compatibility
Refresh struct {
Cron string `yaml:"cron"`
TimeZone string `yaml:"time_zone"`
} `yaml:"refresh"`
Expand Down
10 changes: 5 additions & 5 deletions proto/gen/rill/admin/v1/admin.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1563,9 +1563,9 @@ paths:
state:
type: string
description: Optional state to store with the token. Can be fetched with GetCurrentMagicAuthToken.
title:
displayName:
type: string
description: Optional public url title to store with the token.
description: Optional display name to store with the token.
tags:
- AdminService
/v1/organizations/{organization}/projects/{project}/upload-assets:
Expand Down Expand Up @@ -3544,7 +3544,7 @@ definitions:
v1AlertOptions:
type: object
properties:
title:
displayName:
type: string
intervalDuration:
type: string
Expand Down Expand Up @@ -4381,7 +4381,7 @@ definitions:
type: string
state:
type: string
title:
displayName:
type: string
v1MemberUser:
type: object
Expand Down Expand Up @@ -4666,7 +4666,7 @@ definitions:
v1ReportOptions:
type: object
properties:
title:
displayName:
type: string
refreshCron:
type: string
Expand Down
Loading
Loading