mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 12:36:07 +08:00
* fix(be,fe): upsert dashboard on provision, export with uuid from frontend * chore(fe): formatting in dashboard description * fix: miss out while merging --------- Co-authored-by: Håvard <haavard.markhus@inmeta.no> Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com> Co-authored-by: Haavasma <61970295+Haavasma@users.noreply.github.com>
This commit is contained in:
parent
4c91dbcff0
commit
2b3d1c8ee5
@ -23,7 +23,12 @@ function DashboardDescription(): JSX.Element {
|
|||||||
handleDashboardLockToggle,
|
handleDashboardLockToggle,
|
||||||
} = useDashboard();
|
} = useDashboard();
|
||||||
|
|
||||||
const selectedData = selectedDashboard?.data || ({} as DashboardData);
|
const selectedData = selectedDashboard
|
||||||
|
? {
|
||||||
|
...selectedDashboard.data,
|
||||||
|
uuid: selectedDashboard.uuid,
|
||||||
|
}
|
||||||
|
: ({} as DashboardData);
|
||||||
|
|
||||||
const { title = '', tags, description } = selectedData || {};
|
const { title = '', tags, description } = selectedData || {};
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ export interface Dashboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DashboardData {
|
export interface DashboardData {
|
||||||
|
uuid?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
name?: string;
|
name?: string;
|
||||||
|
@ -25,12 +25,14 @@ import (
|
|||||||
var db *sqlx.DB
|
var db *sqlx.DB
|
||||||
|
|
||||||
// User for mapping job,instance from grafana
|
// User for mapping job,instance from grafana
|
||||||
var instanceEQRE = regexp.MustCompile("instance(?s)=(?s)\\\"{{.instance}}\\\"")
|
var (
|
||||||
var nodeEQRE = regexp.MustCompile("instance(?s)=(?s)\\\"{{.node}}\\\"")
|
instanceEQRE = regexp.MustCompile("instance(?s)=(?s)\\\"{{.instance}}\\\"")
|
||||||
var jobEQRE = regexp.MustCompile("job(?s)=(?s)\\\"{{.job}}\\\"")
|
nodeEQRE = regexp.MustCompile("instance(?s)=(?s)\\\"{{.node}}\\\"")
|
||||||
var instanceRERE = regexp.MustCompile("instance(?s)=~(?s)\\\"{{.instance}}\\\"")
|
jobEQRE = regexp.MustCompile("job(?s)=(?s)\\\"{{.job}}\\\"")
|
||||||
var nodeRERE = regexp.MustCompile("instance(?s)=~(?s)\\\"{{.node}}\\\"")
|
instanceRERE = regexp.MustCompile("instance(?s)=~(?s)\\\"{{.instance}}\\\"")
|
||||||
var jobRERE = regexp.MustCompile("job(?s)=~(?s)\\\"{{.job}}\\\"")
|
nodeRERE = regexp.MustCompile("instance(?s)=~(?s)\\\"{{.node}}\\\"")
|
||||||
|
jobRERE = regexp.MustCompile("job(?s)=~(?s)\\\"{{.job}}\\\"")
|
||||||
|
)
|
||||||
|
|
||||||
// InitDB sets up setting up the connection pool global variable.
|
// InitDB sets up setting up the connection pool global variable.
|
||||||
func InitDB(dataSourceName string) (*sqlx.DB, error) {
|
func InitDB(dataSourceName string) (*sqlx.DB, error) {
|
||||||
@ -188,6 +190,9 @@ func CreateDashboard(ctx context.Context, data map[string]interface{}, fm interf
|
|||||||
dash.UpdateBy = &userEmail
|
dash.UpdateBy = &userEmail
|
||||||
dash.UpdateSlug()
|
dash.UpdateSlug()
|
||||||
dash.Uuid = uuid.New().String()
|
dash.Uuid = uuid.New().String()
|
||||||
|
if data["uuid"] != nil {
|
||||||
|
dash.Uuid = data["uuid"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
mapData, err := json.Marshal(dash.Data)
|
mapData, err := json.Marshal(dash.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -211,7 +216,6 @@ func CreateDashboard(ctx context.Context, data map[string]interface{}, fm interf
|
|||||||
return nil, &model.ApiError{Typ: model.ErrorExec, Err: err}
|
return nil, &model.ApiError{Typ: model.ErrorExec, Err: err}
|
||||||
}
|
}
|
||||||
lastInsertId, err := result.LastInsertId()
|
lastInsertId, err := result.LastInsertId()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &model.ApiError{Typ: model.ErrorExec, Err: err}
|
return nil, &model.ApiError{Typ: model.ErrorExec, Err: err}
|
||||||
}
|
}
|
||||||
@ -255,7 +259,6 @@ func DeleteDashboard(ctx context.Context, uuid string, fm interfaces.FeatureLook
|
|||||||
query := `DELETE FROM dashboards WHERE uuid=?`
|
query := `DELETE FROM dashboards WHERE uuid=?`
|
||||||
|
|
||||||
result, err := db.Exec(query, uuid)
|
result, err := db.Exec(query, uuid)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &model.ApiError{Typ: model.ErrorExec, Err: err}
|
return &model.ApiError{Typ: model.ErrorExec, Err: err}
|
||||||
}
|
}
|
||||||
@ -419,7 +422,6 @@ func (d *Dashboard) UpdateSlug() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func IsPostDataSane(data *map[string]interface{}) error {
|
func IsPostDataSane(data *map[string]interface{}) error {
|
||||||
|
|
||||||
val, ok := (*data)["title"]
|
val, ok := (*data)["title"]
|
||||||
if !ok || val == nil {
|
if !ok || val == nil {
|
||||||
return fmt.Errorf("title not found in post data")
|
return fmt.Errorf("title not found in post data")
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"go.signoz.io/signoz/pkg/query-service/constants"
|
"go.signoz.io/signoz/pkg/query-service/constants"
|
||||||
"go.signoz.io/signoz/pkg/query-service/interfaces"
|
"go.signoz.io/signoz/pkg/query-service/interfaces"
|
||||||
|
"go.signoz.io/signoz/pkg/query-service/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readCurrentDir(dir string, fm interfaces.FeatureLookup) error {
|
func readCurrentDir(dir string, fm interfaces.FeatureLookup) error {
|
||||||
@ -43,22 +44,36 @@ func readCurrentDir(dir string, fm interfaces.FeatureLookup) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, apiErr := GetDashboard(context.Background(), data["uuid"].(string))
|
id := data["uuid"]
|
||||||
if apiErr == nil {
|
if id == nil {
|
||||||
zap.S().Infof("Creating Dashboards: Error in file: %s\t%s", filename, "Dashboard already present in database")
|
_, apiErr := CreateDashboard(context.Background(), data, fm)
|
||||||
|
if apiErr != nil {
|
||||||
|
zap.S().Errorf("Creating Dashboards: Error in file: %s\t%s", filename, apiErr.Err)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, apiErr = CreateDashboard(context.Background(), data, fm)
|
apiErr := upsertDashboard(id.(string), data, filename, fm)
|
||||||
if apiErr != nil {
|
if apiErr != nil {
|
||||||
zap.S().Errorf("Creating Dashboards: Error in file: %s\t%s", filename, apiErr.Err)
|
zap.S().Errorf("Creating Dashboards: Error upserting dashboard: %s\t%s", filename, apiErr.Err)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func upsertDashboard(uuid string, data map[string]interface{}, filename string, fm interfaces.FeatureLookup) *model.ApiError {
|
||||||
|
_, apiErr := GetDashboard(context.Background(), uuid)
|
||||||
|
if apiErr == nil {
|
||||||
|
zap.S().Infof("Creating Dashboards: Already exists: %s\t%s", filename, "Dashboard already present in database, Updating dashboard")
|
||||||
|
_, apiErr := UpdateDashboard(context.Background(), uuid, data, fm)
|
||||||
|
return apiErr
|
||||||
|
}
|
||||||
|
|
||||||
|
zap.S().Infof("Creating Dashboards: UUID not found: %s\t%s", filename, "Dashboard not present in database, Creating dashboard")
|
||||||
|
_, apiErr = CreateDashboard(context.Background(), data, fm)
|
||||||
|
return apiErr
|
||||||
|
}
|
||||||
|
|
||||||
func LoadDashboardFiles(fm interfaces.FeatureLookup) error {
|
func LoadDashboardFiles(fm interfaces.FeatureLookup) error {
|
||||||
dashboardsPath := constants.GetOrDefaultEnv("DASHBOARDS_PATH", "./config/dashboards")
|
dashboardsPath := constants.GetOrDefaultEnv("DASHBOARDS_PATH", "./config/dashboards")
|
||||||
return readCurrentDir(dashboardsPath, fm)
|
return readCurrentDir(dashboardsPath, fm)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user