Skip to content

Commit

Permalink
Merge branch 'main' of github.com:rudderlabs/rudder-cp-sdk into chore…
Browse files Browse the repository at this point in the history
….poc
  • Loading branch information
achettyiitr committed Feb 1, 2024
2 parents 6bf7dcf + d4debaa commit e5d2953
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
3 changes: 1 addition & 2 deletions internal/clients/namespace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package namespace

import (
"context"
"errors"
"net/http"
"time"

Expand Down Expand Up @@ -48,5 +47,5 @@ func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceCon
}

func (c *Client) GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) (*modelv2.WorkspaceConfigs, error) {
return nil, errors.New("not implemented")
return c.GetWorkspaceConfigs(ctx)
}
3 changes: 1 addition & 2 deletions internal/clients/workspace/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package workspace

import (
"context"
"errors"
"net/http"
"time"

Expand Down Expand Up @@ -48,5 +47,5 @@ func (c *Client) GetWorkspaceConfigs(ctx context.Context) (*modelv2.WorkspaceCon
}

func (c *Client) GetUpdatedWorkspaceConfigs(ctx context.Context, updatedAfter time.Time) (*modelv2.WorkspaceConfigs, error) {
return nil, errors.New("not implemented")
return c.GetWorkspaceConfigs(ctx)
}
8 changes: 8 additions & 0 deletions internal/poller/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"time"

"github.com/rudderlabs/rudder-cp-sdk/profiler"

"github.com/rudderlabs/rudder-cp-sdk/modelv2"
"github.com/rudderlabs/rudder-go-kit/logger"
)
Expand Down Expand Up @@ -66,6 +68,9 @@ func (p *Poller) Start(ctx context.Context) {
}

func (p *Poller) poll(ctx context.Context) error {
p.log.Info("After processing config")
profiler.MemProfile(p.log)

var response *modelv2.WorkspaceConfigs
if p.updatedAt.IsZero() {
p.log.Debug("polling for workspace configs")
Expand All @@ -89,6 +94,9 @@ func (p *Poller) poll(ctx context.Context) error {
return fmt.Errorf("failed to handle workspace configs: %w", err)
}

p.log.Info("After processing config")
profiler.MemProfile(p.log)

// only update updatedAt if we managed to handle the response
// so that we don't miss any updates in case of an error
p.updatedAt = response.UpdatedAt()
Expand Down
21 changes: 21 additions & 0 deletions profiler/profiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package profiler

import (
"fmt"
"math/rand"
"os"
"runtime/pprof"
"time"

"github.com/rudderlabs/rudder-go-kit/logger"
)

var r = rand.New(rand.NewSource(time.Now().UnixNano()))

func MemProfile(log logger.Logger) {
f, _ := os.Create(fmt.Sprintf("heap-%d.pprof", r.Int()))
_ = pprof.WriteHeapProfile(f)
_ = f.Close()

log.Infof("heap profile written to %s", f.Name())
}

0 comments on commit e5d2953

Please sign in to comment.