mirror of
https://github.com/hanzoai/o11y-foundry.git
synced 2026-10-30 18:26:45 +00:00
### Summary - Introduce a `kind` discriminator for Casting. Existing Casting without a kind field keep working, empty kind defaults to `Installation` - New `api/v1alpha1/installation/` subpackage with the Installation Casting, Spec types and holds its own JSON schema from its Go type: `installation/casting.schema.json` - New Machinery interface in `api/v1alpha1/machinery.go` exposes `Kind()` and `TrackableProperties()` so Dispatcher(Getv1alpha1 and Forge/Cast/Gauge) work across any kind without knowing its concrete type. - A root casting.schema.json lists every per-Kind schema to supports IDEs completion from one schema URL - cmd/foundryctl gen schemas reads a list of types from schemaTargets. Adding a kind means adding one entry. Related: https://github.com/SigNoz/platform-pod/issues/1970
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
package installation
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/swaggest/jsonschema-go"
|
|
"go.yaml.in/yaml/v3"
|
|
)
|
|
|
|
var _ yaml.Marshaler = (*TelemetryKeeperKind)(nil)
|
|
var _ yaml.Unmarshaler = (*TelemetryKeeperKind)(nil)
|
|
var _ json.Marshaler = (*TelemetryKeeperKind)(nil)
|
|
var _ json.Unmarshaler = (*TelemetryKeeperKind)(nil)
|
|
var _ fmt.Stringer = (*TelemetryKeeperKind)(nil)
|
|
var _ jsonschema.Enum = (*TelemetryKeeperKind)(nil)
|
|
|
|
var (
|
|
TelemetryKeeperKindClickhouseKeeper TelemetryKeeperKind = TelemetryKeeperKind{s: "clickhousekeeper"}
|
|
)
|
|
|
|
type TelemetryKeeperKind struct {
|
|
s string
|
|
}
|
|
|
|
func (kind TelemetryKeeperKind) String() string {
|
|
return kind.s
|
|
}
|
|
|
|
func TelemetryKeeperKinds() []TelemetryKeeperKind {
|
|
return []TelemetryKeeperKind{TelemetryKeeperKindClickhouseKeeper}
|
|
}
|
|
|
|
func (kind TelemetryKeeperKind) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(kind.String())
|
|
}
|
|
|
|
func (kind *TelemetryKeeperKind) UnmarshalJSON(text []byte) error {
|
|
var str string
|
|
if err := json.Unmarshal(text, &str); err != nil {
|
|
return err
|
|
}
|
|
|
|
return kind.UnmarshalText([]byte(str))
|
|
}
|
|
|
|
func (kind *TelemetryKeeperKind) UnmarshalText(text []byte) error {
|
|
for _, availableKind := range TelemetryKeeperKinds() {
|
|
if availableKind.String() == string(text) {
|
|
*kind = availableKind
|
|
return nil
|
|
}
|
|
}
|
|
if text == nil {
|
|
*kind = TelemetryKeeperKind{s: ""}
|
|
return nil
|
|
}
|
|
return errors.New("invalid telemetry keeper kind: " + string(text))
|
|
}
|
|
|
|
func (kind TelemetryKeeperKind) MarshalText() ([]byte, error) {
|
|
return []byte(kind.String()), nil
|
|
}
|
|
|
|
func (kind *TelemetryKeeperKind) UnmarshalYAML(node *yaml.Node) error {
|
|
return kind.UnmarshalText([]byte(node.Value))
|
|
}
|
|
|
|
func (kind TelemetryKeeperKind) MarshalYAML() (any, error) {
|
|
return kind.String(), nil
|
|
}
|
|
|
|
func (kind TelemetryKeeperKind) Enum() []any {
|
|
kinds := []any{}
|
|
for _, kind := range TelemetryKeeperKinds() {
|
|
kinds = append(kinds, kind.String())
|
|
}
|
|
|
|
return kinds
|
|
}
|