From ea36d13ab0b55bda1f14cb0a9c7dee255e368f19 Mon Sep 17 00:00:00 2001 From: SimFG Date: Wed, 4 Sep 2024 11:09:04 +0800 Subject: [PATCH] feat: add static view for the expr (#35887) - issue: #35886 /kind improvement Signed-off-by: SimFG --- internal/http/router.go | 3 + internal/http/server.go | 4 + internal/http/static/index.html | 170 ++++++++++++++++++++++++++++++++ internal/http/static_view.go | 33 +++++++ 4 files changed, 210 insertions(+) create mode 100644 internal/http/static/index.html create mode 100644 internal/http/static_view.go diff --git a/internal/http/router.go b/internal/http/router.go index 5d3f951b2b..2b8e0dbc67 100644 --- a/internal/http/router.go +++ b/internal/http/router.go @@ -28,6 +28,9 @@ const EventLogRouterPath = "/eventlog" // ExprPath is path for expression. const ExprPath = "/expr" +// StaticPath is path for the static view. +const StaticPath = "/static/" + const RootPath = "/" // Prometheus restful api path diff --git a/internal/http/server.go b/internal/http/server.go index f37e0ce442..08f6e9ec16 100644 --- a/internal/http/server.go +++ b/internal/http/server.go @@ -87,6 +87,10 @@ func registerDefaults() { w.Write([]byte(fmt.Sprintf(`{"output": "%s"}`, output))) }), }) + Register(&Handler{ + Path: StaticPath, + Handler: GetStaticHandler(), + }) } func RegisterStopComponent(triggerComponentStop func(role string) error) { diff --git a/internal/http/static/index.html b/internal/http/static/index.html new file mode 100644 index 0000000000..0a12f181e6 --- /dev/null +++ b/internal/http/static/index.html @@ -0,0 +1,170 @@ + + + + + + Milvus Expr Executor + + + +
Milvus Expr Executor
+
+
+

Input

+ + + +
+
+

Result

+

+    
+
+
+

Parameter meaning: +The auth parameter is etcd root path, and the code parameter is expr execution expression.
+Injection object: +Currently, the objects injected by expr include: param, proxy, rootcoord, querycoord, datacoord, quernode, datanode. You can use this tool to get the running value of the object.
+Usage example: +1. Get a configuration: param.CommonCfg.GracefulTime.GetValue() +2. Get a property value in the proxy object: proxy.address +3. Determine whether a graph exists in the datanode: datanode.flowgraphManager.HasFlowgraph("aaa")
+Limitations: +1. Variables cannot be modified. +2. Methods with non-basic type parameters cannot be executed. +3. Functions with multiple return values cannot be chained.

+
+ + + \ No newline at end of file diff --git a/internal/http/static_view.go b/internal/http/static_view.go new file mode 100644 index 0000000000..cb8e941ffe --- /dev/null +++ b/internal/http/static_view.go @@ -0,0 +1,33 @@ +/* + * Licensed to the LF AI & Data foundation under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package http + +import ( + "embed" + "io/fs" + "net/http" +) + +//go:embed static/* +var staticDir embed.FS + +func GetStaticHandler() http.Handler { + innerDir, _ := fs.Sub(staticDir, "static") + return http.StripPrefix("/static/", http.FileServer(http.FS(innerDir))) +}