Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions frontend/src/liboperator/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,23 @@ func CreateHttpHandlers(
router.HandleFunc("/infra_config", func(w http.ResponseWriter, r *http.Request) {
ReplyJSONOK(w, config)
}).Methods("GET")
router.HandleFunc("/context", func(w http.ResponseWriter, r *http.Request) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a endpoint /_debug/varz in HO and I think they aim to achieve the same, if so, let's use the same path for alignment.

getContext(w, r)
}).Methods("GET")
return router
}

func getContext(w http.ResponseWriter, r *http.Request) {
hostname, err := os.Hostname()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we are only querying the hostname. In the future context as a whole should have more information. Wondering whether you can populate context fields that won't change during the lifetime of the operator when the operator starts and the return the already populated struct on every GET request rather than querying the system everytime?

if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
ctx := make(map[string]interface{})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use a defined struct rather than a free form map to keep track of what's being returned.

ctx["hostname"] = hostname
ReplyJSONOK(w, ctx)
}

// Control endpoint
func controlEndpoint(c *JSONUnix, pool *DevicePool) {
log.Println("Controller connected")
Expand Down
Loading