Skip to content

Commit

Permalink
chore: Add more debug logs during panel generation
Browse files Browse the repository at this point in the history
Signed-off-by: Mahendra Paipuri <mahendra.paipuri@gmail.com>
  • Loading branch information
mahendrapaipuri committed Dec 30, 2024
1 parent 5c713ae commit 76a3d8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/plugin/dashboard/panels.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math"
"strings"

"github.com/chromedp/cdproto/runtime"
"github.com/chromedp/chromedp"
Expand Down Expand Up @@ -118,6 +119,8 @@ func (d *Dashboard) panels(ctx context.Context) ([]Panel, error) {
return nil, fmt.Errorf("failed to get dashboard data from browser: %w", err)
}

d.logger.Debug("dashboard data fetch from browser", "data", dashboardData, "num_panels", len(dashboardData))

// Make panels from data
return d.createPanels(dashboardData)
}
Expand Down Expand Up @@ -209,9 +212,10 @@ func (d *Dashboard) panelData(_ context.Context) ([]interface{}, error) {
// panels creates slice of panels from the data fetched from browser's DOM model.
func (d *Dashboard) createPanels(dashData []interface{}) ([]Panel, error) {
var (
allErrs error
err error
panels []Panel
allErrs error
err error
panels []Panel
panelReprs []string
)

// We get HTML element's bounding box absolute coordinates which means
Expand Down Expand Up @@ -299,6 +303,7 @@ func (d *Dashboard) createPanels(dashData []interface{}) ([]Panel, error) {

// Create panel model and append to panels
panels = append(panels, p)
panelReprs = append(panelReprs, p.String())
}

// Remove xOffset and yOffset from all coordinates of panels
Expand All @@ -321,5 +326,7 @@ func (d *Dashboard) createPanels(dashData []interface{}) ([]Panel, error) {
return nil, allErrs
}

d.logger.Debug("fetched panels", "panels", strings.Join(panelReprs, ";"))

return panels, allErrs
}
4 changes: 4 additions & 0 deletions pkg/plugin/dashboard/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ type Panel struct {
CSVData CSVData
}

func (p *Panel) String() string {
return fmt.Sprintf("Panel ID: %s and Title: %s", p.ID, p.Title)
}

func (p *Panel) UnmarshalJSON(b []byte) error {
type tmp Panel

Expand Down

0 comments on commit 76a3d8a

Please sign in to comment.