Skip to content

Use requested environment on streaming requests#4732

Closed
causton81 wants to merge 2 commits into
flipt-io:v2from
causton81:v2
Closed

Use requested environment on streaming requests#4732
causton81 wants to merge 2 commits into
flipt-io:v2from
causton81:v2

Conversation

@causton81

Copy link
Copy Markdown
Contributor

No description provided.

Chris AUSTON added 2 commits September 11, 2025 13:11
Signed-off-by: Chris AUSTON <[email protected]>
Factored the snapshot env logic out and reused in streaming implementation.

Signed-off-by: Chris AUSTON <[email protected]>
@causton81
causton81 requested a review from a team as a code owner September 11, 2025 17:18
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 11, 2025
@dosubot

dosubot Bot commented Sep 11, 2025

Copy link
Copy Markdown

Related Documentation

Checked 3 published document(s). No updates required.

How did I do? Any feedback?  Join Discord

@codecov

codecov Bot commented Sep 11, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.74%. Comparing base (465e630) to head (0fa079e).
⚠️ Report is 11 commits behind head on v2.

Files with missing lines Patch % Lines
internal/server/evaluation/client/server.go 75.00% 3 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (465e630) and HEAD (0fa079e). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (465e630) HEAD (0fa079e)
integrationtests 10 9
unittests 1 0
Additional details and impacted files
@@             Coverage Diff             @@
##               v2    #4732       +/-   ##
===========================================
- Coverage   62.49%   36.74%   -25.75%     
===========================================
  Files         132      124        -8     
  Lines       15554    14936      -618     
===========================================
- Hits         9720     5488     -4232     
- Misses       5153     8885     +3732     
+ Partials      681      563      -118     
Flag Coverage Δ
integrationtests 36.74% <75.00%> (-0.18%) ⬇️
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@erka

erka commented Sep 11, 2025

Copy link
Copy Markdown
Contributor

Hey @causton81

Could you explain the issue you are trying to resolve and how is it related to streaming?

@markphelps

Copy link
Copy Markdown
Collaborator

I think we need to simply add:

env, err := s.envs.Get(ctx, r.EnvironmentKey)
if err != nil {
	// try to get the environment from the context
	// this is for backwards compatibility with v1
	env = s.envs.GetFromContext(ctx)
}

like we do in

func (s *Server) EvaluationSnapshotNamespace(ctx context.Context, r *rpcevaluation.EvaluationNamespaceSnapshotRequest) (*rpcevaluation.EvaluationNamespaceSnapshot, error) {
start := time.Now()
env, err := s.envs.Get(ctx, r.EnvironmentKey)
if err != nil {
// try to get the environment from the context
// this is for backwards compatibility with v1
env = s.envs.GetFromContext(ctx)
}
var (
environmentKey = env.Key()
namespaceKey = r.Key

seems we missed getting the environment from the path parameters for streaming

@causton81

Copy link
Copy Markdown
Contributor Author

Sorry for the lack of description. I added the error for the case where an environment is specified but not found, because it was confusing to get results and then not see my changes pushed out. It took me a little bit to notice I was getting the default environment instead of what I asked for. I was trying to allow for v1 requests with no environment, but I did not test that.

@erka

erka commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

I think we need to simply add:

env, err := s.envs.Get(ctx, r.EnvironmentKey)
if err != nil {
	// try to get the environment from the context
	// this is for backwards compatibility with v1
	env = s.envs.GetFromContext(ctx)
}

like we do in

func (s *Server) EvaluationSnapshotNamespace(ctx context.Context, r *rpcevaluation.EvaluationNamespaceSnapshotRequest) (*rpcevaluation.EvaluationNamespaceSnapshot, error) {
start := time.Now()
env, err := s.envs.Get(ctx, r.EnvironmentKey)
if err != nil {
// try to get the environment from the context
// this is for backwards compatibility with v1
env = s.envs.GetFromContext(ctx)
}
var (
environmentKey = env.Key()
namespaceKey = r.Key

seems we missed getting the environment from the path parameters for streaming

@markphelps should we use request path parameter only in streaming since it's always required to be there? It also remove any conflicts when path key and context key different if someone messes around with it.

@erka

erka commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

Sorry for the lack of description. I added the error for the case where an environment is specified but not found, because it was confusing to get results and then not see my changes pushed out. It took me a little bit to notice I was getting the default environment instead of what I asked for. I was trying to allow for v1 requests with no environment, but I did not test that.

@causton81 I guess it would be better to change envs.GetFromContext to return error in this case. There are few places where this method is called and it would be nice to have the same API experience. wdyt @markphelps?

@erka erka reopened this Sep 12, 2025
@markphelps

Copy link
Copy Markdown
Collaborator

Sorry for the lack of description. I added the error for the case where an environment is specified but not found, because it was confusing to get results and then not see my changes pushed out. It took me a little bit to notice I was getting the default environment instead of what I asked for. I was trying to allow for v1 requests with no environment, but I did not test that.

@causton81 I guess it would be better to change envs.GetFromContext to return error in this case. There are few places where this method is called and it would be nice to have the same API experience. wdyt @markphelps?

yes I think that makes sense

markphelps pushed a commit that referenced this pull request Sep 13, 2025
Changes GetFromContext to return an error when a specific environment
is requested from context but cannot be found, instead of silently
falling back to the default environment.

This makes the API more explicit and consistent with error handling
patterns. The error is only returned when an environment is explicitly
specified in the context but not found. If no environment is specified,
it still returns the default environment without error.

- Modified GetFromContext signature to return (Environment, error)
- Updated all interface definitions
- Updated all call sites to handle the error appropriately
- Regenerated mocks with new signature
- Updated tests to expect the error return value

Implements suggestion from PR #4732
markphelps pushed a commit that referenced this pull request Sep 13, 2025
Changes GetFromContext to return an error when a specific environment
is requested from context but cannot be found, instead of silently
falling back to the default environment.

This makes the API more explicit and consistent with error handling
patterns. The error is only returned when an environment is explicitly
specified in the context but not found. If no environment is specified,
it still returns the default environment without error.

- Modified GetFromContext signature to return (Environment, error)
- Updated all interface definitions
- Updated all call sites to handle the error appropriately
- Regenerated mocks with new signature
- Updated tests to expect the error return value

Implements suggestion from PR #4732

Signed-off-by: markphelps <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants