From 205a00db3137dd086bf1a751d911ef65ab5b24b3 Mon Sep 17 00:00:00 2001 From: stone1100 Date: Tue, 29 Aug 2023 12:59:54 +0800 Subject: [PATCH] [bug]: fix data explore not support namespace --- .github/workflows/docker-latest.yml | 16 +++++++++ .github/workflows/docker-release.yml | 16 +++++++-- Dockerfile-gh | 39 +++++++++++++++++++++ web/src/components/data/MetadataSelect.tsx | 6 ++++ web/src/components/data/TagFilterSelect.tsx | 10 ++++-- web/src/pages/search/DataExplore.tsx | 15 ++++++-- 6 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 Dockerfile-gh diff --git a/.github/workflows/docker-latest.yml b/.github/workflows/docker-latest.yml index ec2034e80..eb8c9093a 100644 --- a/.github/workflows/docker-latest.yml +++ b/.github/workflows/docker-latest.yml @@ -11,15 +11,29 @@ jobs: push_to_registry: name: Push Docker image to Docker Hub runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] steps: - name: Check out code uses: actions/checkout@v3 with: fetch-depth: 1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Build Web + id: web + run: | + make build-frontend + echo "web=$PWD" >> $GITHUB_OUTPUT - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + with: + driver-opts: network=host - name: Docker meta id: meta uses: docker/metadata-action@v4 @@ -44,5 +58,7 @@ jobs: platforms: ${{ env.PLATFORMS }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + context: ${{ steps.web.outputs.web }} + file: Dockerfile-gh build-args: | LD_FLAGS=-ldflags=-s -w -X github.com/lindb/lindb/config.Version=latest -X github.com/lindb/lindb/config.BuildTime=${{ steps.date.outputs.date }} diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 6fa12cf4b..09d818f5c 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -12,12 +12,24 @@ jobs: push_to_registry: name: Push Docker image to Docker Hub runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] steps: - name: Check out code uses: actions/checkout@v3 with: fetch-depth: 1 ref: ${{ github.ref }} + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Build Web + id: web + run: | + make build-frontend + echo "web=$PWD" >> $GITHUB_OUTPUT - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx @@ -42,11 +54,11 @@ jobs: - name: Build and push uses: docker/build-push-action@v4 with: - context: . - file: ./Dockerfile + file: ./Dockerfile-gh push: true platforms: ${{ env.PLATFORMS }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + context: ${{ steps.web.outputs.web }} build-args: | LD_FLAGS=-ldflags=-s -w -X github.com/lindb/lindb/config.Version=${{ github.ref_name }} -X github.com/lindb/lindb/config.BuildTime=${{ steps.date.outputs.date }} diff --git a/Dockerfile-gh b/Dockerfile-gh new file mode 100644 index 000000000..3ef68bfd9 --- /dev/null +++ b/Dockerfile-gh @@ -0,0 +1,39 @@ +# Build the manager binary +FROM golang:1.19 as go_builder +ARG TARGETOS +ARG TARGETARCH +ARG LD_FLAGS + +WORKDIR /go_workspace +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum +# cache deps before building and copying source so that we don't need to re-download as much +# and so that source changes don't invalidate our downloaded layer +RUN go mod download + +# Copy src code +COPY . . + +# Copy web static resource +COPY ${GITHUB_WORKSPACE}/web/static/ web/static + +# Build +# the GOARCH has not a default value to allow the binary be built according to the host where the command +# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO +# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore, +# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} \ + go build "${LD_FLAGS}" -o lind ./cmd/lind \ + && go build "${LD_FLAGS}" -o lindctl ./cmd/cli + +FROM centos:latest +WORKDIR / +COPY --from=go_builder /go_workspace/lind /usr/bin/lind +COPY --from=go_builder /go_workspace/lindctl /usr/bin/lindctl +RUN ln -s /usr/bin/lind /usr/local/bin/lind +RUN ln -s /usr/bin/lindctl /usr/local/bin/lindctl +RUN mkdir /etc/lindb +RUN mkdir /data + +USER 0:0 diff --git a/web/src/components/data/MetadataSelect.tsx b/web/src/components/data/MetadataSelect.tsx index 331a02095..a945452cf 100644 --- a/web/src/components/data/MetadataSelect.tsx +++ b/web/src/components/data/MetadataSelect.tsx @@ -68,6 +68,12 @@ const MetadataSelect: React.FC<{ whereClause.push(...tags); } } + // set namespace + const namespace = _.get(params, "namespace"); + if (!_.isEmpty(namespace)) { + targetSQL += ` on '${namespace}'`; + } + if (!_.isEmpty(whereClause)) { targetSQL += ` where ${whereClause.join(" and ")}`; } diff --git a/web/src/components/data/TagFilterSelect.tsx b/web/src/components/data/TagFilterSelect.tsx index ab68d411b..70f805111 100644 --- a/web/src/components/data/TagFilterSelect.tsx +++ b/web/src/components/data/TagFilterSelect.tsx @@ -46,13 +46,15 @@ export default function TagFilterSelect(props: { const fetchTagKeys = async () => { const metadata = await ExecService.exec({ db: db, - sql: `show tag keys from '${metric}'`, + sql: `show tag keys from '${metric}'${ + namespace ? ` on '${namespace}'` : "" + }`, }); const tagKeys = (metadata as Metadata).values || []; setTagKeys(tagKeys as string[]); }; fetchTagKeys(); - }, [db, metric]); + }, [db, metric, namespace]); return ( diff --git a/web/src/pages/search/DataExplore.tsx b/web/src/pages/search/DataExplore.tsx index 5a42f399a..e96eb2d51 100644 --- a/web/src/pages/search/DataExplore.tsx +++ b/web/src/pages/search/DataExplore.tsx @@ -94,7 +94,12 @@ const ExploreForm: React.FC = () => { }; const MetricMetaForm: React.FC = () => { - const { db, metric, tags } = useParams(["db", "metric", "tags"]); + const { db, metric, namespace, tags } = useParams([ + "db", + "metric", + "namespace", + "tags", + ]); const formApi = useRef() as MutableRefObject; const [tagFilter, setTagFilter] = useState(); const { locale } = useContext(UIContext); @@ -164,7 +169,13 @@ const MetricMetaForm: React.FC = () => { }); } }} - suffix={} + suffix={ + + } />