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

Enhance getComponentHandler for selective data retrieval exposing options #1949

Open
daxroc opened this issue Oct 21, 2024 · 1 comment
Open

Comments

@daxroc
Copy link

daxroc commented Oct 21, 2024

This suggestion improves the getComponentHandler function by introducing support for selective querying of component data using URL query parameters (GetHealth, GetArguments, GetExports, GetDebugInfo).

This update optimizes data retrieval for environments with many targets, allowing api consumers to minimize unnecessary data transfers. For instance, when working with tens of thousands of targets, you may want to fetch detailed data (such as arguments) only once, while requesting debug information more frequently and from all cluster members.

Not sure if I missed anything, Happy to submit the PR

package component

// helper
func ParseBool(value string) bool {
	return value != "false"
}
func getComponentHandler(host service.Host) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		vars := mux.Vars(r)
		requestedComponent := component.ParseID(vars["id"])
		requestedHealth := component.ParseBool(r.URL.Query().Get("health"))
		requestedArguments := component.ParseBool(r.URL.Query().Get("arguments"))
		requestedExports := component.ParseBool(r.URL.Query().Get("exports"))
		requestedDebugInfo := component.ParseBool(r.URL.Query().Get("debugInfo"))

		component, err := host.GetComponent(requestedComponent, component.InfoOptions{
			GetHealth:    requestedHealth,
			GetArguments: requestedArguments,
			GetExports:   requestedExports,
			GetDebugInfo: requestedDebugInfo,
		})
		if err != nil {
			http.NotFound(w, r)
			return
		}

		bb, err := json.Marshal(component)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		_, _ = w.Write(bb)
	}
}
@daxroc
Copy link
Author

daxroc commented Oct 21, 2024

PR-1950 Expose Options

@daxroc daxroc mentioned this issue Oct 21, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant