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

feat: support etag header for client-side eval #3240

Closed
wants to merge 3 commits into from
Closed

feat: support etag header for client-side eval #3240

wants to merge 3 commits into from

Conversation

markphelps
Copy link
Collaborator

Re: flipt-io/flipt-client-sdks#294

Support etag/if-none-match headers for client-side eval endpoint

~ » curl -v  http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080
> GET /internal/v1/evaluation/snapshot/namespace/default HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.6.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Length: 1401
< Content-Type: application/json
< Etag: 7cfafac21953b341569a2a676205e0c0e5ff7e00
< Grpc-Metadata-Content-Type: application/grpc
< X-Content-Type-Options: nosniff

~ » curl -v  -H "If-None-Match: 7cfafac21953b341569a2a676205e0c0e5ff7e00" http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080
> GET /internal/v1/evaluation/snapshot/namespace/default HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.6.0
> Accept: */*
> If-None-Match: 7cfafac21953b341569a2a676205e0c0e5ff7e00
> 
< HTTP/1.1 304 Not Modified

@markphelps markphelps requested a review from a team as a code owner July 5, 2024 13:16
@erka
Copy link
Collaborator

erka commented Jul 5, 2024

@markphelps your code looks great but there is a problem. If you have the namespace with some amount of flags and segments http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default will produce different etag. I believe the logic uses map somewhere and it produces the different order of elements in the json.

Here is the sample

> curl -v http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 7011
< Content-Type: application/json
< Etag: 4bbaa020a72c5bd21b224bcdd11c5bf4c7c0cda3

> curl -v http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 7011
< Content-Type: application/json
< Etag: 92e8e67b990930eca494f3feb4536c68725dc2bf

@markphelps
Copy link
Collaborator Author

@markphelps your code looks great but there is a problem. If you have the namespace with some amount of flags and segments http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default will produce different etag. I believe the logic uses map somewhere and it produce the different order of elements in the json.

Here is the sample

> curl -v http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 7011
< Content-Type: application/json
< Etag: 4bbaa020a72c5bd21b224bcdd11c5bf4c7c0cda3

> curl -v http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 7011
< Content-Type: application/json
< Etag: 92e8e67b990930eca494f3feb4536c68725dc2bf

gah you are right. good find @erka . back to the drawing board it seems

@markphelps
Copy link
Collaborator Author

markphelps commented Jul 5, 2024

@markphelps your code looks great but there is a problem. If you have the namespace with some amount of flags and segments http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default will produce different etag. I believe the logic uses map somewhere and it produce the different order of elements in the json.
Here is the sample

> curl -v http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 7011
< Content-Type: application/json
< Etag: 4bbaa020a72c5bd21b224bcdd11c5bf4c7c0cda3

> curl -v http://localhost:8080/internal/v1/evaluation/snapshot/namespace/default 
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 7011
< Content-Type: application/json
< Etag: 92e8e67b990930eca494f3feb4536c68725dc2bf

gah you are right. good find @erka . back to the drawing board it seems

Its likely related to us using protojson to marshal the output which isnt deterministic: https://protobuf.dev/reference/go/faq/#unstable-json

we need to think of otherways we can produce a stable etag value

@markphelps
Copy link
Collaborator Author

closing for another approach

@markphelps markphelps closed this Jul 7, 2024
@markphelps markphelps mentioned this pull request Jul 7, 2024
7 tasks
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.

None yet

2 participants