Skip to content

Commit

Permalink
refactor(gnostats): export Agent struct
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi committed Aug 28, 2024
1 parent 83d08e5 commit a907611
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions contribs/gnostats/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import (
"github.com/gnolang/gnostats/proto"
)

// angent holds both the injected Gno node RPC client and the Hub gRPC client.
type agent struct {
// Agent holds both the injected Gno node RPC client and the Hub gRPC client
type Agent struct {
hClient proto.HubClient
rClient rpcClient
pollInterval time.Duration // Minimum time interval between two data points
}

type Option func(*agent)
type Option func(*Agent)

// WithPollInterval sets the agent poll interval between two data points
func WithPollInterval(interval time.Duration) Option {
return func(c *agent) {
return func(c *Agent) {
c.pollInterval = interval
}
}

// Start registers with the Hub using Gno node static info, then pushes dynamic
// info from the Gno node to the Hub at intervals specified by pollInterval
func (a *agent) Start(ctx context.Context) error {
func (a *Agent) Start(ctx context.Context) error {
collector := NewCollector(a.rClient)

// Get static info from the Gno node
Expand Down Expand Up @@ -69,18 +69,18 @@ func (a *agent) Start(ctx context.Context) error {
}

// NewAgent creates a new agent using the provided clients and options
func NewAgent(hClient proto.HubClient, rClient rpcClient, options ...Option) *agent {
func NewAgent(hClient proto.HubClient, rClient rpcClient, options ...Option) *Agent {
const defaultInverval = time.Second

a := &agent{
agent := &Agent{
hClient: hClient,
rClient: rClient,
pollInterval: defaultInverval,
}

for _, opt := range options {
opt(a)
opt(agent)
}

return a
return agent
}

0 comments on commit a907611

Please sign in to comment.