Skip to content

Commit

Permalink
Add telemetry on datastore (#56)
Browse files Browse the repository at this point in the history
* Add debug logs

* Add runtime calculation logging

* add more log

* add datastore telemtry

Co-authored-by: Dylan Tinianov <dylantinianov@gmail.com>
  • Loading branch information
devbugging and DylanTinianov authored Sep 21, 2022
1 parent 8056249 commit 9ac7f6c
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions storage/datastore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package datastore

import (
"context"
"github.com/dapperlabs/flow-playground-api/telemetry"
"time"

"github.com/dapperlabs/flow-playground-api/storage"
Expand Down Expand Up @@ -124,10 +125,16 @@ func (d *Datastore) markProjectUpdatedAt(tx *datastore.Transaction, projectID uu
// Users

func (d *Datastore) InsertUser(user *model.User) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

return d.put(user)
}

func (d *Datastore) GetUser(id uuid.UUID, user *model.User) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

user.ID = id
return d.get(user)
}
Expand All @@ -138,6 +145,9 @@ func (d *Datastore) CreateProject(
proj *model.InternalProject,
ttpls []*model.TransactionTemplate,
stpls []*model.ScriptTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -173,6 +183,9 @@ func (d *Datastore) CreateProject(
}

func (d *Datastore) UpdateProject(input model.UpdateProject, proj *model.InternalProject) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -210,6 +223,9 @@ func (d *Datastore) UpdateProject(input model.UpdateProject, proj *model.Interna
}

func (d *Datastore) UpdateProjectOwner(id, userID uuid.UUID) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand All @@ -231,6 +247,9 @@ func (d *Datastore) UpdateProjectOwner(id, userID uuid.UUID) error {
}

func (d *Datastore) UpdateProjectVersion(id uuid.UUID, version *semver.Version) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand All @@ -252,6 +271,9 @@ func (d *Datastore) UpdateProjectVersion(id uuid.UUID, version *semver.Version)
}

func (d *Datastore) ResetProjectState(proj *model.InternalProject) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -309,22 +331,34 @@ func (d *Datastore) ResetProjectState(proj *model.InternalProject) error {
}

func (d *Datastore) GetProject(id uuid.UUID, proj *model.InternalProject) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

proj.ID = id
return d.get(proj)
}

// Accounts

func (d *Datastore) InsertAccount(acc *model.InternalAccount) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

return d.put(acc)
}

func (d *Datastore) GetAccount(id model.ProjectChildID, acc *model.InternalAccount) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

acc.ProjectChildID = id
return d.get(acc)
}

func (d *Datastore) UpdateAccount(input model.UpdateAccount, acc *model.InternalAccount) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -354,11 +388,17 @@ func (d *Datastore) UpdateAccount(input model.UpdateAccount, acc *model.Internal
}

func (d *Datastore) GetAccountsForProject(projectID uuid.UUID, accs *[]*model.InternalAccount) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

q := datastore.NewQuery("Account").Ancestor(model.ProjectNameKey(projectID)).Order("Index")
return d.getAll(q, accs)
}

func (d *Datastore) DeleteAccount(id model.ProjectChildID) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

acc := model.InternalAccount{ProjectChildID: id}

_, txErr := d.dsClient.RunInTransaction(context.Background(), func(tx *datastore.Transaction) error {
Expand All @@ -381,6 +421,9 @@ func (d *Datastore) DeleteAccount(id model.ProjectChildID) error {
// Transaction Templates

func (d *Datastore) InsertTransactionTemplate(tpl *model.TransactionTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -412,6 +455,9 @@ func (d *Datastore) InsertTransactionTemplate(tpl *model.TransactionTemplate) er

}
func (d *Datastore) UpdateTransactionTemplate(input model.UpdateTransactionTemplate, tpl *model.TransactionTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -450,16 +496,25 @@ func (d *Datastore) UpdateTransactionTemplate(input model.UpdateTransactionTempl
}

func (d *Datastore) GetTransactionTemplate(id model.ProjectChildID, tpl *model.TransactionTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

tpl.ProjectChildID = id
return d.get(tpl)
}

func (d *Datastore) GetTransactionTemplatesForProject(projectID uuid.UUID, tpls *[]*model.TransactionTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

q := datastore.NewQuery("TransactionTemplate").Ancestor(model.ProjectNameKey(projectID)).Order("Index")
return d.getAll(q, tpls)
}

func (d *Datastore) DeleteTransactionTemplate(id model.ProjectChildID) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ttpl := model.TransactionTemplate{ProjectChildID: id}

_, txErr := d.dsClient.RunInTransaction(context.Background(), func(tx *datastore.Transaction) error {
Expand All @@ -482,6 +537,9 @@ func (d *Datastore) DeleteTransactionTemplate(id model.ProjectChildID) error {
// Transaction Executions

func (d *Datastore) InsertTransactionExecution(exe *model.TransactionExecution) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -514,13 +572,19 @@ func (d *Datastore) InsertTransactionExecution(exe *model.TransactionExecution)
}

func (d *Datastore) GetTransactionExecutionsForProject(projectID uuid.UUID, exes *[]*model.TransactionExecution) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

q := datastore.NewQuery("TransactionExecution").Ancestor(model.ProjectNameKey(projectID)).Order("Index")
return d.getAll(q, exes)
}

// Script Templates

func (d *Datastore) InsertScriptTemplate(tpl *model.ScriptTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -550,6 +614,9 @@ func (d *Datastore) InsertScriptTemplate(tpl *model.ScriptTemplate) error {
}

func (d *Datastore) UpdateScriptTemplate(input model.UpdateScriptTemplate, tpl *model.ScriptTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand Down Expand Up @@ -587,16 +654,25 @@ func (d *Datastore) UpdateScriptTemplate(input model.UpdateScriptTemplate, tpl *
}

func (d *Datastore) GetScriptTemplate(id model.ProjectChildID, tpl *model.ScriptTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

tpl.ProjectChildID = id
return d.get(tpl)
}

func (d *Datastore) GetScriptTemplatesForProject(projectID uuid.UUID, tpls *[]*model.ScriptTemplate) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

q := datastore.NewQuery("ScriptTemplate").Ancestor(model.ProjectNameKey(projectID)).Order("Index")
return d.getAll(q, tpls)
}

func (d *Datastore) DeleteScriptTemplate(id model.ProjectChildID) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

stpl := model.ScriptTemplate{ProjectChildID: id}

_, txErr := d.dsClient.RunInTransaction(context.Background(), func(tx *datastore.Transaction) error {
Expand All @@ -619,6 +695,9 @@ func (d *Datastore) DeleteScriptTemplate(id model.ProjectChildID) error {
// Script Executions

func (d *Datastore) InsertScriptExecution(exe *model.ScriptExecution) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

ctx, cancel := context.WithTimeout(context.Background(), d.conf.DatastoreTimeout)
defer cancel()

Expand All @@ -641,6 +720,9 @@ func (d *Datastore) InsertScriptExecution(exe *model.ScriptExecution) error {
}

func (d *Datastore) GetScriptExecutionsForProject(projectID uuid.UUID, exes *[]*model.ScriptExecution) error {
telemetry.StartRuntimeCalculation()
defer telemetry.EndRuntimeCalculation()

q := datastore.NewQuery("ScriptExecution").Ancestor(model.ProjectNameKey(projectID)).Order("Index")
return d.getAll(q, exes)
}

0 comments on commit 9ac7f6c

Please sign in to comment.