Skip to content

Commit

Permalink
Initialize with a no-op client
Browse files Browse the repository at this point in the history
Signed-off-by: Paschalis Tsilias <[email protected]>
  • Loading branch information
tpaschalis committed Feb 1, 2024
1 parent c5ff4d4 commit 91c2ff8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
41 changes: 41 additions & 0 deletions service/remotecfg/noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package remotecfg

import (
"context"
"errors"

"connectrpc.com/connect"
agentv1 "github.com/grafana/agent-remote-config/api/gen/proto/go/agent/v1"
)

type noopClient struct{}

// GetConfig returns the agent's configuration.
func (c noopClient) GetConfig(context.Context, *connect.Request[agentv1.GetConfigRequest]) (*connect.Response[agentv1.GetConfigResponse], error) {
return nil, errors.New("noop client")
}

// GetAgent returns information about the agent.
func (c noopClient) GetAgent(context.Context, *connect.Request[agentv1.GetAgentRequest]) (*connect.Response[agentv1.Agent], error) {
return nil, errors.New("noop client")
}

// ListAgents returns information about all agents.
func (c noopClient) ListAgents(context.Context, *connect.Request[agentv1.ListAgentsRequest]) (*connect.Response[agentv1.Agents], error) {
return nil, errors.New("noop client")
}

// CreateAgent registers a new agent.
func (c noopClient) CreateAgent(context.Context, *connect.Request[agentv1.CreateAgentRequest]) (*connect.Response[agentv1.Agent], error) {
return nil, errors.New("noop client")
}

// UpdateAgent updates an existing agent.
func (c noopClient) UpdateAgent(context.Context, *connect.Request[agentv1.UpdateAgentRequest]) (*connect.Response[agentv1.Agent], error) {
return nil, errors.New("noop client")
}

// DeleteAgent deletes an existing agent.
func (c noopClient) DeleteAgent(context.Context, *connect.Request[agentv1.DeleteAgentRequest]) (*connect.Response[agentv1.DeleteAgentResponse], error) {
return nil, errors.New("noop client")
}
9 changes: 5 additions & 4 deletions service/remotecfg/remotecfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ func New(opts Options) (*Service, error) {
}

return &Service{
opts: opts,
ticker: time.NewTicker(math.MaxInt64),
opts: opts,
asClient: noopClient{},
ticker: time.NewTicker(math.MaxInt64),
}, nil
}

Expand Down Expand Up @@ -257,8 +258,8 @@ func (s *Service) Update(newConfig any) error {
s.mut.Lock()
defer s.mut.Unlock()
s.ticker.Reset(math.MaxInt64)
s.asClient = nil
s.args.HTTPClientConfig = nil
s.asClient = noopClient{}
s.args.HTTPClientConfig = config.CloneDefaultHTTPClientConfig()
s.currentConfigHash = ""
return nil
}
Expand Down

0 comments on commit 91c2ff8

Please sign in to comment.