1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

feat(performance): performance optimizations EE-6042 (#10520)

This commit is contained in:
andres-portainer 2023-10-24 13:55:11 -03:00 committed by GitHub
parent e4e66dac9c
commit ae1726cece
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 311 additions and 382 deletions

View file

@ -2,7 +2,6 @@ package client
import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
@ -14,6 +13,7 @@ import (
portainer "github.com/portainer/portainer/api"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
var errInvalidResponseStatus = errors.New("invalid response status (expecting 200)")

View file

@ -1,7 +1,6 @@
package customtemplates
import (
"encoding/json"
"errors"
"fmt"
"net/http"
@ -21,6 +20,7 @@ import (
"github.com/asaskevich/govalidator"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
func (handler *Handler) customTemplateCreate(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {

View file

@ -2,7 +2,6 @@ package customtemplates
import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/fs"
@ -20,6 +19,8 @@ import (
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/internal/authorization"
"github.com/portainer/portainer/api/jwt"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)

View file

@ -2,13 +2,14 @@ package edgestacks
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
portainer "github.com/portainer/portainer/api"
"github.com/segmentio/encoding/json"
)
// Create

View file

@ -1,13 +1,14 @@
package edgestacks
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
portainer "github.com/portainer/portainer/api"
"github.com/segmentio/encoding/json"
)
// Delete

View file

@ -2,13 +2,14 @@ package edgestacks
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"testing"
portainer "github.com/portainer/portainer/api"
"github.com/segmentio/encoding/json"
)
// Update Status

View file

@ -2,7 +2,6 @@ package edgestacks
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
@ -10,6 +9,8 @@ import (
"testing"
portainer "github.com/portainer/portainer/api"
"github.com/segmentio/encoding/json"
)
// Update

View file

@ -1,13 +1,14 @@
package edgetemplates
import (
"encoding/json"
"net/http"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/http/client"
httperror "github.com/portainer/portainer/pkg/libhttp/error"
"github.com/portainer/portainer/pkg/libhttp/response"
"github.com/segmentio/encoding/json"
)
type templateFileFormat struct {

View file

@ -2,7 +2,6 @@ package endpointedge
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
@ -17,6 +16,7 @@ import (
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/jwt"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)

View file

@ -1,7 +1,6 @@
package endpoints
import (
"encoding/json"
"errors"
"fmt"
"io"
@ -15,6 +14,8 @@ import (
httperror "github.com/portainer/portainer/pkg/libhttp/error"
"github.com/portainer/portainer/pkg/libhttp/request"
"github.com/portainer/portainer/pkg/libhttp/response"
"github.com/segmentio/encoding/json"
)
type dockerhubStatusResponse struct {

View file

@ -1,7 +1,6 @@
package endpoints
import (
"encoding/json"
"fmt"
"io"
"net/http"
@ -13,6 +12,8 @@ import (
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/internal/snapshot"
"github.com/portainer/portainer/api/internal/testhelpers"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)
@ -27,13 +28,13 @@ func Test_EndpointList_AgentVersion(t *testing.T) {
GroupID: 1,
Type: portainer.AgentOnDockerEnvironment,
Agent: struct {
Version string "example:\"1.0.0\""
Version string `json:"Version,omitempty" example:"1.0.0"`
}{
Version: "1.0.0",
},
}
version2Endpoint := portainer.Endpoint{ID: 2, GroupID: 1, Type: portainer.AgentOnDockerEnvironment, Agent: struct {
Version string "example:\"1.0.0\""
Version string `json:"Version,omitempty" example:"1.0.0"`
}{Version: "2.0.0"}}
noVersionEndpoint := portainer.Endpoint{ID: 3, Type: portainer.AgentOnDockerEnvironment, GroupID: 1}
notAgentEnvironments := portainer.Endpoint{ID: 4, Type: portainer.DockerEnvironment, GroupID: 1}

View file

@ -22,12 +22,12 @@ func Test_Filter_AgentVersion(t *testing.T) {
version1Endpoint := portainer.Endpoint{ID: 1, GroupID: 1,
Type: portainer.AgentOnDockerEnvironment,
Agent: struct {
Version string "example:\"1.0.0\""
Version string `json:"Version,omitempty" example:"1.0.0"`
}{Version: "1.0.0"}}
version2Endpoint := portainer.Endpoint{ID: 2, GroupID: 1,
Type: portainer.AgentOnDockerEnvironment,
Agent: struct {
Version string "example:\"1.0.0\""
Version string `json:"Version,omitempty" example:"1.0.0"`
}{Version: "2.0.0"}}
noVersionEndpoint := portainer.Endpoint{ID: 3, GroupID: 1,
Type: portainer.AgentOnDockerEnvironment,

View file

@ -2,15 +2,13 @@ package helm
import (
"bytes"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/portainer/portainer/api/datastore"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/datastore"
"github.com/portainer/portainer/api/exec/exectest"
"github.com/portainer/portainer/api/http/security"
helper "github.com/portainer/portainer/api/internal/testhelpers"
@ -19,6 +17,8 @@ import (
"github.com/portainer/portainer/pkg/libhelm/binary/test"
"github.com/portainer/portainer/pkg/libhelm/options"
"github.com/portainer/portainer/pkg/libhelm/release"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)

View file

@ -1,7 +1,6 @@
package helm
import (
"encoding/json"
"io"
"net/http"
"net/http/httptest"
@ -11,14 +10,15 @@ import (
"github.com/portainer/portainer/api/datastore"
"github.com/portainer/portainer/api/exec/exectest"
"github.com/portainer/portainer/api/http/security"
helper "github.com/portainer/portainer/api/internal/testhelpers"
"github.com/portainer/portainer/api/jwt"
"github.com/portainer/portainer/api/kubernetes"
"github.com/portainer/portainer/pkg/libhelm/binary/test"
"github.com/portainer/portainer/pkg/libhelm/options"
"github.com/portainer/portainer/pkg/libhelm/release"
"github.com/stretchr/testify/assert"
helper "github.com/portainer/portainer/api/internal/testhelpers"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)
func Test_helmList(t *testing.T) {

View file

@ -2,7 +2,6 @@ package openamt
import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
@ -20,6 +19,7 @@ import (
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
type HostInfo struct {

View file

@ -1,7 +1,6 @@
package motd
import (
"encoding/json"
"net/http"
"strings"
@ -9,6 +8,8 @@ import (
"github.com/portainer/portainer/api/http/client"
"github.com/portainer/portainer/pkg/libcrypto"
"github.com/portainer/portainer/pkg/libhttp/response"
"github.com/segmentio/encoding/json"
)
type motdResponse struct {

View file

@ -1,7 +1,6 @@
package system
import (
"encoding/json"
"net/http"
portainer "github.com/portainer/portainer/api"
@ -11,6 +10,7 @@ import (
"github.com/coreos/go-semver/semver"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
type versionResponse struct {

View file

@ -1,7 +1,6 @@
package system
import (
"encoding/json"
"fmt"
"io"
"net/http"
@ -15,6 +14,8 @@ import (
"github.com/portainer/portainer/api/demo"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/jwt"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)

View file

@ -1,7 +1,6 @@
package teams
import (
"encoding/json"
"fmt"
"io"
"net/http"
@ -15,6 +14,8 @@ import (
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/internal/authorization"
"github.com/portainer/portainer/api/jwt"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)

View file

@ -1,7 +1,6 @@
package templates
import (
"encoding/json"
"errors"
"net/http"
@ -12,6 +11,7 @@ import (
"github.com/asaskevich/govalidator"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
type filePayload struct {

View file

@ -2,7 +2,6 @@ package users
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
@ -15,6 +14,8 @@ import (
"github.com/portainer/portainer/api/datastore"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/jwt"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)
@ -105,7 +106,7 @@ func Test_userCreateAccessToken(t *testing.T) {
body, err := io.ReadAll(rr.Body)
is.NoError(err, "ReadAll should not return error")
is.Equal("{\"message\":\"Auth not supported\",\"details\":\"JWT Authentication required\"}\n", string(body))
is.Equal(`{"message":"Auth not supported","details":"JWT Authentication required"}`, string(body))
})
}

View file

@ -1,7 +1,6 @@
package users
import (
"encoding/json"
"fmt"
"io"
"net/http"
@ -14,6 +13,8 @@ import (
"github.com/portainer/portainer/api/datastore"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/jwt"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)

View file

@ -1,7 +1,6 @@
package users
import (
"encoding/json"
"fmt"
"io"
"net/http"
@ -17,6 +16,8 @@ import (
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/internal/authorization"
"github.com/portainer/portainer/api/jwt"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/assert"
)

View file

@ -2,20 +2,20 @@ package websocket
import (
"bytes"
"encoding/json"
"github.com/portainer/portainer/api/http/security"
"github.com/rs/zerolog/log"
"net"
"net/http"
"net/http/httputil"
"time"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/http/security"
httperror "github.com/portainer/portainer/pkg/libhttp/error"
"github.com/portainer/portainer/pkg/libhttp/request"
"github.com/asaskevich/govalidator"
"github.com/gorilla/websocket"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
type execStartOperationPayload struct {

View file

@ -13,9 +13,7 @@ import (
"github.com/gorilla/mux"
)
const (
contextEndpoint = "endpoint"
)
const contextEndpoint = "endpoint"
func WithEndpoint(endpointService dataservices.EndpointService, endpointIDParam string) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {

View file

@ -2,7 +2,6 @@ package docker
import (
"bytes"
"encoding/json"
"errors"
"io"
"mime"
@ -11,6 +10,7 @@ import (
"github.com/portainer/portainer/api/archive"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
const OneMegabyte = 1024768

View file

@ -3,22 +3,21 @@ package docker
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"strings"
"github.com/docker/docker/client"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/http/proxy/factory/utils"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/internal/authorization"
"github.com/docker/docker/client"
"github.com/segmentio/encoding/json"
)
const (
containerObjectIdentifier = "Id"
)
const containerObjectIdentifier = "Id"
func getInheritedResourceControlFromContainerLabels(dockerClient *client.Client, endpointID portainer.EndpointID, containerID string, resourceControls []portainer.ResourceControl) (*portainer.ResourceControl, error) {
container, err := dockerClient.ContainerInspect(context.Background(), containerID)

View file

@ -3,22 +3,20 @@ package docker
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"net/http"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/http/proxy/factory/utils"
"github.com/portainer/portainer/api/internal/authorization"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/segmentio/encoding/json"
)
const (
serviceObjectIdentifier = "ID"
)
const serviceObjectIdentifier = "ID"
func getInheritedResourceControlFromServiceLabels(dockerClient *client.Client, endpointID portainer.EndpointID, serviceID string, resourceControls []portainer.ResourceControl) (*portainer.ResourceControl, error) {
service, _, err := dockerClient.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{})

View file

@ -3,7 +3,6 @@ package docker
import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
@ -15,12 +14,13 @@ import (
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/dataservices"
dockerclient "github.com/portainer/portainer/api/docker/client"
"github.com/portainer/portainer/api/http/proxy/factory/utils"
"github.com/portainer/portainer/api/http/security"
"github.com/portainer/portainer/api/internal/authorization"
dockerclient "github.com/portainer/portainer/api/docker/client"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
var apiVersionRe = regexp.MustCompile(`(/v[0-9]\.[0-9]*)?`)

View file

@ -2,7 +2,6 @@ package kubernetes
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
@ -18,6 +17,7 @@ import (
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/segmentio/encoding/json"
)
type baseTransport struct {

View file

@ -2,12 +2,12 @@ package utils
import (
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"io"
"mime"
"github.com/segmentio/encoding/json"
"gopkg.in/yaml.v3"
)