[Framework] simplify cache interfaces#74
Conversation
7c5a4b4 to
34a4311
Compare
rokatyy
left a comment
There was a problem hiding this comment.
I'm not really sure regarding the proposed changes. Let's discuss it further offline
| // NewTarget returns a Target based on the length of the input slice | ||
| func (st *SafeTrie) NewTarget(inputs []string) (Target, error) { | ||
| switch len(inputs) { | ||
| case 1: | ||
| return Targets{inputs[0]}, nil | ||
| case 2: | ||
| return Targets{inputs[0], inputs[1]}, nil | ||
| default: | ||
| return nil, errors.New("unexpected input length") |
There was a problem hiding this comment.
Why not having singleTarget and canary? How the check will look like from resolving point of view? Every time we check single function (which is the most often case), we need to check both values for no reason, this is less friendly for long-time support of the code than previous solution that maps us to real entities, not some random slice of 2 that can be of len 1 or 2.
There was a problem hiding this comment.
As discussed F2F, we decided to keep the SingleTarget.
Changes were committed here - CR comment - move to more generic - rename functionTarget to targets …
…and change naming singleTarget and CanaryTarget to just Targets
9837dcb to
247f643
Compare
pkg/ingresscache/ingresscache.go
Outdated
| } | ||
|
|
||
| return errors.Wrap(err, "failed to set function name in the ingress host tree") | ||
| return errors.Wrap(err, "failed to set targets name in the ingress host tree") |
There was a problem hiding this comment.
| return errors.Wrap(err, "failed to set targets name in the ingress host tree") | |
| return errors.Wrap(err, "failed to set targets in the ingress host tree") |
same in all places below
There was a problem hiding this comment.
TomerShor
left a comment
There was a problem hiding this comment.
some nitpicks on comments mostly :)
pkg/ingresscache/types.go
Outdated
| type IngressHostCache interface { | ||
| // Set adds a new item to the cache for the given host, path and function name. Will overwrite existing values if any | ||
| Set(host string, path string, function string) error | ||
| // Set adds a new item to the cache for the given host, path and targets name. Will overwrite existing values if any |
There was a problem hiding this comment.
| // Set adds a new item to the cache for the given host, path and targets name. Will overwrite existing values if any | |
| // Set adds a new item to the cache for the given host, path and targets. Will overwrite existing values if any |
There was a problem hiding this comment.
pkg/ingresscache/types.go
Outdated
| type IngressHostsTree interface { | ||
| // Set sets a function for a given path. Will overwrite existing values if the path already exists | ||
| Set(path string, function string) error | ||
| // Set sets a targets for a given path. Will overwrite existing values if the path already exists |
There was a problem hiding this comment.
| // Set sets a targets for a given path. Will overwrite existing values if the path already exists | |
| // Set sets the targets for a given path. Will overwrite existing values if the path already exists |
There was a problem hiding this comment.
pkg/ingresscache/types.go
Outdated
|
|
||
| // Delete removes the function from the given path and deletes the deepest suffix used only by that function; does nothing if the path or function doesn't exist. | ||
| Delete(path string, function string) error | ||
| // Delete removes the targets from the given path and deletes the deepest suffix used only by that targets; does nothing if the path or targets doesn't exist. |
There was a problem hiding this comment.
| // Delete removes the targets from the given path and deletes the deepest suffix used only by that targets; does nothing if the path or targets doesn't exist. | |
| // Delete removes the targets from the given path and deletes the deepest suffix used only by these targets; does nothing if the path or targets don't exist. |
There was a problem hiding this comment.
pkg/ingresscache/types.go
Outdated
|
|
||
| // Get retrieves the best matching function names for a given path based on longest prefix match | ||
| Get(path string) (FunctionTarget, error) | ||
| // Get retrieves the best matching target names for a given path based on longest prefix match |
There was a problem hiding this comment.
| // Get retrieves the best matching target names for a given path based on longest prefix match | |
| // Get retrieves the best matching targets for a given path based on longest prefix match |
There was a problem hiding this comment.
pkg/ingresscache/safetrie.go
Outdated
|
|
||
| // Set adds a function for a given path. If the path does not exist, it creates it | ||
| func (st *SafeTrie) Set(path string, function string) error { | ||
| // Set adds a targets for a given path. If the path does not exist, it creates it |
There was a problem hiding this comment.
| // Set adds a targets for a given path. If the path does not exist, it creates it | |
| // Set adds targets for a given path. If the path does not exist, it creates it |
There was a problem hiding this comment.
pkg/ingresscache/safetrie.go
Outdated
|
|
||
| // Delete removes a function from a path and cleans up the longest suffix of the path only used by that function | ||
| func (st *SafeTrie) Delete(path string, function string) error { | ||
| // Delete removes a targets from a path and cleans up the longest suffix of the path only used by that targets |
There was a problem hiding this comment.
| // Delete removes a targets from a path and cleans up the longest suffix of the path only used by that targets | |
| // Delete removes the targets from a path and cleans up the longest suffix of the path only used by these targets |
There was a problem hiding this comment.
pkg/ingresscache/safetrie.go
Outdated
| st.pathTrie.Delete(path) | ||
| } | ||
| return nil | ||
| requestTarget, err := st.NewTarget(targets) |
There was a problem hiding this comment.
| requestTarget, err := st.NewTarget(targets) | |
| targetToDelete, err := st.NewTarget(targets) |
There was a problem hiding this comment.
|
|
||
| func (suite *IngressCacheTestSuite) TestAllThreeMainFunctionalitiesWithTheSameHostAndPath() { | ||
| // This test verifies the flow of setting a function name in an empty IngressCache, then getting it, and finally deleting it. | ||
| // This test verifies the flow of setting a targets name in an empty IngressCache, then getting it, and finally deleting it. |
There was a problem hiding this comment.
| // This test verifies the flow of setting a targets name in an empty IngressCache, then getting it, and finally deleting it. | |
| // This test verifies the flow of setting targets in an empty IngressCache, then getting it, and finally deleting it. |
There was a problem hiding this comment.
| // Set a function name in an empty cache | ||
| err = testIngressCache.Set("example.com", "/test/path", "test-function-name-1") | ||
| suite.Require().NoError(err, "Expected no error when setting a function name in an empty cache") | ||
| // Set a targets name in an empty cache |
There was a problem hiding this comment.
| // Set a targets name in an empty cache | |
| // Set targets in an empty cache |
There was a problem hiding this comment.
Motivation
Enable the watching operator to use the cache through its interface without needing awareness of the underlying implementation.
Root Cause
The original interfaces were designed to support a single string, which turned out to be insufficient.
This refactoring updates them to use
[]stringinstead.Using string slices allows for a simpler and more accurate implementation of the cache, better aligned with the behavior defined in the HLD.
Description
For more details, see Jira: https://iguazio.atlassian.net/browse/NUC-502
Affected Areas
This PR is a prerequisite for NUC-498
Testing
Changes Made
IngressHostCacheto use[]stringinstead ofstringfor all relevant methods (Set, Delete) to reflect support for multiple functions.IngressHostsTreeto also operate on[]stringrather thanstringfor consistency and alignment with the cache layer.FunctionTargetto simplify its role: onlyEqual()andToSliceString()remain, as other behaviors (Add, Delete, Contains, IsSingle) were removed in favor of simplified usage patterns.