github.com/smartcontractkit/chainlink-testing-framework/libs@v0.0.0-20240227141906-ec710b4eb1a3/config/pyroscope.go (about)

     1  package config
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/smartcontractkit/chainlink-testing-framework/libs/utils/net"
     8  )
     9  
    10  type PyroscopeConfig struct {
    11  	Enabled     *bool   `toml:"enabled"`
    12  	ServerUrl   *string `toml:"server_url"`
    13  	Key         *string `toml:"key_secret"`
    14  	Environment *string `toml:"environment"`
    15  }
    16  
    17  // Validate checks that the pyroscope config is valid, which means that
    18  // server url, environment and key are set and non-empty, but only if
    19  // pyroscope is enabled
    20  func (c *PyroscopeConfig) Validate() error {
    21  	if c.Enabled != nil && *c.Enabled {
    22  		if c.ServerUrl == nil {
    23  			return errors.New("pyroscope server url must be set")
    24  		}
    25  		if !net.IsValidURL(*c.ServerUrl) {
    26  			return fmt.Errorf("invalid pyroscope server url %s", *c.ServerUrl)
    27  		}
    28  		if c.Environment == nil || *c.Environment == "" {
    29  			return errors.New("pyroscope environment must be set")
    30  		}
    31  		if c.Key == nil || *c.Key == "" {
    32  			return errors.New("pyroscope key must be set")
    33  		}
    34  	}
    35  
    36  	return nil
    37  }