mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
feat(edge): optimize Edge Stack retrieval BE-11555 (#294)
This commit is contained in:
parent
f8b2ee8c0d
commit
1ed9a0106e
1 changed files with 24 additions and 5 deletions
|
@ -1,8 +1,10 @@
|
||||||
package endpointedge
|
package endpointedge
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
"github.com/portainer/portainer/api/edge"
|
"github.com/portainer/portainer/api/edge"
|
||||||
|
@ -13,8 +15,12 @@ import (
|
||||||
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
||||||
"github.com/portainer/portainer/pkg/libhttp/request"
|
"github.com/portainer/portainer/pkg/libhttp/request"
|
||||||
"github.com/portainer/portainer/pkg/libhttp/response"
|
"github.com/portainer/portainer/pkg/libhttp/response"
|
||||||
|
|
||||||
|
"golang.org/x/sync/singleflight"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var edgeStackSingleFlightGroup = singleflight.Group{}
|
||||||
|
|
||||||
// @summary Inspect an Edge Stack for an Environment(Endpoint)
|
// @summary Inspect an Edge Stack for an Environment(Endpoint)
|
||||||
// @description **Access policy**: public
|
// @description **Access policy**: public
|
||||||
// @tags edge, endpoints, edge_stacks
|
// @tags edge, endpoints, edge_stacks
|
||||||
|
@ -42,13 +48,26 @@ func (handler *Handler) endpointEdgeStackInspect(w http.ResponseWriter, r *http.
|
||||||
return httperror.BadRequest("Invalid edge stack identifier route variable", fmt.Errorf("invalid Edge stack route variable: %w. Environment name: %s", err, endpoint.Name))
|
return httperror.BadRequest("Invalid edge stack identifier route variable", fmt.Errorf("invalid Edge stack route variable: %w. Environment name: %s", err, endpoint.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s, err, _ := edgeStackSingleFlightGroup.Do(strconv.Itoa(edgeStackID), func() (any, error) {
|
||||||
edgeStack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID))
|
edgeStack, err := handler.DataStore.EdgeStack().EdgeStack(portainer.EdgeStackID(edgeStackID))
|
||||||
if handler.DataStore.IsErrObjectNotFound(err) {
|
if handler.DataStore.IsErrObjectNotFound(err) {
|
||||||
return httperror.NotFound("Unable to find an edge stack with the specified identifier inside the database", fmt.Errorf("unable to find the Edge stack from database: %w. Environment name: %s", err, endpoint.Name))
|
return nil, httperror.NotFound("Unable to find an edge stack with the specified identifier inside the database", fmt.Errorf("unable to find the Edge stack from database: %w. Environment name: %s", err, endpoint.Name))
|
||||||
} else if err != nil {
|
|
||||||
return httperror.InternalServerError("Unable to find an edge stack with the specified identifier inside the database", fmt.Errorf("failed to find the Edge stack from database: %w. Environment name: %s", err, endpoint.Name))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return edgeStack, err
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
var httpErr *httperror.HandlerError
|
||||||
|
if errors.As(err, &httpErr) {
|
||||||
|
return httpErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return httperror.InternalServerError("Unable to find an edge stack with the specified identifier inside the database", fmt.Errorf("failed to find Edge stack from the database: %w. Environment name: %s", err, endpoint.Name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: this variable must not be mutated
|
||||||
|
edgeStack := s.(*portainer.EdgeStack)
|
||||||
|
|
||||||
fileName := edgeStack.EntryPoint
|
fileName := edgeStack.EntryPoint
|
||||||
if endpointutils.IsDockerEndpoint(endpoint) {
|
if endpointutils.IsDockerEndpoint(endpoint) {
|
||||||
if fileName == "" {
|
if fileName == "" {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue