From 152c75349ea93b15b2b4b236edfcebcb790786d7 Mon Sep 17 00:00:00 2001 From: wangxinyi7 <121973291+wangxinyi7@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:21:24 -0700 Subject: [PATCH] net 2731 ip config entry OSS version (#16642) * ip config entry * name changing * move to ent * ent version * renaming * change format * renaming * refactor * add default values --- agent/consul/state/config_entry.go | 1 + agent/structs/config_entry.go | 5 ++ agent/structs/config_entry_oss.go | 4 ++ api/config_entry.go | 3 ++ api/config_entry_rate_limit_ip.go | 78 ++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 api/config_entry_rate_limit_ip.go diff --git a/agent/consul/state/config_entry.go b/agent/consul/state/config_entry.go index b37098aaf8..47d81de827 100644 --- a/agent/consul/state/config_entry.go +++ b/agent/consul/state/config_entry.go @@ -553,6 +553,7 @@ func validateProposedConfigEntryInGraph( case structs.InlineCertificate: case structs.HTTPRoute: case structs.TCPRoute: + case structs.RateLimitIPConfig: default: return fmt.Errorf("unhandled kind %q during validation of %q", kindName.Kind, kindName.Name) } diff --git a/agent/structs/config_entry.go b/agent/structs/config_entry.go index f330babf70..5bc7716eda 100644 --- a/agent/structs/config_entry.go +++ b/agent/structs/config_entry.go @@ -40,6 +40,8 @@ const ( InlineCertificate string = "inline-certificate" HTTPRoute string = "http-route" TCPRoute string = "tcp-route" + // TODO: decide if we want to highlight 'ip' keyword in the name of RateLimitIPConfig + RateLimitIPConfig string = "control-plane-request-limit" ProxyConfigGlobal string = "global" MeshConfigMesh string = "mesh" @@ -653,6 +655,9 @@ func (c *ConfigEntryRequest) UnmarshalBinary(data []byte) error { } func MakeConfigEntry(kind, name string) (ConfigEntry, error) { + if configEntry := makeEnterpriseConfigEntry(kind, name); configEntry != nil { + return configEntry, nil + } switch kind { case ServiceDefaults: return &ServiceConfigEntry{Name: name}, nil diff --git a/agent/structs/config_entry_oss.go b/agent/structs/config_entry_oss.go index 4bd3a93fcd..288a2715d0 100644 --- a/agent/structs/config_entry_oss.go +++ b/agent/structs/config_entry_oss.go @@ -44,3 +44,7 @@ func validateExportedServicesName(name string) error { } return nil } + +func makeEnterpriseConfigEntry(kind, name string) ConfigEntry { + return nil +} diff --git a/api/config_entry.go b/api/config_entry.go index 3a5b7bb36b..9d734aa646 100644 --- a/api/config_entry.go +++ b/api/config_entry.go @@ -24,6 +24,7 @@ const ( MeshConfig string = "mesh" ExportedServices string = "exported-services" SamenessGroup string = "sameness-group" + RateLimitIPConfig string = "control-plane-request-limit" ProxyConfigGlobal string = "global" MeshConfigMesh string = "mesh" @@ -366,6 +367,8 @@ func makeConfigEntry(kind, name string) (ConfigEntry, error) { return &InlineCertificateConfigEntry{Kind: kind, Name: name}, nil case HTTPRoute: return &HTTPRouteConfigEntry{Kind: kind, Name: name}, nil + case RateLimitIPConfig: + return &RateLimitIPConfigEntry{Kind: kind, Name: name}, nil default: return nil, fmt.Errorf("invalid config entry kind: %s", kind) } diff --git a/api/config_entry_rate_limit_ip.go b/api/config_entry_rate_limit_ip.go new file mode 100644 index 0000000000..b6df6c3c5f --- /dev/null +++ b/api/config_entry_rate_limit_ip.go @@ -0,0 +1,78 @@ +package api + +type readWriteRatesConfig struct { + ReadRate float64 + WriteRate float64 +} + +type RateLimitIPConfigEntry struct { + // Kind of the config entry. This will be set to structs.RateLimitIPConfig + Kind string + Name string + Mode string // {permissive, enforcing, disabled} + + Meta map[string]string `json:",omitempty"` + // overall limits + ReadRate float64 + WriteRate float64 + + //limits specific to a type of call + ACL *readWriteRatesConfig `json:",omitempty"` + Catalog *readWriteRatesConfig `json:",omitempty"` + ConfigEntry *readWriteRatesConfig `json:",omitempty"` + ConnectCA *readWriteRatesConfig `json:",omitempty"` + Coordinate *readWriteRatesConfig `json:",omitempty"` + DiscoveryChain *readWriteRatesConfig `json:",omitempty"` + Health *readWriteRatesConfig `json:",omitempty"` + Intention *readWriteRatesConfig `json:",omitempty"` + KV *readWriteRatesConfig `json:",omitempty"` + Tenancy *readWriteRatesConfig `json:",omitempty"` + PreparedQuery *readWriteRatesConfig `json:",omitempty"` + Session *readWriteRatesConfig `json:",omitempty"` + Txn *readWriteRatesConfig `json:",omitempty"` + + // Partition is the partition the config entry is associated with. + // Partitioning is a Consul Enterprise feature. + Partition string `json:",omitempty"` + + // Namespace is the namespace the config entry is associated with. + // Namespacing is a Consul Enterprise feature. + Namespace string `json:",omitempty"` + + // CreateIndex is the Raft index this entry was created at. This is a + // read-only field. + CreateIndex uint64 + + // ModifyIndex is used for the Check-And-Set operations and can also be fed + // back into the WaitIndex of the QueryOptions in order to perform blocking + // queries. + ModifyIndex uint64 +} + +func (r *RateLimitIPConfigEntry) GetKind() string { + return RateLimitIPConfig +} +func (r *RateLimitIPConfigEntry) GetName() string { + if r == nil { + return "" + } + return r.Name +} +func (r *RateLimitIPConfigEntry) GetPartition() string { + return r.Partition +} +func (r *RateLimitIPConfigEntry) GetNamespace() string { + return r.Namespace +} +func (r *RateLimitIPConfigEntry) GetMeta() map[string]string { + if r == nil { + return nil + } + return r.Meta +} +func (r *RateLimitIPConfigEntry) GetCreateIndex() uint64 { + return r.CreateIndex +} +func (r *RateLimitIPConfigEntry) GetModifyIndex() uint64 { + return r.ModifyIndex +}