Skip to content

[Framework] simplify cache interfaces#74

Merged
TomerShor merged 5 commits intov3io:developmentfrom
weilerN:nuc-502-simplify-cache-interfaces
Jul 3, 2025
Merged

[Framework] simplify cache interfaces#74
TomerShor merged 5 commits intov3io:developmentfrom
weilerN:nuc-502-simplify-cache-interfaces

Conversation

@weilerN
Copy link
Collaborator

@weilerN weilerN commented Jul 1, 2025

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 []string instead.
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

  • Updated all unit tests and flow tests to reflect and validate the new behavior

Changes Made

  • Updated IngressHostCache to use []string instead of string for all relevant methods (Set, Delete) to reflect support for multiple functions.
  • Updated IngressHostsTree to also operate on []string rather than string for consistency and alignment with the cache layer.
  • Refactored FunctionTarget to simplify its role: only Equal() and ToSliceString() remain, as other behaviors (Add, Delete, Contains, IsSingle) were removed in favor of simplified usage patterns.

@weilerN weilerN requested review from TomerShor and rokatyy July 1, 2025 15:22
@weilerN weilerN force-pushed the nuc-502-simplify-cache-interfaces branch from 7c5a4b4 to 34a4311 Compare July 1, 2025 15:24
@weilerN weilerN marked this pull request as ready for review July 1, 2025 15:26
@weilerN weilerN marked this pull request as draft July 2, 2025 06:56
Copy link
Collaborator

@rokatyy rokatyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure regarding the proposed changes. Let's discuss it further offline

Comment on lines 130 to 138
// 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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@weilerN weilerN force-pushed the nuc-502-simplify-cache-interfaces branch from 9837dcb to 247f643 Compare July 2, 2025 11:54
@weilerN weilerN marked this pull request as ready for review July 2, 2025 12:10
@weilerN weilerN requested a review from rokatyy July 2, 2025 12:10
}

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")
Copy link
Collaborator

@rokatyy rokatyy Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@TomerShor TomerShor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some nitpicks on comments mostly :)

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

st.pathTrie.Delete(path)
}
return nil
requestTarget, err := st.NewTarget(targets)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
requestTarget, err := st.NewTarget(targets)
targetToDelete, err := st.NewTarget(targets)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Set a targets name in an empty cache
// Set targets in an empty cache

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@weilerN weilerN requested review from TomerShor and rokatyy July 2, 2025 13:38
Copy link
Collaborator

@rokatyy rokatyy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TomerShor TomerShor merged commit 5b0d9bc into v3io:development Jul 3, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants