-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Optimise reloads by only reloading the API if the file has changed. #5456
base: master
Are you sure you want to change the base?
Conversation
… 1d0b0c9c9d - High Tea: Gitea with Traefik It already used Checksup, but still was serializing API spec objects to Go objects, and running MakeSpec (which creates regexes and etc) on every reload.
A JIRA Issue ID is missing from your branch name, PR title and PR description! 🦄 Your branch: churn/optimise-reloads Your PR title: Optimise reloads by only reloading the API if the file has changed. · 1d0b0c9c9d - High Tea: Gitea with Traefik Your PR description: It already used Checksup, but still was serializing API spec objects to Go objects, and running MakeSpec (which creates regexes and etc) on every reload. DescriptionRelated IssueMotivation and ContextHow This Has Been TestedScreenshots (if appropriate)Types of changes
Checklist
If this is your first time contributing to this repository - welcome! Please refer to jira-lint to get started. Without the JIRA Issue ID in your branch name you would lose out on automatic updates to JIRA via SCM; some GitHub status checks might fail. Valid sample branch names:‣ feature/shiny-new-feature--mojo-10' |
PR Analysis
PR Feedback
How to use
|
💥 CI tests failed 🙈git-statediff --git a/gateway/api_definition.go b/gateway/api_definition.go
index b759b8b..3a8ceb9 100644
--- a/gateway/api_definition.go
+++ b/gateway/api_definition.go
@@ -20,9 +20,10 @@ import (
"text/template"
"time"
- graphqlinternal "github.com/TykTechnologies/tyk/internal/graphql"
"github.com/buger/jsonparser"
+ graphqlinternal "github.com/TykTechnologies/tyk/internal/graphql"
+
"github.com/getkin/kin-openapi/routers"
"github.com/getkin/kin-openapi/routers/gorillamux" Please look at the run or in the Checks tab. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
API tests result: success ✅ |
Now same as APIs it will parse new policy only if checksum is changed. Also policies was not using pointers in the code, so it was allocating unnecessary resources.
API Changes --- prev.txt 2023-08-25 15:35:28.351651451 +0000
+++ current.txt 2023-08-25 15:35:24.227682148 +0000
@@ -6448,8 +6448,8 @@
will decode request body as json to map[string]string and adds the key/value
pairs in r.Form.
-func LoadPoliciesFromDir(dir string) map[string]user.Policy
-func LoadPoliciesFromFile(filePath string) map[string]user.Policy
+func LoadPoliciesFromDir(dir string) map[string]*user.Policy
+func LoadPoliciesFromFile(filePath string) map[string]*user.Policy
func LoopingUrl(host string) string
func NewPythonDispatcher(conf config.Config) (dispatcher coprocess.Dispatcher, err error)
NewPythonDispatcher wraps all the actions needed for this CP.
@@ -6957,11 +6957,13 @@
func (d *DBAccessDefinition) ToRegularAD() user.AccessDefinition
type DBPolicy struct {
- user.Policy
+ *user.Policy
AccessRights map[string]DBAccessDefinition `bson:"access_rights" json:"access_rights"`
+
+ // Has unexported fields.
}
-func (d *DBPolicy) ToRegularPolicy() user.Policy
+func (d *DBPolicy) ToRegularPolicy() *user.Policy
type DashboardServiceSender interface {
Init() error
@@ -7301,13 +7303,13 @@
func (gw *Gateway) LoadDefinitionsFromRPCBackup() ([]*APISpec, error)
-func (gw *Gateway) LoadPoliciesFromDashboard(endpoint, secret string, allowExplicit bool) map[string]user.Policy
+func (gw *Gateway) LoadPoliciesFromDashboard(endpoint, secret string, allowExplicit bool) map[string]*user.Policy
LoadPoliciesFromDashboard will connect and download Policies from a Tyk
Dashboard instance.
-func (gw *Gateway) LoadPoliciesFromRPC(store RPCDataLoader, orgId string, allowExplicit bool) (map[string]user.Policy, error)
+func (gw *Gateway) LoadPoliciesFromRPC(store RPCDataLoader, orgId string, allowExplicit bool) (map[string]*user.Policy, error)
-func (gw *Gateway) LoadPoliciesFromRPCBackup() (map[string]user.Policy, error)
+func (gw *Gateway) LoadPoliciesFromRPCBackup() (map[string]*user.Policy, error)
func (gw *Gateway) LoadSampleAPI(def string) (spec *APISpec)
@@ -9040,7 +9042,7 @@
func (s *Test) GetApiById(apiId string) *APISpec
-func (s *Test) GetPolicyById(policyId string) (user.Policy, bool)
+func (s *Test) GetPolicyById(policyId string) (*user.Policy, bool)
func (s *Test) RegisterBundle(name string, files map[string]string) string
@@ -9583,6 +9585,12 @@
TYPES
+type FlatMap map[string]string
+ FlatMap is alias of map[string]string
+
+func Flatten(data map[string]interface{}) (flatmap FlatMap, err error)
+ Flatten transform complex map to flatten map
+
type RawFormatter struct{}
func (f *RawFormatter) Format(entry *logrus.Entry) ([]byte, error)
@@ -10986,7 +10994,7 @@
func (s SessionState) Clone() SessionState
Clone returns a fresh copy of s
-func (s *SessionState) CustomPolicies() (map[string]Policy, error)
+func (s *SessionState) CustomPolicies() (map[string]*Policy, error)
func (s *SessionState) GetQuotaLimitByAPIID(apiID string) (int64, int64, int64, int64)
GetQuotaLimitByAPIID return quota max, quota remaining, quota renewal rate
@@ -11018,7 +11026,7 @@
For backwards compatibility reasons, this falls back to ApplyPolicyID if
ApplyPolicies is empty.
-func (s *SessionState) SetCustomPolicies(list []Policy)
+func (s *SessionState) SetCustomPolicies(list []*Policy)
func (s *SessionState) SetKeyHash(hash string)
|
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result: success ✅ |
💥 CI tests failed 🙈git-statediff --git a/gateway/api_definition.go b/gateway/api_definition.go
index b759b8b..3a8ceb9 100644
--- a/gateway/api_definition.go
+++ b/gateway/api_definition.go
@@ -20,9 +20,10 @@ import (
"text/template"
"time"
- graphqlinternal "github.com/TykTechnologies/tyk/internal/graphql"
"github.com/buger/jsonparser"
+ graphqlinternal "github.com/TykTechnologies/tyk/internal/graphql"
+
"github.com/getkin/kin-openapi/routers"
"github.com/getkin/kin-openapi/routers/gorillamux"
diff --git a/gateway/policy.go b/gateway/policy.go
index d635c7a..831bbd5 100644
--- a/gateway/policy.go
+++ b/gateway/policy.go
@@ -10,9 +10,10 @@ import (
"os"
"path/filepath"
- "github.com/TykTechnologies/graphql-go-tools/pkg/graphql"
"github.com/buger/jsonparser"
+ "github.com/TykTechnologies/graphql-go-tools/pkg/graphql"
+
"github.com/TykTechnologies/tyk/rpc"
"github.com/sirupsen/logrus" Please look at the run or in the Checks tab. |
API tests result: success ✅ |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result: success ✅ |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result: success ✅ |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result: success ✅ |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result: success ✅ |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result: success ✅ |
💥 CI tests failed 🙈git-stateall ok Please look at the run or in the Checks tab. |
API tests result: success ✅ |
It already used Checksup, but still was serializing API spec objects to Go objects, and running MakeSpec (which creates regexes and etc) on every reload.
Description
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist