Skip to content
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 in v1beta1 #2603

Open
pavolloffay opened this issue Feb 3, 2024 · 4 comments
Open

Remove unnecessary config marshalling in v1beta1 #2603

pavolloffay opened this issue Feb 3, 2024 · 4 comments
Assignees
Labels
area:collector Issues for deploying collector help wanted Extra attention is needed

Comments

@pavolloffay
Copy link
Member

Component(s)

collector

Describe the issue you're reporting

Created from #2532

@crossoverJie
Copy link
Contributor

@pavolloffay
I'd like to fix this issue.

We can create a hardcoded method:

func (c *Config) ToMap() map[string]interface{} {
	result := make(map[string]interface{})

	result["receivers"] = c.Receivers.Object
	result["exporters"] = c.Exporters.Object
	if c.Processors != nil {
		result["processors"] = c.Processors.Object
	}

	if c.Connectors != nil {
		result["connectors"] = c.Connectors.Object
	}
	if c.Extensions != nil {
		result["extensions"] = c.Extensions.Object

	}
	serviceMap := make(map[string]interface{})
	if c.Service.Extensions != nil {
		serviceMap["extensions"] = c.Service.Extensions
	}
	if c.Service.Telemetry != nil {
		serviceMap["telemetry"] = c.Service.Telemetry
	}
	serviceMap["pipelines"] = c.Service.Pipelines.Object
	result["service"] = serviceMap

	return result
}

Or use serialization method:

func (c *Config) ToMap() (map[string]interface{}, error) {
	var result map[string]interface{}
	v, err := json.Marshal(c)
	if err != nil {
		return nil, err
	}
	err = json.Unmarshal(v, &result)
	if err != nil {
		return nil, err
	}
	return result, err
}

But this will still cause multiple calls to the serialization and deserialization method.

BWT, maybe we can replace map[interface{}]interface{} with map[string]interface{} so we can avoid redundant type assertions.

pipelineV, withPipelineCfg := pipelineID.(string)

@jaronoff97 jaronoff97 changed the title Remove unnecessary config marshalling in v1alpha2 Remove unnecessary config marshalling in v1beta1 Apr 18, 2024
@jaronoff97
Copy link
Contributor

@crossoverJie yep, already working on this :)

@pavolloffay
Copy link
Member Author

@jaronoff97 is this done?

@jaronoff97
Copy link
Contributor

Almost! We still have this code block that we should probably try and fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:collector Issues for deploying collector help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants