@@ -56,7 +56,7 @@ type Dashboard struct {
5656 builder dashboard.Builder
5757}
5858
59- // NewDashboard creates new dashboard
59+ // NewDashboard initializes a Dashboard with provided alerts and options, using environment variables for configuration. It prepares the dashboard for deployment and returns the instance or an error if setup fails.
6060func NewDashboard (reqs []WaspAlert , opts []dashboard.Option ) (* Dashboard , error ) {
6161 name := os .Getenv ("DASHBOARD_NAME" )
6262 if name == "" {
@@ -93,7 +93,8 @@ func NewDashboard(reqs []WaspAlert, opts []dashboard.Option) (*Dashboard, error)
9393 return dash , nil
9494}
9595
96- // Deploy deploys this dashboard to some Grafana folder
96+ // Deploy uploads the Dashboard to Grafana, creating the folder if necessary.
97+ // It returns the deployed grabana.Dashboard and any encountered error.
9798func (m * Dashboard ) Deploy () (* grabana.Dashboard , error ) {
9899 ctx := context .Background ()
99100 client := grabana .NewClient (& http.Client {}, m .GrafanaURL , grabana .WithAPIToken (m .GrafanaToken ))
@@ -105,7 +106,8 @@ func (m *Dashboard) Deploy() (*grabana.Dashboard, error) {
105106 return client .UpsertDashboard (ctx , fo , m .builder )
106107}
107108
108- // defaultStatWidget creates default Stat widget
109+ // defaultStatWidget creates a standard dashboard stat widget using the specified name, datasource, Prometheus target, and legend.
110+ // It is used to display consistent metrics within dashboard rows.
109111func defaultStatWidget (name , datasourceName , target , legend string ) row.Option {
110112 return row .WithStat (
111113 name ,
@@ -120,7 +122,8 @@ func defaultStatWidget(name, datasourceName, target, legend string) row.Option {
120122 )
121123}
122124
123- // defaultLastValueAlertWidget creates default last value alert
125+ // defaultLastValueAlertWidget generates a timeseries.Option for alerting using a WaspAlert.
126+ // It returns the custom alert if provided, otherwise configures a default last-value alert for consistent monitoring in dashboards.
124127func defaultLastValueAlertWidget (a WaspAlert ) timeseries.Option {
125128 if a .CustomAlert != nil {
126129 return a .CustomAlert
@@ -143,7 +146,9 @@ func defaultLastValueAlertWidget(a WaspAlert) timeseries.Option {
143146 )
144147}
145148
146- // defaultLabelValuesVar creates a dashboard variable with All/Multiple options
149+ // defaultLabelValuesVar generates a dashboard variable for the specified name and datasource.
150+ // It enables multiple selections, includes an "All" option, and sorts label values in ascending numerical order.
151+ // Use it to create consistent query variables for dashboard filtering.
147152func defaultLabelValuesVar (name , datasourceName string ) dashboard.Option {
148153 return dashboard .VariableAsQuery (
149154 name ,
@@ -155,7 +160,8 @@ func defaultLabelValuesVar(name, datasourceName string) dashboard.Option {
155160 )
156161}
157162
158- // timeSeriesWithAlerts creates timeseries graphs per alert + definition of alert
163+ // timeSeriesWithAlerts creates dashboard options for each WaspAlert, configuring time series panels with alert settings.
164+ // Use it to add alert-specific rows to a dashboard based on provided alert definitions.
159165func timeSeriesWithAlerts (datasourceName string , alertDefs []WaspAlert ) []dashboard.Option {
160166 dashboardOpts := make ([]dashboard.Option , 0 )
161167 for _ , a := range alertDefs {
@@ -189,6 +195,9 @@ func timeSeriesWithAlerts(datasourceName string, alertDefs []WaspAlert) []dashbo
189195 return dashboardOpts
190196}
191197
198+ // AddVariables generates standard dashboard options for common label variables using the provided datasourceName.
199+ // It includes variables like go_test_name, gen_name, branch, commit, and call_group.
200+ // Use this to easily incorporate these variables into your dashboard configuration.
192201func AddVariables (datasourceName string ) []dashboard.Option {
193202 opts := []dashboard.Option {
194203 defaultLabelValuesVar ("go_test_name" , datasourceName ),
@@ -200,7 +209,8 @@ func AddVariables(datasourceName string) []dashboard.Option {
200209 return opts
201210}
202211
203- // dashboard is internal appendable representation of all Dashboard widgets
212+ // dashboard generates dashboard configuration options based on the specified datasource and alert requirements.
213+ // It is used to set up panels and settings when building a new dashboard.
204214func (m * Dashboard ) dashboard (datasourceName string , requirements []WaspAlert ) []dashboard.Option {
205215 panelQuery := map [string ]string {
206216 "branch" : `=~"${branch:pipe}"` ,
@@ -221,7 +231,8 @@ func (m *Dashboard) dashboard(datasourceName string, requirements []WaspAlert) [
221231 return defaultOpts
222232}
223233
224- // Build creates dashboard instance
234+ // Build initializes the Dashboard with the specified name, data source, and alert requirements.
235+ // It prepares the dashboard builder for further configuration and usage.
225236func (m * Dashboard ) Build (dashboardName , datasourceName string , requirements []WaspAlert ) error {
226237 b , err := dashboard .New (
227238 dashboardName ,
@@ -234,12 +245,14 @@ func (m *Dashboard) Build(dashboardName, datasourceName string, requirements []W
234245 return nil
235246}
236247
237- // JSON render dashboard as JSON
248+ // JSON serializes the Dashboard into indented JSON format.
249+ // It provides a human-readable representation, useful for exporting or inspecting the dashboard.
238250func (m * Dashboard ) JSON () ([]byte , error ) {
239251 return m .builder .MarshalIndentJSON ()
240252}
241253
242- // InlineLokiAlertParams is specific params for predefined alerts for wasp dashboard
254+ // InlineLokiAlertParams generates a Loki query string based on the alert type, test name, and generator name.
255+ // It is used to configure specific alert conditions for monitoring test metrics in dashboards.
243256func InlineLokiAlertParams (queryType , testName , genName string ) string {
244257 switch queryType {
245258 case AlertTypeQuantile99 :
@@ -262,6 +275,8 @@ max_over_time({go_test_name="%s", test_data_type=~"stats", gen_name="%s"}
262275 }
263276}
264277
278+ // WASPLoadStatsRow creates a "WASP Load Stats" dashboard row with widgets displaying real-time and total load metrics.
279+ // It utilizes the provided data source and query parameters to configure the relevant statistics for monitoring.
265280func WASPLoadStatsRow (dataSource string , query map [string ]string ) dashboard.Option {
266281 queryString := ""
267282 for key , value := range query {
@@ -384,6 +399,9 @@ func WASPLoadStatsRow(dataSource string, query map[string]string) dashboard.Opti
384399 )
385400}
386401
402+ // WASPDebugDataRow returns a dashboard.Option containing a row with WASP debug metrics and logs.
403+ // It uses the provided data source and query parameters.
404+ // Use this function to include detailed debug information in your dashboard.
387405func WASPDebugDataRow (dataSource string , query map [string ]string , collapse bool ) dashboard.Option {
388406 queryString := ""
389407 for key , value := range query {
0 commit comments