Skip to content

Commit

Permalink
Add opentracing to sync and cleaner services
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Cobden committed Sep 20, 2018
1 parent 836e8a9 commit f780e38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions users-sync/attrsync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package attrsync

import (
"context"
"github.com/opentracing/opentracing-go"
"time"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -118,8 +119,10 @@ func (c *AttributeSyncer) sync() {
cancel()
return
}
span, syncCtx := opentracing.StartSpanFromContext(ctx, "Sync")
span.LogKV("userFilter", userFilter)

err := c.syncUsers(ctx, userFilter)
err := c.syncUsers(syncCtx, userFilter)
if err != nil {
c.log.WithField("error", err).Errorln("Error syncing users")
}
Expand All @@ -139,14 +142,16 @@ func (c *AttributeSyncer) syncUsers(ctx context.Context, userFilter filter.User)
break
}

span, pageCtx := opentracing.StartSpanFromContext(ctx, "SyncUsersPage")
span.LogKV("count", len(users), "page", page)
c.log.WithFields(map[string]interface{}{
"filter": userFilter,
"count": len(users),
"page": page,
}).Debugf("Syncing attributes for users")

for _, user := range users {
ctxWithID := commonUser.InjectUserID(ctx, user.ID)
ctxWithID := commonUser.InjectUserID(pageCtx, user.ID)
instrument.CollectedRequest(
ctxWithID,
"syncUser",
Expand Down
6 changes: 6 additions & 0 deletions users-sync/cleaner/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cleaner

import (
"context"
"github.com/opentracing/opentracing-go"
"github.com/weaveworks/common/logging"
"net/http"
"time"
Expand Down Expand Up @@ -121,20 +122,25 @@ func (c *OrgCleaner) Trigger() {
}

func (c *OrgCleaner) findAndClean(ctx context.Context) {
_, ctx = opentracing.StartSpanFromContext(ctx, "FindAndClean")
findAndCleanTotal.Inc()
ids, err := c.db.FindUncleanedOrgIDs(ctx)
if err != nil {
c.log.Warnf("cannot find uncleaned org IDs, error: %s\n", err)
errorFindUncleanedOrgIDsTotal.Inc()
return
}

uncleanedOrgs.Set(float64(len(ids)))
for _, id := range ids {
c.clean(ctx, id)
}
}

func (c *OrgCleaner) clean(ctx context.Context, id string) {
span, ctx := opentracing.StartSpanFromContext(ctx, "Clean")
span.LogKV("OrgId", id)

done := c.runCleanupJobs(ctx, id)
if done {
if err := c.db.SetOrganizationCleanup(ctx, id, true); err != nil {
Expand Down

0 comments on commit f780e38

Please sign in to comment.