forked from TrueCloudLab/frostfs-api-go
[#12] tracing: Add tracing package
Add tracing config, implementation and setup Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
3a7280968b
commit
816628d37d
6 changed files with 807 additions and 0 deletions
74
pkg/tracing/config.go
Normal file
74
pkg/tracing/config.go
Normal file
|
@ -0,0 +1,74 @@
|
|||
package tracing
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Exporter is type of tracing target.
|
||||
type Exporter string
|
||||
|
||||
const (
|
||||
Stdout Exporter = "stdout"
|
||||
OTLPgRPC Exporter = "otlp_grpc"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
// Enabled is true, if tracing enabled.
|
||||
Enabled bool
|
||||
// Exporter is collector type.
|
||||
Exporter Exporter
|
||||
// Endpoint is collector endpoint for OTLP exporters.
|
||||
Endpoint string
|
||||
|
||||
// Service is service name that will be used in tracing.
|
||||
// Mandatory.
|
||||
Service string
|
||||
// InstanceID is identity of service instance.
|
||||
// Optional.
|
||||
InstanceID string
|
||||
// Version is version of service instance.
|
||||
// Optional.
|
||||
Version string
|
||||
}
|
||||
|
||||
func (c *Config) validate() error {
|
||||
if !c.Enabled {
|
||||
return nil
|
||||
}
|
||||
|
||||
if c.Exporter != Stdout && c.Exporter != OTLPgRPC {
|
||||
return fmt.Errorf("tracing config error: unknown exporter '%s', valid values are %v",
|
||||
c.Exporter, []string{string(Stdout), string(OTLPgRPC)})
|
||||
}
|
||||
|
||||
if len(c.Service) == 0 {
|
||||
return fmt.Errorf("tracing config error: service name must be specified")
|
||||
}
|
||||
|
||||
if c.Exporter == OTLPgRPC && len(c.Endpoint) == 0 {
|
||||
return fmt.Errorf("tracing config error: exporter '%s' requires endpoint", c.Exporter)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Config) hasChange(other *Config) bool {
|
||||
if !c.Enabled && !other.Enabled {
|
||||
return false
|
||||
}
|
||||
if c.Enabled != other.Enabled {
|
||||
return true
|
||||
}
|
||||
|
||||
if c.Exporter == Stdout && other.Exporter == Stdout {
|
||||
return !c.serviceInfoEqual(other)
|
||||
}
|
||||
|
||||
return c.Exporter != other.Exporter ||
|
||||
c.Endpoint != other.Endpoint ||
|
||||
!c.serviceInfoEqual(other)
|
||||
}
|
||||
|
||||
func (c *Config) serviceInfoEqual(other *Config) bool {
|
||||
return c.Service == other.Service &&
|
||||
c.InstanceID == other.InstanceID &&
|
||||
c.Version == other.Version
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue