-
Notifications
You must be signed in to change notification settings - Fork 0
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
Websocket logs endpoint for polling envoy fleet container logs #80
Merged
kylehodgetts
merged 19 commits into
main
from
kylehodgetts/feature/stream-logs-websocket
Nov 25, 2022
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8bef725
initial websocket commit
6029e5e
initial websocket commit
2dd3181
update ci pipelines to build websocket as well as API server
1950f76
move api server and create websocket dockerfiles in build directory
9a135e0
add websocket service to docker-compose
b323731
add websocket service to test kubernetes manifest file
81b6538
check for errors when adding to k8s runtime scheme
7494b1a
Add default tail parameter in case one is not defined
92e1c2c
pass in tail log line count param for specifying how many log lines t…
dc3f3d3
add port flag to specify port to listen on
d6e061e
add gorilla websocket dependency
7c0e4b2
add healthz endpoint
c5c42d5
update build target
995e9fb
add correct endpoint to api spec
871185c
correctly tag docker images
654fb03
accept write,pong wait seconds and max message size as flag params
1fc898f
add rewrite policy to websocket log endpoint
0344ef6
correct path params to query params
db09353
pass wait params to client
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM --platform=$BUILDPLATFORM docker.io/golang:1.18 as builder | ||
WORKDIR /go/src | ||
# Copy `go.mod` for definitions and `go.sum` to invalidate the next layer | ||
# in case of a change in the dependencies | ||
COPY ../server/go.mod ../server/go.sum ./ | ||
# Download dependencies | ||
RUN go mod download | ||
|
||
ARG TELEMETRY_TOKEN | ||
ARG VERSION | ||
ARG TARGETARCH | ||
ARG TARGETOS | ||
|
||
COPY ../server ./ | ||
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -v -ldflags "-X github.com/kubeshop/kusk-gateway/pkg/analytics.TelemetryToken=$TELEMETRY_TOKEN -X github.com/kubeshop/kusk-gateway/pkg/build.Version=$VERSION" -o kusk-gateway-api-websocket cmd/websocket/*.go | ||
|
||
FROM --platform=$BUILDPLATFORM gcr.io/distroless/static:nonroot | ||
COPY --from=builder --chown=65532:65532 /go/src/kusk-gateway-api-websocket ./ | ||
|
||
USER 65532:65532 | ||
|
||
ENTRYPOINT ["./kusk-gateway-api-websocket"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
version: "3" | ||
services: | ||
kgwapi: | ||
build: ./server | ||
build: | ||
context: . | ||
dockerfile: ./build/api-server/Dockerfile | ||
environment: | ||
- KUBECONFIG=/kube/config | ||
- ANALYTICS_ENABLED=false | ||
volumes: | ||
- $HOME/.kube/config:/kube/config:ro | ||
ports: | ||
- 8080:8080 | ||
- "8080:8080" | ||
websocket: | ||
build: | ||
context: . | ||
dockerfile: ./build/websocket/Dockerfile | ||
environment: | ||
- KUBECONFIG=/kube/config | ||
volumes: | ||
- $HOME/.kube/config:/kube/config:ro | ||
ports: | ||
- "8081:8080" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"io" | ||
"log" | ||
"time" | ||
|
||
"github.com/gorilla/websocket" | ||
) | ||
|
||
type client struct { | ||
conn *websocket.Conn | ||
logStream io.ReadCloser | ||
|
||
writeWait time.Duration | ||
pongWait time.Duration | ||
pingPeriod time.Duration | ||
maxMessageSize int64 | ||
} | ||
|
||
func (c *client) readPump(ctx context.Context, stopCh chan struct{}) { | ||
defer func() { | ||
c.conn.Close() | ||
stopCh <- struct{}{} | ||
}() | ||
c.conn.SetReadLimit(c.maxMessageSize) | ||
c.conn.SetReadDeadline(time.Now().Add(c.pongWait)) | ||
c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(c.pongWait)); return nil }) | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
default: | ||
_, _, err := c.conn.ReadMessage() | ||
if err != nil { | ||
if websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure, websocket.CloseNormalClosure) { | ||
log.Printf("error: %v", err) | ||
} | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (c *client) writePump(ctx context.Context, stopCh chan struct{}) { | ||
ticker := time.NewTicker(c.pingPeriod) | ||
defer func() { | ||
ticker.Stop() | ||
c.conn.Close() | ||
stopCh <- struct{}{} | ||
}() | ||
|
||
reader := bufio.NewReader(c.logStream) | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
case <-stopCh: | ||
return | ||
case <-ticker.C: | ||
c.conn.SetWriteDeadline(time.Now().Add(c.writeWait)) | ||
if err := c.conn.WriteMessage(websocket.PingMessage, nil); err != nil { | ||
return | ||
} | ||
default: | ||
c.conn.SetWriteDeadline(time.Now().Add(c.writeWait)) | ||
line, err := readLongLine(reader) | ||
if err != nil { | ||
log.Println("writePump: cannot read line", err) | ||
continue | ||
} | ||
|
||
if err := c.conn.WriteMessage(websocket.TextMessage, line); err != nil { | ||
log.Println("writePump: cannot write message", err) | ||
continue | ||
} | ||
} | ||
} | ||
} | ||
|
||
func readLongLine(r *bufio.Reader) (line []byte, err error) { | ||
var buffer []byte | ||
var isPrefix bool | ||
|
||
for { | ||
buffer, isPrefix, err = r.ReadLine() | ||
line = append(line, buffer...) | ||
if err != nil { | ||
break | ||
} | ||
|
||
if !isPrefix { | ||
break | ||
} | ||
} | ||
|
||
return line, err | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change the type to an array of string? because it generates a wrong type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's
it
? Are you using a library on the front end to generate stuff?