Skip to content

Commit

Permalink
Changes console behavior to streaming by default, adds relative/absol…
Browse files Browse the repository at this point in the history
…ute time filtering options (#9)

* Changed default behavior in console from fetching all logs to
streaming new data
* Added a selector that allows users to filter logs using relative time
(e.g. 5 minutes ago) or absolute time
  • Loading branch information
amorey committed Feb 19, 2024
1 parent 21c5921 commit 2ce0696
Show file tree
Hide file tree
Showing 17 changed files with 901 additions and 330 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ WORKDIR /frontend

# enable pnpm
RUN corepack enable
RUN corepack prepare [email protected].1 --activate
RUN corepack prepare [email protected].3 --activate

# set up git+ssh for private package download from github
RUN apk add git openssh-client
Expand Down
18 changes: 4 additions & 14 deletions backend/graph/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"k8s.io/client-go/kubernetes"
"k8s.io/utils/ptr"

"github.com/kubetail-org/kubetail/graph/lib"
"github.com/kubetail-org/kubetail/graph/model"
)

Expand Down Expand Up @@ -219,17 +218,6 @@ func newLogRecordFromLogLine(logLine string) model.LogRecord {
}
}

func validatePodLogQueryTimeArgs(now time.Time, args ...string) error {
for _, arg := range args {
if ts, err := time.Parse(time.RFC3339Nano, arg); err == nil {
if ts.After(now) {
return lib.NewValidationError("custom", "`since` and `until` timestamp values must be in the past")
}
}
}
return nil
}

func tailPodLog(ctx context.Context, clientset kubernetes.Interface, namespace string, name string, container *string, args TailArgs) (<-chan model.LogRecord, error) {
// init output channel
ch := make(chan model.LogRecord)
Expand All @@ -246,7 +234,8 @@ func tailPodLog(ctx context.Context, clientset kubernetes.Interface, namespace s
)

// handle `since`
if since := strings.TrimSpace(args.Since); since == "" {
since := strings.TrimSpace(args.Since)
if strings.ToLower(since) == "beginning" {
tailSince = TailSinceBeginning
} else if strings.ToLower(since) == "now" {
tailSince = TailSinceNow
Expand All @@ -270,7 +259,8 @@ func tailPodLog(ctx context.Context, clientset kubernetes.Interface, namespace s
}

// handle `until`
if until := strings.TrimSpace(args.Until); until == "" {
until := strings.TrimSpace(args.Until)
if strings.ToLower(until) == "forever" {
tailUntil = TailUntilForever
} else if strings.ToLower(until) == "now" {
tailUntil = TailUntilTime
Expand Down
4 changes: 2 additions & 2 deletions backend/graph/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ type Query {
name: String!,
container: String,
after: String,
since: String,
since: String = "BEGINNING",
until: String = "NOW",
limit: Int @validate(rule: "gt=0", message: "Value must be greater than 0")
): [LogRecord!] @nullIfValidationFailed
Expand Down Expand Up @@ -678,7 +678,7 @@ type Subscription {
"""
Returns log records that came until the specified option (e.g. "NOW", "PT1M", "2006-01-03T15:04:05Z07:00")
"""
until: String
until: String = "FOREVER"

"""
Close the subscription after _n_ records are returned.
Expand Down
22 changes: 16 additions & 6 deletions backend/graph/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions backend/internal/ginapp/ginapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,6 @@ func TestHealthz(t *testing.T) {
assert.Equal(t, "{\"status\":\"ok\"}", w.Body.String())
}

func TestGraphQLPlayground(t *testing.T) {
app := NewTestApp(nil)

// check url
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/graphiql", nil)
app.ServeHTTP(w, r)

// check result
res := w.Result()
assert.Equal(t, http.StatusOK, res.StatusCode)
}

func TestWraponce(t *testing.T) {
app := NewTestApp(nil)

Expand Down
5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
"@heroicons/react": "^2.1.1",
"async-mutex": "^0.4.1",
"clsx": "^2.1.0",
"date-fns": "^3.3.1",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
"distinct-colors": "^3.0.0",
"graphql": "^16.8.1",
"graphql-ws": "^5.15.0",
"kubetail-ui": "github:kubetail-org/kubetail-ui#v0.1.0",
"kubetail-ui": "github:kubetail-org/kubetail-ui#v0.1.1",
"lucide-react": "^0.303.0",
"react": "^18.2.0",
"react-day-picker": "^8.10.0",
Expand Down
129 changes: 107 additions & 22 deletions frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2ce0696

Please sign in to comment.