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

feature: filter fifoWithBody #2676

Closed
wants to merge 2 commits into from
Closed

feature: filter fifoWithBody #2676

wants to merge 2 commits into from

Conversation

szuecs
Copy link
Member

@szuecs szuecs commented Oct 13, 2023

feature: filter fifoWithBody that works similar to fifo(), but release deferred until body streaming to client was finished

@szuecs
Copy link
Member Author

szuecs commented Oct 13, 2023

@AlexanderYastrebov maybe better than #2675 wdyt?

Comment on lines +171 to +172
case fifoWithBody:
ctx.StateBag()[filters.FifoWithBody] = g
Copy link
Member

@AlexanderYastrebov AlexanderYastrebov Oct 13, 2023

Choose a reason for hiding this comment

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

Its not clear how multiple fifoWithBody would chain and how they would interplay with regular fifo.
I think you'd need to have the same logic stored under different keys and then run chain of hooks in two places in proxy depending on the key at proxy.do and proxy.ServeHTTP:

...
func (f *fifoFilter) createResponse(ctx filters.FilterContext, typ string) {
        pending, ok := ctx.StateBag()[typ].([]func())
        if !ok {
	        return
        }
        last := len(pending) - 1
        if last < 0 {
	        return
        }
        pending[last]()
        ctx.StateBag()[fifoKey] = pending[:last]
}

...
// existing in proxy.do
pendingFIFO, _ := stateBag[scheduler.FIFOKey].([]func())
for _, done := range pendingFIFO {
	done()
}
...
// in proxy.ServeHTTP
pendingFIFO, _ := stateBag[scheduler.FIFOWithBodyKey].([]func())
for _, done := range pendingFIFO {
	done()
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's a good point. I also thought about that I need to do something like that.
What do you like more to support the copystream part? this one or the other?

Copy link
Member

@AlexanderYastrebov AlexanderYastrebov Oct 16, 2023

Choose a reason for hiding this comment

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

I think we can remove existing pendingFIFO cleanup from proxy.go see #2680

Comment on lines +20 to +23
const (
fifo fifoType = iota + 1
fifoWithBody
)
Copy link
Member

Choose a reason for hiding this comment

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

You can use filter name as spec.typ and have withBody bool in filter similar to

f := &histFilter{
response: s.typ == filters.HistogramResponseLatencyName,

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the enum style better than string.

AlexanderYastrebov and others added 2 commits October 16, 2023 20:30
Make lifo, lifoGroup and fifo filters backed error aware and remove
cleanup from the proxy.

Follow up on #1054, #1086 and #2239
Updates #1238

Signed-off-by: Alexander Yastrebov <[email protected]>
…e defered until body streaming to client was finished

Signed-off-by: Sandor Szücs <[email protected]>
@szuecs szuecs force-pushed the feature/fifo-with-body branch from 451e0df to 1eb2e0f Compare October 16, 2023 18:39
@szuecs
Copy link
Member Author

szuecs commented Oct 16, 2023

close to create a PR to cw2023freeze

@szuecs szuecs closed this Oct 16, 2023
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.

2 participants