-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary config marshalling wherever possible #2735
Changes from all commits
c94db2f
f50ef83
07c0ee0
a1bf2d3
7e80a33
5a4e4e0
6c0b5e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,10 +30,10 @@ | |
} | ||
|
||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | ||
func (in *AnyConfig) DeepCopyInto(out *AnyConfig) { | ||
*out = *in | ||
if in.Object != nil { | ||
in, out := &in.Object, &out.Object | ||
func (c *AnyConfig) DeepCopyInto(out *AnyConfig) { | ||
*out = *c | ||
if c.Object != nil { | ||
in, out := &c.Object, &out.Object | ||
*out = make(map[string]interface{}, len(*in)) | ||
for key, val := range *in { | ||
(*out)[key] = val | ||
|
@@ -42,12 +42,12 @@ | |
} | ||
|
||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AnyConfig. | ||
func (in *AnyConfig) DeepCopy() *AnyConfig { | ||
if in == nil { | ||
func (c *AnyConfig) DeepCopy() *AnyConfig { | ||
if c == nil { | ||
return nil | ||
} | ||
out := new(AnyConfig) | ||
in.DeepCopyInto(out) | ||
c.DeepCopyInto(out) | ||
return out | ||
} | ||
|
||
|
@@ -98,14 +98,56 @@ | |
return buf.String(), nil | ||
} | ||
|
||
// MetricsConfig comes from the collector | ||
type MetricsConfig struct { | ||
// Level is the level of telemetry metrics, the possible values are: | ||
// - "none" indicates that no telemetry data should be collected; | ||
// - "basic" is the recommended and covers the basics of the service telemetry. | ||
// - "normal" adds some other indicators on top of basic. | ||
// - "detailed" adds dimensions and views to the previous levels. | ||
Level string `json:"level,omitempty" yaml:"level,omitempty"` | ||
|
||
// Address is the [address]:port that metrics exposition should be bound to. | ||
Address string `json:"address,omitempty" yaml:"address,omitempty"` | ||
} | ||
|
||
type Telemetry struct { | ||
Metrics MetricsConfig `json:"metrics,omitempty" yaml:"metrics,omitempty"` | ||
|
||
// Resource specifies user-defined attributes to include with all emitted telemetry. | ||
// Note that some attributes are added automatically (e.g. service.version) even | ||
// if they are not specified here. In order to suppress such attributes the | ||
// attribute must be specified in this map with null YAML value (nil string pointer). | ||
Resource map[string]*string `json:"resource,omitempty" yaml:"resource,omitempty"` | ||
} | ||
|
||
type Service struct { | ||
Extensions *[]string `json:"extensions,omitempty" yaml:"extensions,omitempty"` | ||
Extensions []string `json:"extensions,omitempty" yaml:"extensions,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC this will enforce marshalling of empty array for extensions. Is this necessary? |
||
// +kubebuilder:pruning:PreserveUnknownFields | ||
Telemetry *AnyConfig `json:"telemetry,omitempty" yaml:"telemetry,omitempty"` | ||
// +kubebuilder:pruning:PreserveUnknownFields | ||
Pipelines AnyConfig `json:"pipelines" yaml:"pipelines"` | ||
} | ||
|
||
// GetTelemetry serves as a helper function to access the fields we care about in the underlying telemetry struct. | ||
// This exists to avoid needing to worry extra fields in the telemetry struct. | ||
func (s *Service) GetTelemetry() *Telemetry { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we add a test for this? Getting a telemetry from an existing yaml? |
||
if s.Telemetry == nil { | ||
return nil | ||
} | ||
// Convert map to JSON bytes | ||
jsonData, err := json.Marshal(s.Telemetry) | ||
if err != nil { | ||
return nil | ||
} | ||
t := &Telemetry{} | ||
// Unmarshal JSON into the provided struct | ||
if err := json.Unmarshal(jsonData, t); err != nil { | ||
return nil | ||
} | ||
return t | ||
} | ||
|
||
// Returns null objects in the config. | ||
func (c Config) nullObjects() []string { | ||
var nullKeys []string | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be introduced in a separate PR?