Skip to content

Commit

Permalink
feat(dataobj): Add a Explorer UI for dataobj (#15908)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyriltovena authored Jan 23, 2025
1 parent 93cee63 commit 9b1407e
Show file tree
Hide file tree
Showing 43 changed files with 5,357 additions and 49 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cmd/querytee/querytee
dlv
rootfs/
dist
!pkg/dataobj/explorer/dist
*coverage.txt
*test_results.txt
.DS_Store
Expand All @@ -36,6 +37,8 @@ dist
pkg/loki/wal
tools/lambda-promtail/main
tools/dev/kafka/data/
pkg/dataobj/explorer/ui/node_modules/*
pkg/dataobj/explorer/ui/.vite/*

# Submodule added by `act` CLI
_shared-workflows-dockerhub-login
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ______ ____ __ __ _
# ______ ____ __ __ _
# / ____/________ _/ __/___ _____ ____ _ / / ____ / /__(_)
# / / __/ ___/ __ `/ /_/ __ `/ __ \/ __ `/ / / / __ \/ //_/ /
# / /_/ / / / /_/ / __/ /_/ / / / / /_/ / / /___/ /_/ / ,< / /
Expand Down Expand Up @@ -199,6 +199,8 @@ cmd/loki/loki:
cmd/loki/loki-debug:
CGO_ENABLED=0 go build $(DEBUG_GO_FLAGS) -o $@ ./$(@D)

ui-assets:
make -C pkg/dataobj/explorer/ui build
###############
# Loki-Canary #
###############
Expand Down
12 changes: 11 additions & 1 deletion cmd/loki/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
ARG GO_VERSION=1.23
FROM golang:${GO_VERSION} AS build

# UI build stage
FROM node:20-alpine AS ui-builder
RUN apk add --no-cache make
COPY . /src/loki
WORKDIR /src/loki
RUN make -C pkg/dataobj/explorer/ui build

# Go build stage
FROM golang:${GO_VERSION} AS build
COPY . /src/loki
COPY --from=ui-builder /src/loki/pkg/dataobj/explorer/dist /src/loki/pkg/dataobj/explorer/dist
WORKDIR /src/loki
RUN make clean && make BUILD_IN_CONTAINER=false loki

# Final stage
FROM gcr.io/distroless/static:debug

COPY --from=build /src/loki/cmd/loki/loki /usr/bin/loki
Expand Down
6 changes: 6 additions & 0 deletions docs/sources/shared/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,12 @@ kafka_config:
# CLI flag: -kafka.max-consumer-lag-at-startup
[max_consumer_lag_at_startup: <duration> | default = 15s]

dataobj_explorer:
# Prefix to use when exploring the bucket. If set, only objects under this
# prefix will be visible.
# CLI flag: -dataobj-explorer.storage-bucket-prefix
[storage_bucket_prefix: <string> | default = "dataobj/"]

# Configuration for 'runtime config' module, responsible for reloading runtime
# configuration file.
[runtime_config: <runtime_config>]
Expand Down
14 changes: 14 additions & 0 deletions pkg/dataobj/explorer/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package explorer

import "flag"

// Config holds the configuration for the explorer service
type Config struct {
// StorageBucketPrefix is the prefix to use when exploring the bucket
StorageBucketPrefix string `yaml:"storage_bucket_prefix"`
}

// RegisterFlags registers the flags for the explorer configuration
func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.StringVar(&cfg.StorageBucketPrefix, "dataobj-explorer.storage-bucket-prefix", "dataobj/", "Prefix to use when exploring the bucket. If set, only objects under this prefix will be visible.")
}
68 changes: 68 additions & 0 deletions pkg/dataobj/explorer/dist/assets/index-CWzBrpZu.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/dataobj/explorer/dist/assets/style-Dz5w-Rts.css

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pkg/dataobj/explorer/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DataObj Explorer</title>
<script type="module" crossorigin src="/dataobj/explorer/assets/index-CWzBrpZu.js"></script>
<link rel="stylesheet" crossorigin href="/dataobj/explorer/assets/style-Dz5w-Rts.css">
</head>

<body>
<div id="root"></div>
</body>

</html>
47 changes: 47 additions & 0 deletions pkg/dataobj/explorer/download.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package explorer

import (
"fmt"
"io"
"net/http"
"path"

"github.com/go-kit/log/level"
)

func (s *Service) handleDownload(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}

filename := r.URL.Query().Get("file")
if filename == "" {
http.Error(w, "file parameter is required", http.StatusBadRequest)
return
}

attrs, err := s.bucket.Attributes(r.Context(), filename)
if err != nil {
level.Error(s.logger).Log("msg", "failed to get file attributes", "file", filename, "err", err)
http.Error(w, fmt.Sprintf("failed to get file: %v", err), http.StatusInternalServerError)
return
}

reader, err := s.bucket.Get(r.Context(), filename)
if err != nil {
level.Error(s.logger).Log("msg", "failed to get file", "file", filename, "err", err)
http.Error(w, fmt.Sprintf("failed to get file: %v", err), http.StatusInternalServerError)
return
}
defer reader.Close()

w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, path.Base(filename)))
w.Header().Set("Content-Length", fmt.Sprintf("%d", attrs.Size))

if _, err := io.Copy(w, reader); err != nil {
level.Error(s.logger).Log("msg", "failed to stream file", "file", filename, "err", err)
return
}
}
Loading

0 comments on commit 9b1407e

Please sign in to comment.