func loadAgentConfig(c *config.Agent) error {
	b, err := ioutil.ReadFile(c.Config)
	switch {
	case err == nil:
	case os.IsNotExist(err):
		return nil
	default:
		return err
	}
	var a config.Agent
	if err = yaml.Unmarshal(b, &a); err != nil {
		return err
	}
	c.Tags = mergeTags(a.Tags, c.Tags)
	for _, t := range a.Targets {
		t.Tags = mergeTags(t.Tags, c.Tags)
		c.Targets = append(c.Targets, t)
	}
	return nil
}
loadAgentConfig is a hack for viper parser, which can't merge maps:
https://github.com/spf13/viper#accessing-nested-keys.
TODO(kolesnikovae): find a way to get rid of the function.
package cli
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"github.com/kardianos/service"
	"github.com/sirupsen/logrus"
	"gopkg.in/yaml.v2"
	"github.com/pyroscope-io/pyroscope/pkg/agent/target"
	"github.com/pyroscope-io/pyroscope/pkg/agent/upstream/remote"
	"github.com/pyroscope-io/pyroscope/pkg/config"
)
type agentService struct {
	remote *remote.Remote
	tgtMgr *target.Manager
}
func newAgentService(logger *logrus.Logger, cfg *config.Agent) (*agentService, error) {
	rc := remote.RemoteConfig{
		AuthToken:              cfg.AuthToken,
		UpstreamThreads:        cfg.UpstreamThreads,
		UpstreamAddress:        cfg.ServerAddress,
		UpstreamRequestTimeout: cfg.UpstreamRequestTimeout,
		ManualStart:            true,
	}
	upstream, err := remote.New(rc, logger)
	if err != nil {
		return nil, fmt.Errorf("upstream configuration: %w", err)
	}
	s := agentService{
		tgtMgr: target.NewManager(logger, upstream, cfg),
		remote: upstream,
	}
	return &s, nil
}
func (svc *agentService) Start(_ service.Service) error {
	svc.remote.Start()
	svc.tgtMgr.Start()
	return nil
}
func (svc *agentService) Stop(_ service.Service) error {
	svc.tgtMgr.Stop()
	svc.remote.Stop()
	return nil
}