Skip to content
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

New cache interface proposal #718

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

valerian-roche
Copy link
Contributor

This draft PR is proposing a new interface for the Cache package
The main goals are:

  • abstract away the request. This makes the interface more generic while also avoiding having conflicting resource lists
  • pass a subscription state to get the current stateful state of the stream for the given type. This is needed also for sotw for some behaviors
  • make private all internals of the Cache to limit the API scope
  • make both interfaces more compatible to limit the amount of duplication between sotw and delta. From a Cache perspective they should behave the same in the end. It's not fully there yet but closing on it

This PR is not yet finalized (e.g. it doesn't compile currently), but it shows a first proposal. It brings a lot of change and the final implementation would likely be broken in pieces

…e uniform between sotw and delta

Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>
Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>
Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>
…lso compatible with sotw

Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>
Signed-off-by: Valerian Roche <valerian.roche@datadoghq.com>
// The versions are:
// - delta protocol: version of the specific resource set in the response
// - sotw protocol: version of the global response when the resource was last ACKed
GetKnownResources() map[string]string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal is to remove the current global version behavior in the future. It would allow to handle both protocols in a more uniform manner, as well as supporting partial sotw responses for non-wildcard requests


type FetchRequest interface {
Request
GetResourceNames() []string
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fetch has no subscription notion

// Get the context provided during response creation.
GetContext() context.Context

// Get the Constructed DiscoveryResponse
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Imo those should not be in Cache, as those depend on the server and the cache does not really need to know what requests/responses are passed
For now I kept them there to limit the impact

)

type resourceWithNameAndVersion interface {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea is to avoid constraints on the resources that are actually not needed. Any added resource version in the cache is already set with a name
For the version it avoids having to rehash the resource. In the future we could also avoid the double serialization we currently do, which is quite expensive in CPU

var _ DeltaResponse = &rawDeltaResponse{}

// RawDeltaResponse is a pre-serialized xDS response that utilizes the delta discovery request/response objects.
type rawDeltaResponse struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made private. This allows us to evolve Cache implementations with less impact on users

// * detect the version change, and return the resource (as an update)
// * detect the resource deletion, and set it as removed in the response
streamState.GetResourceVersions()[resource] = ""
streamState.GetKnownResources()[resource] = "unsubscribed"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for sure hacky (though not much more than before), while allowing the use of "" for the standard case of "non-existent" resource

@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the stale label Jul 10, 2023
@github-actions
Copy link

This pull request has been automatically closed because it has not had activity in the last 37 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot closed this Jul 17, 2023
@alecholmez alecholmez self-requested a review July 17, 2023 14:08
@alecholmez alecholmez self-assigned this Jul 17, 2023
@alecholmez alecholmez reopened this Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants