Skip to content

Commit b9088f1

Browse files
fix: add mutext (#2415)
1 parent ac53f5b commit b9088f1

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

internal/common/client.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ type Client struct {
5050
K6APIClient *k6.APIClient
5151
K6APIConfig *k6providerapi.K6APIConfig
5252

53-
alertingMutex sync.Mutex
54-
folderMutex sync.Mutex
53+
alertingMutex sync.Mutex
54+
folderMutex sync.Mutex
55+
dashboardMutex sync.Mutex
5556
}
5657

5758
// WithAlertingMutex is a helper function that wraps a CRUD Terraform function with a mutex.
@@ -74,6 +75,16 @@ func WithFolderMutex[T schema.CreateContextFunc | schema.ReadContextFunc | schem
7475
}
7576
}
7677

78+
// WithDashboardMutex is a helper function that wraps a CRUD Terraform function with a mutex.
79+
func WithDashboardMutex[T schema.CreateContextFunc | schema.ReadContextFunc | schema.UpdateContextFunc | schema.DeleteContextFunc](f T) T {
80+
return func(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
81+
lock := &meta.(*Client).dashboardMutex
82+
lock.Lock()
83+
defer lock.Unlock()
84+
return f(ctx, d, meta)
85+
}
86+
}
87+
7788
func (c *Client) GrafanaSubpath(path string) string {
7889
path = strings.TrimPrefix(path, c.GrafanaAPIURLParsed.Path)
7990
return c.GrafanaAPIURLParsed.JoinPath(path).String()

internal/resources/grafana/resource_dashboard.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ Manages Grafana dashboards.
3030
* [HTTP API](https://grafana.com/docs/grafana/latest/developers/http_api/dashboard/)
3131
`,
3232

33-
CreateContext: CreateDashboard,
33+
CreateContext: common.WithDashboardMutex[schema.CreateContextFunc](CreateDashboard),
3434
ReadContext: ReadDashboard,
35-
UpdateContext: UpdateDashboard,
36-
DeleteContext: DeleteDashboard,
35+
UpdateContext: common.WithDashboardMutex[schema.UpdateContextFunc](UpdateDashboard),
36+
DeleteContext: common.WithDashboardMutex[schema.DeleteContextFunc](DeleteDashboard),
3737
Importer: &schema.ResourceImporter{
3838
StateContext: schema.ImportStatePassthroughContext,
3939
},

0 commit comments

Comments
 (0)