mirror of
https://github.com/hanzoai/o11y.git
synced 2026-11-02 14:03:38 +00:00
Re-sync the entire SigNoz-derived Go tree to a clean fork of latest SigNoz main (upstream 3e6339019), eliminating the version-skew that broke `go build ./...` (mixed-era packages, ~14 imported-but-absent packages, partial signoz->o11y / clickhouse->datastore rebrands, self-import cycle, duplicate package decls). - pkg/ + cmd/ wholesale replaced with latest SigNoz; imports rewritten github.com/SigNoz/signoz/ -> github.com/hanzoai/o11y/. - Adopt SigNoz's CURRENT structure (resourcefilter->telemetryresourcefilter, integrationtypes->cloudintegrationtypes, roletypes/grammar/times folded in upstream); old paths dropped. - Fork deps repathed to hanzoai + bumped: signoz-otel-collector v0.144.6, clickhouse-go-mock v0.14.1, govaluate v0.1.0; expr-lang/expr => hanzoai/expr v1.17.8 (replace). go.mod reconciled from latest SigNoz; go.sum re-tidied. - ee/ + cmd/enterprise stripped — o11y stays MIT-only; community edition imports no ee packages. - Preserved o11y additions: module path github.com/hanzoai/o11y, mount.go (cloud.Register/zip mount adapter, HIP-0106), NOTICE + LICENSE (SigNoz §4c attribution retained; upstream pkg files are headerless per SigNoz convention). - Reverted o11y cosmetic renames (o11y*/datastore*) and experimental originals (authz/iamauthz, billing, zapreceiver, zapmetricreceiver) to SigNoz canonical to kill the skew; snapshots retained in git history for re-layering. go build ./... = exit 0. go vet clean except benign "unreachable code" in generated ANTLR parser files (inherited from upstream).
196 lines
4.6 KiB
Go
196 lines
4.6 KiB
Go
package otelconfig
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"go.opentelemetry.io/collector/confmap"
|
|
)
|
|
|
|
type ConfigParser struct {
|
|
lock sync.Mutex
|
|
agentConf *confmap.Conf
|
|
}
|
|
|
|
func NewConfigParser(agentConf *confmap.Conf) ConfigParser {
|
|
return ConfigParser{
|
|
agentConf: agentConf,
|
|
}
|
|
}
|
|
|
|
func toMap(i interface{}) map[string]interface{} {
|
|
return i.(map[string]interface{})
|
|
}
|
|
|
|
func toList(i interface{}) []interface{} {
|
|
return i.([]interface{})
|
|
}
|
|
|
|
// sent when key is not found in config
|
|
func emptyMap() map[string]interface{} {
|
|
return map[string]interface{}{}
|
|
}
|
|
|
|
func emptyList() []interface{} {
|
|
return []interface{}{}
|
|
}
|
|
|
|
func (cp *ConfigParser) Service() map[string]interface{} {
|
|
service := cp.agentConf.Get("service")
|
|
if service == nil {
|
|
return emptyMap()
|
|
}
|
|
return toMap(service)
|
|
}
|
|
|
|
// components gets the high level parts like receivers, exporters, processors etc
|
|
func (cp *ConfigParser) components(partName, nameOptional string) map[string]interface{} {
|
|
parts := cp.agentConf.Get(partName)
|
|
if parts == nil {
|
|
return emptyMap()
|
|
}
|
|
|
|
parsedParts := toMap(parts)
|
|
if nameOptional != "" {
|
|
if p, ok := parsedParts[nameOptional]; ok {
|
|
return p.(map[string]interface{})
|
|
} else {
|
|
return emptyMap()
|
|
}
|
|
}
|
|
|
|
return parsedParts
|
|
}
|
|
|
|
func (cp *ConfigParser) Processors() map[string]interface{} {
|
|
return cp.components("processors", "")
|
|
}
|
|
|
|
func (cp *ConfigParser) Processor(name string) map[string]interface{} {
|
|
return cp.components("processors", name)
|
|
}
|
|
|
|
func (cp *ConfigParser) Exporters() map[string]interface{} {
|
|
return cp.components("exporters", "")
|
|
}
|
|
|
|
func (cp *ConfigParser) Exporter(name string) map[string]interface{} {
|
|
return cp.components("exporters", name)
|
|
}
|
|
|
|
func (cp *ConfigParser) Receivers() map[string]interface{} {
|
|
return cp.components("receivers", "")
|
|
}
|
|
|
|
func (cp *ConfigParser) Receiver(name string) map[string]interface{} {
|
|
return cp.components("receivers", name)
|
|
}
|
|
|
|
func (cp *ConfigParser) Pipelines(nameOptional string) map[string]interface{} {
|
|
services := cp.Service()
|
|
if p, ok := services["pipelines"]; ok {
|
|
pipelines := toMap(p)
|
|
if nameOptional != "" {
|
|
if namedPipeline, ok := pipelines[nameOptional]; ok {
|
|
return toMap(namedPipeline)
|
|
} else {
|
|
return emptyMap()
|
|
}
|
|
|
|
}
|
|
return pipelines
|
|
}
|
|
return emptyMap()
|
|
}
|
|
|
|
// component can be "recevers", "exporter" or "processors"
|
|
func (cp *ConfigParser) PipelineComponent(pipelineName, pipelineComponent string) []interface{} {
|
|
pipeline := cp.Pipelines(pipelineName)
|
|
if exporters, ok := pipeline[pipelineComponent]; ok {
|
|
exporters := toList(exporters)
|
|
return exporters
|
|
}
|
|
return emptyList()
|
|
}
|
|
|
|
func (cp *ConfigParser) PipelineExporters(pipelineName string) []interface{} {
|
|
return cp.PipelineComponent(pipelineName, "exporters")
|
|
}
|
|
|
|
func (cp *ConfigParser) PipelineReceivers(pipelineName string) []interface{} {
|
|
return cp.PipelineComponent(pipelineName, "receivers")
|
|
}
|
|
|
|
func (cp *ConfigParser) PipelineProcessors(pipelineName string) []interface{} {
|
|
return cp.PipelineComponent(pipelineName, "processors")
|
|
}
|
|
|
|
func (cp *ConfigParser) CheckPipelineExists(name string) bool {
|
|
if name == "" {
|
|
return false
|
|
}
|
|
pipelines := cp.Pipelines(name)
|
|
return len(pipelines) > 0
|
|
}
|
|
|
|
// CheckEntryInPipeline lets you look for an entry in pipeline by receiver, processor or exporter name
|
|
func (cp *ConfigParser) CheckEntryInPipeline(pipelineName, pipelineComponent, name string) bool {
|
|
if pipelineName == "" || pipelineComponent == "" || name == "" {
|
|
return false
|
|
}
|
|
|
|
list := cp.PipelineComponent(pipelineName, pipelineComponent)
|
|
var found bool
|
|
for _, item := range list {
|
|
if item == name {
|
|
found = true
|
|
}
|
|
}
|
|
|
|
return found
|
|
}
|
|
|
|
func (cp *ConfigParser) CheckExporterInPipeline(pipelineName, name string) bool {
|
|
return cp.CheckEntryInPipeline(pipelineName, "exporters", name)
|
|
}
|
|
|
|
func (cp *ConfigParser) CheckProcessorInPipeline(pipelineName, name string) bool {
|
|
return cp.CheckEntryInPipeline(pipelineName, "processors", name)
|
|
}
|
|
|
|
func (cp *ConfigParser) Merge(c *confmap.Conf) {
|
|
cp.lock.Lock()
|
|
defer cp.lock.Unlock()
|
|
_ = cp.agentConf.Merge(c)
|
|
}
|
|
|
|
func (cp *ConfigParser) UpdateProcessors(processors map[string]interface{}) {
|
|
updates := cp.Processors()
|
|
|
|
for key, params := range processors {
|
|
updates[key] = params
|
|
}
|
|
|
|
updatedProcessors := map[string]interface{}{
|
|
"processors": updates,
|
|
}
|
|
|
|
updatedProcessorConf := confmap.NewFromStringMap(updatedProcessors)
|
|
|
|
cp.Merge(updatedProcessorConf)
|
|
}
|
|
|
|
func (cp *ConfigParser) UpdateProcsInPipeline(pipelineName string, list []interface{}) {
|
|
|
|
serviceConf := map[string]interface{}{
|
|
"service": map[string]interface{}{
|
|
"pipelines": map[string]interface{}{
|
|
pipelineName: map[string]interface{}{
|
|
"processors": list,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
cp.Merge(confmap.NewFromStringMap(serviceConf))
|
|
}
|