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
84 lines
1.8 KiB
Go
84 lines
1.8 KiB
Go
package installation
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/swaggest/jsonschema-go"
|
|
"go.yaml.in/yaml/v3"
|
|
)
|
|
|
|
var _ yaml.Marshaler = (*TelemetryStoreKind)(nil)
|
|
var _ yaml.Unmarshaler = (*TelemetryStoreKind)(nil)
|
|
var _ json.Marshaler = (*TelemetryStoreKind)(nil)
|
|
var _ json.Unmarshaler = (*TelemetryStoreKind)(nil)
|
|
var _ fmt.Stringer = (*TelemetryStoreKind)(nil)
|
|
var _ jsonschema.Enum = (*TelemetryStoreKind)(nil)
|
|
|
|
var (
|
|
TelemetryStoreKindClickhouse TelemetryStoreKind = TelemetryStoreKind{s: "clickhouse"}
|
|
)
|
|
|
|
type TelemetryStoreKind struct {
|
|
s string
|
|
}
|
|
|
|
func TelemetryStoreKinds() []TelemetryStoreKind {
|
|
return []TelemetryStoreKind{TelemetryStoreKindClickhouse}
|
|
}
|
|
|
|
func (kind TelemetryStoreKind) String() string {
|
|
return kind.s
|
|
}
|
|
|
|
func (kind TelemetryStoreKind) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(kind.String())
|
|
}
|
|
|
|
func (kind *TelemetryStoreKind) UnmarshalJSON(text []byte) error {
|
|
var str string
|
|
if err := json.Unmarshal(text, &str); err != nil {
|
|
return err
|
|
}
|
|
|
|
return kind.UnmarshalText([]byte(str))
|
|
}
|
|
|
|
func (kind *TelemetryStoreKind) UnmarshalText(text []byte) error {
|
|
for _, availableKind := range TelemetryStoreKinds() {
|
|
if availableKind.String() == string(text) {
|
|
*kind = availableKind
|
|
return nil
|
|
}
|
|
}
|
|
|
|
if text == nil {
|
|
*kind = TelemetryStoreKind{s: ""}
|
|
return nil
|
|
}
|
|
|
|
return errors.New("invalid telemetry store kind: " + string(text))
|
|
}
|
|
|
|
func (kind TelemetryStoreKind) MarshalText() ([]byte, error) {
|
|
return []byte(kind.String()), nil
|
|
}
|
|
|
|
func (kind *TelemetryStoreKind) UnmarshalYAML(node *yaml.Node) error {
|
|
return kind.UnmarshalText([]byte(node.Value))
|
|
}
|
|
|
|
func (kind TelemetryStoreKind) MarshalYAML() (any, error) {
|
|
return kind.String(), nil
|
|
}
|
|
|
|
func (kind TelemetryStoreKind) Enum() []any {
|
|
kinds := []any{}
|
|
for _, kind := range TelemetryStoreKinds() {
|
|
kinds = append(kinds, kind.String())
|
|
}
|
|
|
|
return kinds
|
|
}
|