9
9
"github.com/google/uuid"
10
10
"github.com/grafana/grafana-plugin-sdk-go/backend"
11
11
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
12
+ "go.opentelemetry.io/otel"
12
13
13
14
"github.com/grafana/grafana/pkg/api/dtos"
14
15
"github.com/grafana/grafana/pkg/infra/log"
@@ -45,6 +46,7 @@ type PublicDashboardServiceImpl struct {
45
46
}
46
47
47
48
var LogPrefix = "publicdashboards.service"
49
+ var tracer = otel .Tracer ("github.com/grafana/grafana/pkg/services/publicdashboards/service" )
48
50
49
51
// Gives us compile time error if the service does not adhere to the contract of
50
52
// the interface
@@ -79,6 +81,9 @@ func ProvideService(
79
81
}
80
82
81
83
func (pd * PublicDashboardServiceImpl ) GetPublicDashboardForView (ctx context.Context , accessToken string ) (* dtos.DashboardFullWithMeta , error ) {
84
+ ctx , span := tracer .Start (ctx , "publicdashboards.GetPublicDashboardForView" )
85
+ defer span .End ()
86
+
82
87
pubdash , dash , err := pd .FindEnabledPublicDashboardAndDashboardByAccessToken (ctx , accessToken )
83
88
if err != nil {
84
89
return nil , err
@@ -110,10 +115,14 @@ func (pd *PublicDashboardServiceImpl) GetPublicDashboardForView(ctx context.Cont
110
115
111
116
// FindByDashboardUid this method would be replaced by another implementation for Enterprise version
112
117
func (pd * PublicDashboardServiceImpl ) FindByDashboardUid (ctx context.Context , orgId int64 , dashboardUid string ) (* PublicDashboard , error ) {
118
+ ctx , span := tracer .Start (ctx , "publicdashboards.FindByDashboardUid" )
119
+ defer span .End ()
113
120
return pd .serviceWrapper .FindByDashboardUid (ctx , orgId , dashboardUid )
114
121
}
115
122
116
123
func (pd * PublicDashboardServiceImpl ) Find (ctx context.Context , uid string ) (* PublicDashboard , error ) {
124
+ ctx , span := tracer .Start (ctx , "publicdashboards.Find" )
125
+ defer span .End ()
117
126
pubdash , err := pd .store .Find (ctx , uid )
118
127
if err != nil {
119
128
return nil , ErrInternalServerError .Errorf ("Find: failed to find public dashboard%w" , err )
@@ -123,6 +132,8 @@ func (pd *PublicDashboardServiceImpl) Find(ctx context.Context, uid string) (*Pu
123
132
124
133
// FindDashboard Gets a dashboard by Uid
125
134
func (pd * PublicDashboardServiceImpl ) FindDashboard (ctx context.Context , orgId int64 , dashboardUid string ) (* dashboards.Dashboard , error ) {
135
+ ctx , span := tracer .Start (ctx , "publicdashboards.FindDashboard" )
136
+ defer span .End ()
126
137
dash , err := pd .dashboardService .GetDashboard (ctx , & dashboards.GetDashboardQuery {UID : dashboardUid , OrgID : orgId })
127
138
if err != nil {
128
139
var dashboardErr dashboards.DashboardErr
@@ -139,6 +150,8 @@ func (pd *PublicDashboardServiceImpl) FindDashboard(ctx context.Context, orgId i
139
150
140
151
// FindByAccessToken Gets public dashboard by access token
141
152
func (pd * PublicDashboardServiceImpl ) FindByAccessToken (ctx context.Context , accessToken string ) (* PublicDashboard , error ) {
153
+ ctx , span := tracer .Start (ctx , "publicdashboards.FindByAccessToken" )
154
+ defer span .End ()
142
155
pubdash , err := pd .store .FindByAccessToken (ctx , accessToken )
143
156
if err != nil {
144
157
return nil , ErrInternalServerError .Errorf ("FindByAccessToken: failed to find a public dashboard: %w" , err )
@@ -153,6 +166,8 @@ func (pd *PublicDashboardServiceImpl) FindByAccessToken(ctx context.Context, acc
153
166
154
167
// FindEnabledPublicDashboardAndDashboardByAccessToken Gets public dashboard and a dashboard by access token if public dashboard is enabled
155
168
func (pd * PublicDashboardServiceImpl ) FindEnabledPublicDashboardAndDashboardByAccessToken (ctx context.Context , accessToken string ) (* PublicDashboard , * dashboards.Dashboard , error ) {
169
+ ctx , span := tracer .Start (ctx , "publicdashboards.FindEnabledPublicDashboardAndDashboardByAccessToken" )
170
+ defer span .End ()
156
171
pubdash , dash , err := pd .FindPublicDashboardAndDashboardByAccessToken (ctx , accessToken )
157
172
if err != nil {
158
173
return pubdash , dash , err
@@ -171,6 +186,8 @@ func (pd *PublicDashboardServiceImpl) FindEnabledPublicDashboardAndDashboardByAc
171
186
172
187
// FindPublicDashboardAndDashboardByAccessToken Gets public dashboard and a dashboard by access token
173
188
func (pd * PublicDashboardServiceImpl ) FindPublicDashboardAndDashboardByAccessToken (ctx context.Context , accessToken string ) (* PublicDashboard , * dashboards.Dashboard , error ) {
189
+ ctx , span := tracer .Start (ctx , "publicdashboards.FindPublicDashboardAndDashboardByAccessToken" )
190
+ defer span .End ()
174
191
pubdash , err := pd .FindByAccessToken (ctx , accessToken )
175
192
if err != nil {
176
193
return nil , nil , err
@@ -190,6 +207,8 @@ func (pd *PublicDashboardServiceImpl) FindPublicDashboardAndDashboardByAccessTok
190
207
191
208
// Creates and validates the public dashboard and saves it to the database
192
209
func (pd * PublicDashboardServiceImpl ) Create (ctx context.Context , u * user.SignedInUser , dto * SavePublicDashboardDTO ) (* PublicDashboard , error ) {
210
+ ctx , span := tracer .Start (ctx , "publicdashboards.Create" )
211
+ defer span .End ()
193
212
// validate fields
194
213
err := validation .ValidatePublicDashboard (dto )
195
214
if err != nil {
@@ -247,6 +266,8 @@ func (pd *PublicDashboardServiceImpl) Create(ctx context.Context, u *user.Signed
247
266
248
267
// Update: updates an existing public dashboard based on publicdashboard.Uid
249
268
func (pd * PublicDashboardServiceImpl ) Update (ctx context.Context , u * user.SignedInUser , dto * SavePublicDashboardDTO ) (* PublicDashboard , error ) {
269
+ ctx , span := tracer .Start (ctx , "publicdashboards.Update" )
270
+ defer span .End ()
250
271
// validate fields
251
272
err := validation .ValidatePublicDashboard (dto )
252
273
if err != nil {
@@ -303,6 +324,8 @@ func (pd *PublicDashboardServiceImpl) Update(ctx context.Context, u *user.Signed
303
324
304
325
// NewPublicDashboardUid Generates a unique uid to create a public dashboard. Will make 3 attempts and fail if it cannot find an unused uid
305
326
func (pd * PublicDashboardServiceImpl ) NewPublicDashboardUid (ctx context.Context ) (string , error ) {
327
+ ctx , span := tracer .Start (ctx , "publicdashboards.NewPublicDashboardUid" )
328
+ defer span .End ()
306
329
var uid string
307
330
for i := 0 ; i < 3 ; i ++ {
308
331
uid = util .GenerateShortUID ()
@@ -317,6 +340,8 @@ func (pd *PublicDashboardServiceImpl) NewPublicDashboardUid(ctx context.Context)
317
340
318
341
// NewPublicDashboardAccessToken Generates a unique accessToken to create a public dashboard. Will make 3 attempts and fail if it cannot find an unused access token
319
342
func (pd * PublicDashboardServiceImpl ) NewPublicDashboardAccessToken (ctx context.Context ) (string , error ) {
343
+ ctx , span := tracer .Start (ctx , "publicdashboards.NewPublicDashboardAccessToken" )
344
+ defer span .End ()
320
345
var accessToken string
321
346
for i := 0 ; i < 3 ; i ++ {
322
347
var err error
@@ -335,6 +360,8 @@ func (pd *PublicDashboardServiceImpl) NewPublicDashboardAccessToken(ctx context.
335
360
336
361
// FindAllWithPagination Returns a list of public dashboards by orgId, based on permissions and with pagination
337
362
func (pd * PublicDashboardServiceImpl ) FindAllWithPagination (ctx context.Context , query * PublicDashboardListQuery ) (* PublicDashboardListResponseWithPagination , error ) {
363
+ ctx , span := tracer .Start (ctx , "publicdashboards.FindAllWithPagination" )
364
+ defer span .End ()
338
365
query .Offset = query .Limit * (query .Page - 1 )
339
366
resp , err := pd .store .FindAllWithPagination (ctx , query )
340
367
if err != nil {
@@ -348,18 +375,26 @@ func (pd *PublicDashboardServiceImpl) FindAllWithPagination(ctx context.Context,
348
375
}
349
376
350
377
func (pd * PublicDashboardServiceImpl ) ExistsEnabledByDashboardUid (ctx context.Context , dashboardUid string ) (bool , error ) {
378
+ ctx , span := tracer .Start (ctx , "publicdashboards.ExistsEnabledByDashboardUid" )
379
+ defer span .End ()
351
380
return pd .store .ExistsEnabledByDashboardUid (ctx , dashboardUid )
352
381
}
353
382
354
383
func (pd * PublicDashboardServiceImpl ) ExistsEnabledByAccessToken (ctx context.Context , accessToken string ) (bool , error ) {
384
+ ctx , span := tracer .Start (ctx , "publicdashboards.ExistsEnabledByAccessToken" )
385
+ defer span .End ()
355
386
return pd .store .ExistsEnabledByAccessToken (ctx , accessToken )
356
387
}
357
388
358
389
func (pd * PublicDashboardServiceImpl ) GetOrgIdByAccessToken (ctx context.Context , accessToken string ) (int64 , error ) {
390
+ ctx , span := tracer .Start (ctx , "publicdashboards.GetOrgIdByAccessToken" )
391
+ defer span .End ()
359
392
return pd .store .GetOrgIdByAccessToken (ctx , accessToken )
360
393
}
361
394
362
395
func (pd * PublicDashboardServiceImpl ) Delete (ctx context.Context , uid string , dashboardUid string ) error {
396
+ ctx , span := tracer .Start (ctx , "publicdashboards.Delete" )
397
+ defer span .End ()
363
398
// get existing public dashboard if exists
364
399
existingPubdash , err := pd .store .Find (ctx , uid )
365
400
if err != nil {
@@ -377,6 +412,8 @@ func (pd *PublicDashboardServiceImpl) Delete(ctx context.Context, uid string, da
377
412
}
378
413
379
414
func (pd * PublicDashboardServiceImpl ) DeleteByDashboard (ctx context.Context , dashboard * dashboards.Dashboard ) error {
415
+ ctx , span := tracer .Start (ctx , "publicdashboards.DeleteByDashboard" )
416
+ defer span .End ()
380
417
if dashboard .IsFolder {
381
418
// get all pubdashes for the folder
382
419
pubdashes , err := pd .store .FindByFolder (ctx , dashboard .OrgID , dashboard .UID )
@@ -464,6 +501,8 @@ func GenerateAccessToken() (string, error) {
464
501
}
465
502
466
503
func (pd * PublicDashboardServiceImpl ) newCreatePublicDashboard (ctx context.Context , dto * SavePublicDashboardDTO ) (* PublicDashboard , error ) {
504
+ ctx , span := tracer .Start (ctx , "publicdashboards.newCreatePublicDashboard" )
505
+ defer span .End ()
467
506
//Check if uid already exists, if none then auto generate
468
507
var err error
469
508
uid := dto .PublicDashboard .Uid
0 commit comments