feat: agent metadata with custom collectors
This commit is contained in:
31
internal/agent/metadata/collector/buildinfo/collector.go
Normal file
31
internal/agent/metadata/collector/buildinfo/collector.go
Normal file
@ -0,0 +1,31 @@
|
||||
package buildinfo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime/debug"
|
||||
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/agent/metadata"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
const (
|
||||
MetadataBuildInfo = "buildinfo"
|
||||
)
|
||||
|
||||
type Collector struct{}
|
||||
|
||||
// Collect implements agent.MetadataCollector
|
||||
func (c *Collector) Collect(ctx context.Context) (string, string, error) {
|
||||
buildInfo, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "", "", errors.WithStack(metadata.ErrMetadataNotAvailable)
|
||||
}
|
||||
|
||||
return MetadataBuildInfo, buildInfo.String(), nil
|
||||
}
|
||||
|
||||
func NewCollector() *Collector {
|
||||
return &Collector{}
|
||||
}
|
||||
|
||||
var _ metadata.Collector = &Collector{}
|
Reference in New Issue
Block a user