Skip to content

Commit

Permalink
Update backendSupport.setFromDb to support ConnectionString
Browse files Browse the repository at this point in the history
log errors from dashboard execution
  • Loading branch information
kaidaguerre committed Feb 3, 2025
1 parent 25996e8 commit 45c57a1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/spf13/viper v1.19.0
github.com/stevenle/topsort v0.2.0
github.com/turbot/go-kit v0.10.0-rc.0
github.com/turbot/pipe-fittings/v2 v2.0.0-rc.2
github.com/turbot/pipe-fittings/v2 v2.0.1-rc.0
github.com/turbot/steampipe-plugin-sdk/v5 v5.11.0
github.com/turbot/terraform-components v0.0.0-20231213122222-1f3526cab7a7 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,8 @@ github.com/turbot/go-kit v0.10.0-rc.0 h1:kd+jp2ibbIV33Hc8SsMAN410Dl9Pz6SJ40axbKU
github.com/turbot/go-kit v0.10.0-rc.0/go.mod h1:fFQqR59I5z5JeeBLfK1PjSifn4Oprs3NiQx0CxeSJxs=
github.com/turbot/pipe-fittings v1.6.0 h1:sn4OJPQQR0fggKMNUuyvShJipZG/Ze5jR48Hl12Eokg=
github.com/turbot/pipe-fittings v1.6.0/go.mod h1:1nlRVh18QkYy9eq5pW9gpnoE2VgnQW0Y2zKzrH8Q4kI=
github.com/turbot/pipe-fittings/v2 v2.0.0-rc.2 h1:0nUVueTEbgPSqhff/6DCCgUaAjkZHvHdKOf/PtoeyRE=
github.com/turbot/pipe-fittings/v2 v2.0.0-rc.2/go.mod h1:4srBITqYs/VWpgpqjQmJejJ3akkPVRueCHQa9CiETr0=
github.com/turbot/pipe-fittings/v2 v2.0.1-rc.0 h1:z11uypxjxxoFfltbNPJFC3Ub5HwoVtViPFB28T1ZS0g=
github.com/turbot/pipe-fittings/v2 v2.0.1-rc.0/go.mod h1:4srBITqYs/VWpgpqjQmJejJ3akkPVRueCHQa9CiETr0=
github.com/turbot/pipes-sdk-go v0.9.1 h1:2yRojY2wymvJn6NQyE6A0EDFV267MNe+yDLxPVvsBwM=
github.com/turbot/pipes-sdk-go v0.9.1/go.mod h1:Mb+KhvqqEdRbz/6TSZc2QWDrMa5BN3E4Xw+gPt2TRkc=
github.com/turbot/steampipe-plugin-code v0.7.0 h1:SROYIo/TI/Q/YNfXK+sAIS71umypUFm1Uz851TmoJkM=
Expand Down
22 changes: 21 additions & 1 deletion internal/dashboardserver/backend_support.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package dashboardserver

import (
"context"
"log/slog"

"github.com/turbot/pipe-fittings/v2/backend"
"github.com/turbot/pipe-fittings/v2/connection"
"github.com/turbot/pipe-fittings/v2/constants"
"github.com/turbot/pipe-fittings/v2/modconfig"
"log/slog"
)

type backendSupport struct {
Expand All @@ -19,6 +23,22 @@ func (bs *backendSupport) setFromDb(db connection.ConnectionStringProvider) {
bs.supportsSearchPath = true
case *connection.TailpipeConnection:
bs.supportsTimeRange = true
case *connection.ConnectionString:
// create a backend and get its name
// if it is a steampipe or postgres backend, set supportsSearchPath
// NOTE: a tailpipe connection cannot be specified by a connection string
// (as the connection string is dynamic and provided by the Tailpipe CLI),
// so we will not set the supportsTimeRange flag here

// we do not expect an error from ConnectionString.GetConnectionString
connectionString, _ := db.GetConnectionString()
// get the backend name from the connection string
// NOTE: this does not create the backend and will therefore return postgres for a steampipe backend
// as we cannot tell the difference purely from the connection string
// This is fine as we just want to determine whether a search path is supported
backendName, _ := backend.NameFromConnectionString(context.Background(), connectionString)
// set supportsSearchPath if the backend is a steampipe or postgres backend
bs.supportsSearchPath = backendName == constants.PostgresBackendName
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions internal/dashboardserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ func (s *Server) HandleDashboardEvent(ctx context.Context, event dashboardevents
if typeHelpers.SafeString(dashboardClientInfo.Dashboard) == changedDashboardName {

if changedResource := s.getResource(changedDashboardName); changedResource != nil {
_ = dashboardexecute.Executor.ExecuteDashboard(ctx, sessionId, changedResource, dashboardClientInfo.DashboardInputs, s.workspace)
err := dashboardexecute.Executor.ExecuteDashboard(ctx, sessionId, changedResource, dashboardClientInfo.DashboardInputs, s.workspace)
if err != nil {
OutputError(ctx, sperr.WrapWithMessage(err, "error executing dashboard"))
}
}
}
}
Expand All @@ -300,7 +303,10 @@ func (s *Server) HandleDashboardEvent(ctx context.Context, event dashboardevents
for sessionId, dashboardClientInfo := range sessionMap {
if typeHelpers.SafeString(dashboardClientInfo.Dashboard) == newDashboardName {
if newDashboard := s.getResource(newDashboardName); newDashboard != nil {
_ = dashboardexecute.Executor.ExecuteDashboard(ctx, sessionId, newDashboard, dashboardClientInfo.DashboardInputs, s.workspace)
err := dashboardexecute.Executor.ExecuteDashboard(ctx, sessionId, newDashboard, dashboardClientInfo.DashboardInputs, s.workspace)
if err != nil {
OutputError(ctx, sperr.WrapWithMessage(err, "error executing dashboard"))
}
}
}
}
Expand Down Expand Up @@ -387,8 +393,10 @@ func (s *Server) handleMessageFunc(ctx context.Context) func(session *melody.Ses
SearchPathPrefix: request.Payload.SearchPathPrefix,
}))
}
_ = dashboardexecute.Executor.ExecuteDashboard(ctx, sessionId, dashboard, inputValues, s.workspace, opts...)

err := dashboardexecute.Executor.ExecuteDashboard(ctx, sessionId, dashboard, inputValues, s.workspace, opts...)
if err != nil {
OutputError(ctx, sperr.WrapWithMessage(err, "error executing dashboard"))
}
slog.Debug("get_dashboard_metadata", "dashboard", request.Payload.Dashboard.FullName)
payload, err := s.buildDashboardMetadataPayload(dashboard)
if err != nil {
Expand Down

0 comments on commit 45c57a1

Please sign in to comment.