Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Introduce actuator endpoint, the first method is Info which returns basic server info

天舟7dc6d711e5d4
diff --git a/api/actuator.go b/api/actuator.go
new file mode 100644
index 0000000000..d84786ed49
--- /dev/null
+++ b/api/actuator.go
@@ -0,0 +1,9 @@
+package api
+
+// Actuator concept is similar to the Spring Boot Actuator
+type ServerInfo struct {
+ Mode string `json:"mode"`
+ Host string `json:"host"`
+ Port string `json:"port"`
+ StartedTs int64 `json:"startedTs"`
+}
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index 72506e07d3..44de961267 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -154,7 +154,7 @@ func (m *main) Run() error {
m.db = db
- server := server.NewServer(m.l, host, port)
+ server := server.NewServer(m.l, m.profile.mode, host, port)
server.PrincipalService = store.NewPrincipalService(m.l, db)
server.MemberService = store.NewMemberService(m.l, db)
server.ProjectService = store.NewProjectService(m.l, db)
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vue
index 2e115cc34d..18719d547a 100644
--- a/frontend/src/components/ProfileDropdown.vue
+++ b/frontend/src/components/ProfileDropdown.vue
@@ -90,6 +90,7 @@ import { computed } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import PrincipalAvatar from "./PrincipalAvatar.vue";
+import { ServerInfo } from "../types";
export default {
name: "ProfileDropdown",
@@ -173,11 +174,11 @@ export default {
};
const ping = () => {
- store.dispatch("debug/ping").then((message: string) => {
+ store.dispatch("actuator/info").then((info: ServerInfo) => {
store.dispatch("notification/pushNotification", {
module: "bytebase",
style: "SUCCESS",
- title: message,
+ title: info,
});
});
};
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index 6dba8211ed..98afc95632 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -17,6 +17,8 @@ export default {
store.getters["auth/currentUser"]()
);
+ await store.dispatch("actuator/info");
+
await store.dispatch("environment/fetchEnvironmentList");
await Promise.all([
diff --git a/frontend/src/layouts/BodyLayout.vue b/frontend/src/layouts/BodyLayout.vue
index 441e777c06..c4657f20e6 100644
--- a/frontend/src/layouts/BodyLayout.vue
+++ b/frontend/src/layouts/BodyLayout.vue
@@ -262,7 +262,7 @@ import Breadcrumb from "../components/Breadcrumb.vue";
import Quickstart from "../components/Quickstart.vue";
import QuickActionPanel from "../components/QuickActionPanel.vue";
import { QuickActionType } from "../types";
-import { isDBA, isDemo, isDeveloper, isOwner } from "../utils";
+import { isDBA, isDeveloper, isOwner } from "../utils";
interface LocalState {
showMobileOverlay: boolean;
@@ -335,7 +335,10 @@ export default {
const showQuickstart = computed(() => {
// Do not show quickstart in demo mode since we don't expect user to alter the data
- return !isDemo() && !store.getters["uistate/introStateByKey"]("hidden");
+ return (
+ !store.getters["actuator/isDemo"]() &&
+ !store.getters["uistate/introStateByKey"]("hidden")
+ );
});
return {
diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vue
index 00cded2cb7..15e63588e9 100644
--- a/frontend/src/layouts/DashboardLayout.vue
+++ b/frontend/src/layouts/DashboardLayout.vue
@@ -33,6 +33,8 @@ import { useStore } from "vuex";
import ProvideDashboardContext from "../components/ProvideDashboardContext.vue";
import DashboardHeader from "../views/DashboardHeader.vue";
import BannerDemo from "../views/BannerDemo.vue";
+import { ServerInfo } from "../types";
+import { computed } from "@vue/runtime-core";
export default {
name: "DashboardLayout",
@@ -41,17 +43,20 @@ export default {
const store = useStore();
const ping = () => {
- store.dispatch("debug/ping").then((message: string) => {
+ store.dispatch("actuator/info").then((info: ServerInfo) => {
store.dispatch("notification/pushNotification", {
module: "bytebase",
style: "SUCCESS",
- title: message,
+ title: info,
});
});
};
+ const isDemo = computed(() => store.getters["actuator/isDemo"]());
+
return {
ping,
+ isDemo,
};
},
};
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index e46819ea4e..e4d772cb63 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -35,7 +35,6 @@ import dataSourceType from "./directives/data-source-type";
import highlight from "./directives/highlight";
import {
isDev,
- isDemo,
isRelease,
backendURL,
humanizeTs,
@@ -51,6 +50,7 @@ import {
dataSourceSlug,
registerStoreWithRoleUtil,
} from "./utils";
+import { ServerInfo } from "./types";
const app = createApp(App);
@@ -60,7 +60,6 @@ app.config.globalProperties.console = console;
app.config.globalProperties.moment = moment;
app.config.globalProperties.humanizeTs = humanizeTs;
app.config.globalProperties.isDev = isDev();
-app.config.globalProperties.isDemo = isDemo();
app.config.globalProperties.isRelease = isRelease();
app.config.globalProperties.sizeToFit = sizeToFit;
app.config.globalProperties.urlfy = urlfy;
@@ -76,7 +75,6 @@ app.config.globalProperties.dataSourceSlug = dataSourceSlug;
registerStoreWithRoleUtil(store);
console.debug("dev:", isDev());
-console.debug("demo:", isDemo());
console.debug("release:", isRelease());
console.debug("backend:", backendURL());
diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.ts
index 6197311590..1b65ed891c 100644
--- a/frontend/src/store/index.ts
+++ b/frontend/src/store/index.ts
@@ -31,8 +31,8 @@ import router from "./modules/router";
import command from "./modules/command";
import notification from "./modules/notification";
-// Debug module
-import debug from "./modules/debug";
+// Actuator module
+import actuator from "./modules/actuator";
const isProd = import.meta.env.NODE_ENV == "production";
@@ -63,7 +63,7 @@ export const store: Store<any> = createStore({
router,
command,
notification,
- debug,
+ actuator,
},
strict: !isProd,
});
diff --git a/frontend/src/store/modules/actuator.ts b/frontend/src/store/modules/actuator.ts
new file mode 100644
index 0000000000..0f5f5a4a84
--- /dev/null
+++ b/frontend/src/store/modules/actuator.ts
@@ -0,0 +1,39 @@
+import axios from "axios";
+import { ActuatorState, ServerInfo } from "../../types";
+
+const state: () => ActuatorState = () => ({
+ serverInfo: undefined,
+});
+
+const getters = {
+ info: (state: ActuatorState) => (): ServerInfo | undefined => {
+ return state.serverInfo;
+ },
+ isDemo: (state: ActuatorState) => (): boolean => {
+ return state.serverInfo?.mode == "demo";
+ },
+};
+
+const actions = {
+ async info({ commit }: any): Promise<ServerInfo> {
+ const serverInfo = (await axios.get(`/api/actuator/info`)).data;
+
+ commit("setInfo", serverInfo);
+
+ return serverInfo;
+ },
+};
+
+const mutations = {
+ setInfo(state: ActuatorState, serverInfo: ServerInfo) {
+ state.serverInfo = serverInfo;
+ },
+};
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ actions,
+ mutations,
+};
diff --git a/frontend/src/store/modules/debug.ts b/frontend/src/store/modules/debug.ts
deleted file mode 100644
index b39196fe9d..0000000000
--- a/frontend/src/store/modules/debug.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import axios from "axios";
-
-const getters = {};
-
-const actions = {
- async ping() {
- const message = (await axios.get(`/api/ping`)).data;
- return message;
- },
-};
-
-const mutations = {};
-
-export default {
- namespaced: true,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/types/actuator.ts b/frontend/src/types/actuator.ts
new file mode 100644
index 0000000000..5f5db20461
--- /dev/null
+++ b/frontend/src/types/actuator.ts
@@ -0,0 +1,6 @@
+export type ServerInfo = {
+ mode: string;
+ host: string;
+ port: string;
+ startedTs: number;
+};
diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts
index 1d6c8dac84..7e8582b811 100644
--- a/frontend/src/types/index.ts
+++ b/frontend/src/types/index.ts
@@ -21,5 +21,7 @@ export * from "./notification";
export * from "./plan";
export * from "./store";
+export * from "./actuator";
+
export * from "./oauth";
export * from "./jsonapi";
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 00db676d5e..bfc2dec3c9 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -25,6 +25,11 @@ import { Notification } from "./notification";
import { Table } from "./table";
import { VCS } from "./vcs";
import { Repository } from "./repository";
+import { ServerInfo } from "./actuator";
+
+export interface ActuatorState {
+ serverInfo?: ServerInfo;
+}
export interface AuthState {
currentUser: Principal;
diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts
index 4a6671946f..a80bb68704 100644
--- a/frontend/src/utils/util.ts
+++ b/frontend/src/utils/util.ts
@@ -4,12 +4,8 @@ export function isDev(): boolean {
return import.meta.env.DEV;
}
-export function isDemo(): boolean {
- return import.meta.env.MODE === "demo";
-}
-
export function isRelease(): boolean {
- return import.meta.env.PROD && !isDemo();
+ return import.meta.env.PROD;
}
// Use VITE_BACKEND as the backendURL if specified. Otherwise, just use the current host
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index 8754fae0e8..f6244e283d 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -124,8 +124,7 @@
<div
class="
py-6
- lg:pl-4
- lg:w-96
+ lg:pl-4 lg:w-96
xl:w-112
lg:border-l lg:border-block-border
"
@@ -204,7 +203,6 @@ import isEqual from "lodash-es/isEqual";
import {
idFromSlug,
issueSlug,
- isDemo,
pipelineType,
PipelineType,
indexFromSlug,
@@ -366,7 +364,7 @@ export default {
};
// For demo mode, we assign the issue to the current user, so it can also experience the assignee user flow.
- if (isDemo()) {
+ if (store.getters["actuator/isDemo"]()) {
newIssue.assigneeId = currentUser.value.id;
}
diff --git a/server/acl_casbin_policy_dba.csv b/server/acl_casbin_policy_dba.csv
index 3e0be9bf06..cb90081105 100644
--- a/server/acl_casbin_policy_dba.csv
+++ b/server/acl_casbin_policy_dba.csv
@@ -1,3 +1,4 @@
+p, DBA, /actuator/info, GET
p, DBA, /principal, GET
p, DBA, /principal/{id}, GET
p, DBA, /principal/{id}, PATCH_SELF
diff --git a/server/acl_casbin_policy_developer.csv b/server/acl_casbin_policy_developer.csv
index 3dac02f7f7..7f166ba5b0 100644
--- a/server/acl_casbin_policy_developer.csv
+++ b/server/acl_casbin_policy_developer.csv
@@ -1,3 +1,4 @@
+p, DEVELOPER, /actuator/info, GET
p, DEVELOPER, /principal, GET
p, DEVELOPER, /principal/{id}, GET
p, DEVELOPER, /principal/{id}, PATCH_SELF
diff --git a/server/acl_casbin_policy_owner.csv b/server/acl_casbin_policy_owner.csv
index c96790071a..c48ef65f50 100644
--- a/server/acl_casbin_policy_owner.csv
+++ b/server/acl_casbin_policy_owner.csv
@@ -1,3 +1,4 @@
+p, OWNER, /actuator/info, GET
p, OWNER, /principal, POST
p, OWNER, /principal, GET
p, OWNER, /principal/{id}, GET
diff --git a/server/actuator.go b/server/actuator.go
new file mode 100644
index 0000000000..ff13d6c6c7
--- /dev/null
+++ b/server/actuator.go
@@ -0,0 +1,21 @@
+package server
+
+import (
+ "net/http"
+ "strconv"
+
+ "github.com/bytebase/bytebase/api"
+ "github.com/labstack/echo/v4"
+)
+
+func (s *Server) registerActuatorRoutes(g *echo.Group) {
+ g.GET("/actuator/info", func(c echo.Context) error {
+ serverInfo := api.ServerInfo{
+ Mode: s.mode,
+ Host: s.host,
+ Port: strconv.Itoa(s.port),
+ StartedTs: s.startedTs,
+ }
+ return c.JSON(http.StatusOK, serverInfo)
+ })
+}
diff --git a/server/debug.go b/server/debug.go
deleted file mode 100644
index 2f96149810..0000000000
--- a/server/debug.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package server
-
-import (
- "fmt"
- "net/http"
- "time"
-
- "github.com/labstack/echo/v4"
-)
-
-func (s *Server) registerDebugRoutes(g *echo.Group) {
- g.GET("/ping", func(c echo.Context) error {
- return c.String(http.StatusOK, fmt.Sprintf("[%v] Pong from backend", time.Now().Format("2006-01-02 15:04:05")))
- })
-}
diff --git a/server/server.go b/server/server.go
index 7c52699ad3..b4bdded284 100644
--- a/server/server.go
+++ b/server/server.go
@@ -43,9 +43,11 @@ type Server struct {
e *echo.Echo
- l *zap.Logger
- host string
- port int
+ l *zap.Logger
+ mode string
+ host string
+ port int
+ startedTs int64
}
//go:embed dist
@@ -75,7 +77,7 @@ func getFileSystem() http.FileSystem {
return http.FS(fsys)
}
-func NewServer(logger *zap.Logger, host string, port int) *Server {
+func NewServer(logger *zap.Logger, mode, host string, port int) *Server {
e := echo.New()
// Catch-all route to return index.html, this is to prevent 404 when accessing non-root url.
@@ -88,10 +90,12 @@ func NewServer(logger *zap.Logger, host string, port int) *Server {
e.GET("/assets/*", echo.WrapHandler(assetHandler))
s := &Server{
- l: logger,
- e: e,
- host: host,
- port: port,
+ l: logger,
+ e: e,
+ mode: mode,
+ host: host,
+ port: port,
+ startedTs: time.Now().Unix(),
}
scheduler := NewTaskScheduler(logger, s)
@@ -144,8 +148,7 @@ func NewServer(logger *zap.Logger, host string, port int) *Server {
apiGroup.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return ACLMiddleware(logger, s, ce, next)
})
-
- s.registerDebugRoutes(apiGroup)
+ s.registerActuatorRoutes(apiGroup)
s.registerAuthRoutes(apiGroup)
s.registerPrincipalRoutes(apiGroup)
s.registerMemberRoutes(apiGroup)