mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-07-06 16:11:56 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b7bb409e96 | |||
| 9fa43ccc00 | |||
| c2a11050dd |
+1
-2
@@ -2,5 +2,4 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
/config.yml
|
/config.yml
|
||||||
/build/
|
/build/
|
||||||
/apipark
|
/apipark
|
||||||
.gitlab-ci.yml
|
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
variables:
|
||||||
|
PATH: /opt/go-1.21/go/bin/:/opt/node/node/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
|
||||||
|
GOROOT: /opt/go-1.21/go
|
||||||
|
GOPROXY: https://goproxy.cn
|
||||||
|
VERSION: $CI_COMMIT_SHORT_SHA
|
||||||
|
APP: apipark
|
||||||
|
APP_PRE: ${APP}_${VERSION}
|
||||||
|
BUILD_DIR: ${APP}-build
|
||||||
|
DEPLOY_DESC: "DEV 环境"
|
||||||
|
VIEW_ADDR: http://172.18.166.219:8288
|
||||||
|
SAVE_DIR: /opt/${APP}
|
||||||
|
NODE_OPTIONS: --max_old_space_size=8192
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- notice
|
||||||
|
- prefix
|
||||||
|
- build
|
||||||
|
- deploy
|
||||||
|
- webhook
|
||||||
|
|
||||||
|
feishu-informer: # 飞书回调
|
||||||
|
stage: notice
|
||||||
|
variables:
|
||||||
|
DIFF_URL: "$CI_MERGE_REQUEST_PROJECT_URL/-/merge_requests/$CI_MERGE_REQUEST_IID/diffs"
|
||||||
|
rules:
|
||||||
|
- if: $CI_PIPELINE_SOURCE=="merge_request_event" && $CI_COMMIT_BRANCH =~ "main"
|
||||||
|
script:
|
||||||
|
- echo "merge request"
|
||||||
|
- |
|
||||||
|
curl -X POST -H "Content-Type: application/json" \
|
||||||
|
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"项目:${CI_PROJECT_NAME}\\n提交人:${GITLAB_USER_NAME}\\n提交信息:${CI_MERGE_REQUEST_TITLE}\\n合并分支信息:${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} -> ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}\\n差异性地址:${DIFF_URL}\\n请及时review代码\"}}" \
|
||||||
|
https://open.feishu.cn/open-apis/bot/v2/hook/1c334752-2874-41a1-8f1b-3060f2d46b6c
|
||||||
|
|
||||||
|
prebuild:
|
||||||
|
stage: prefix
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == "main"
|
||||||
|
script:
|
||||||
|
- echo "prebuild"
|
||||||
|
- chmod +x ./scripts/prefix.sh
|
||||||
|
- ./scripts/prefix.sh
|
||||||
|
|
||||||
|
builder:
|
||||||
|
stage: build
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == "main"
|
||||||
|
script:
|
||||||
|
- set -e
|
||||||
|
- |
|
||||||
|
if [ ! -d "../artifacts" ]; then
|
||||||
|
mkdir -p ../artifacts
|
||||||
|
fi
|
||||||
|
if [ -d "../artifacts/dist" ]; then
|
||||||
|
cp -r ../artifacts/dist frontend/dist
|
||||||
|
fi
|
||||||
|
- |
|
||||||
|
if [ -n "$(git diff --name-status HEAD~1 HEAD -- frontend)" ]; then
|
||||||
|
./scripts/build.sh $BUILD_DIR ${VERSION} all ""
|
||||||
|
else
|
||||||
|
./scripts/build.sh $BUILD_DIR ${VERSION}
|
||||||
|
fi
|
||||||
|
if [ -d "frontend/dist" ]; then
|
||||||
|
echo "copy frontend/dist to artifacts/dist"
|
||||||
|
rm -fr ../artifacts/dist
|
||||||
|
cp -r frontend/dist ../artifacts/dist
|
||||||
|
fi
|
||||||
|
cp $BUILD_DIR/${APP_PRE}_linux_amd64.tar.gz ${SAVE_DIR}
|
||||||
|
|
||||||
|
deployer:
|
||||||
|
stage: deploy
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == "main"
|
||||||
|
variables:
|
||||||
|
APIPARK_GUEST_MODE: allow
|
||||||
|
APIPARK_GUEST_ID: dklejrfbhjqwdh
|
||||||
|
script:
|
||||||
|
- cd ${SAVE_DIR};mkdir -p ${APP_PRE};tar -zxvf ${APP_PRE}_linux_amd64.tar.gz -C ${APP_PRE};cd ${APP_PRE};./install.sh ${SAVE_DIR};./run.sh restart;cd ${SAVE_DIR} && ./clean.sh ${APP_PRE}
|
||||||
|
when: on_success
|
||||||
|
success:
|
||||||
|
stage: webhook
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == "main"
|
||||||
|
script:
|
||||||
|
- |
|
||||||
|
curl -X POST -H "Content-Type: application/json" \
|
||||||
|
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:${CI_PROJECT_NAME}\\n环境:${DEPLOY_DESC}\\n更新部署完成.\\n访问地址:${VIEW_ADDR}\\n工作流地址:${CI_PIPELINE_URL}\"}}" \
|
||||||
|
https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
|
||||||
|
when: on_success
|
||||||
|
failure:
|
||||||
|
stage: webhook
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH == "main"
|
||||||
|
script:
|
||||||
|
- |
|
||||||
|
curl -X POST -H "Content-Type: application/json" \
|
||||||
|
-d "{\"msg_type\":\"text\",\"content\":{\"text\":\"最近一次提交:${CI_COMMIT_TITLE}\\n提交人:${GITLAB_USER_NAME}\\n项目:${CI_PROJECT_NAME}\\n环境:${DEPLOY_DESC}\\n更新部署失败,请及时到gitlab上查看\\n工作流地址:${CI_PIPELINE_URL}\"}}" \
|
||||||
|
https://open.feishu.cn/open-apis/bot/v2/hook/c3672932-4dfa-4989-8023-0128bae59338
|
||||||
|
when: on_failure
|
||||||
@@ -146,20 +146,11 @@ export const PublishApprovalModalContent = forwardRef<PublishApprovalModalHandle
|
|||||||
...x,
|
...x,
|
||||||
title: typeof x.title === 'string' ? $t(x.title) : x.title,
|
title: typeof x.title === 'string' ? $t(x.title) : x.title,
|
||||||
...(x.dataIndex === 'status' ? {
|
...(x.dataIndex === 'status' ? {
|
||||||
render:(_,entity)=> {
|
render:(_,entity)=> (
|
||||||
switch(entity.change){
|
<span className={`${ApprovalStatusColorClass[entity.change as keyof typeof ApprovalStatusColorClass]} truncate block`}>
|
||||||
case 'none':
|
{$t(ChangeTypeEnum[entity.change as (keyof typeof ChangeTypeEnum)] || '-')}
|
||||||
return '-'
|
</span>
|
||||||
case 'new':
|
)
|
||||||
return $t('新建')
|
|
||||||
case 'update':
|
|
||||||
return $t('更新')
|
|
||||||
case 'delete':
|
|
||||||
return $t('删除')
|
|
||||||
default:
|
|
||||||
return '-'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}:{})
|
}:{})
|
||||||
}
|
}
|
||||||
}),[state.language])
|
}),[state.language])
|
||||||
|
|||||||
@@ -486,17 +486,17 @@ export const PERMISSION_DEFINITION = [
|
|||||||
},
|
},
|
||||||
"team.application.subscription.add": {
|
"team.application.subscription.add": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.subscription.subscribe"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.subscription.subscribe"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.subscription.edit": {
|
"team.application.subscription.edit": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.subscription.manager_subscribed_services"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.subscription.manager_subscribed_services"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.subscription.delete": {
|
"team.application.subscription.delete": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.team.consumer.subscription.manager_subscribed_services"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.team.consumer.subscription.manager_subscribed_services"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.application.view": {
|
"team.application.application.view": {
|
||||||
@@ -506,47 +506,47 @@ export const PERMISSION_DEFINITION = [
|
|||||||
},
|
},
|
||||||
"team.application.application.add": {
|
"team.application.application.add": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.application.edit": {
|
"team.application.application.edit": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.application.delete": {
|
"team.application.application.delete": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all",'team.team.consumer.manager',"team.consumer.application.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.consumer.authorization.view": {
|
"team.consumer.authorization.view": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","system.workspace.application.view_all","team.consumer.authorization.view"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","system.workspace.application.view_all","team.consumer.authorization.view"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.authorization.add": {
|
"team.application.authorization.add": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.authorization.edit": {
|
"team.application.authorization.edit": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.authorization.delete": {
|
"team.application.authorization.delete": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.authorization.cancelSubApply": {
|
"team.application.authorization.cancelSubApply": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.application.authorization.cancelSub": {
|
"team.application.authorization.cancelSub": {
|
||||||
"granted": {
|
"granted": {
|
||||||
"anyOf": [{ "backend": ["system.workspace.application.manager_al","team.consumer.authorization.manager"] }]
|
"anyOf": [{ "backend": ["system.workspace.application.manager_all","team.consumer.authorization.manager"] }]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"team.team.team.view": {
|
"team.team.team.view": {
|
||||||
|
|||||||
@@ -106,9 +106,9 @@ const AiSettingList = ()=>{
|
|||||||
</a>
|
</a>
|
||||||
<div>
|
<div>
|
||||||
<CancelBtn/>
|
<CancelBtn/>
|
||||||
<WithPermission access="system.devops.ai_provider.edit" showDisabled={false}>
|
{
|
||||||
<OkBtn/>
|
checkAccess('system.devops.ai_provider.edit', accessData) ? <OkBtn/> : null
|
||||||
</WithPermission>
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ const PartitionInsideDashboardSetting: FC = () => {
|
|||||||
pageTitle={$t('数据源')}
|
pageTitle={$t('数据源')}
|
||||||
description={$t("设置监控报表的数据来源,设置完成之后即可获得详细的API调用统计图表。")}
|
description={$t("设置监控报表的数据来源,设置完成之后即可获得详细的API调用统计图表。")}
|
||||||
showBorder={false}
|
showBorder={false}
|
||||||
scrollPage={true}
|
scrollPage={false}
|
||||||
>
|
>
|
||||||
<div className="flex flex-col overflow-auto pb-PAGE_INSIDE_B pr-PAGE_INSIDE_X">
|
<div className="flex flex-col overflow-auto pb-PAGE_INSIDE_B pr-PAGE_INSIDE_X">
|
||||||
<Spin wrapperClassName="flex-1" indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />} spinning={loading}>
|
<Spin wrapperClassName="flex-1" indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />} spinning={loading}>
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ export default defineConfig({
|
|||||||
target: 'http://172.18.166.219:8288/',
|
target: 'http://172.18.166.219:8288/',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
open: true
|
||||||
},
|
},
|
||||||
logLevel:'info'
|
logLevel:'info'
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { RouterParams } from "@core/components/aoplatform/RenderRoutes";
|
|||||||
import { SimpleTeamItem } from "@common/const/type";
|
import { SimpleTeamItem } from "@common/const/type";
|
||||||
import { useTenantManagementContext } from "../../../contexts/TenantManagementContext";
|
import { useTenantManagementContext } from "../../../contexts/TenantManagementContext";
|
||||||
import { Icon } from "@iconify/react/dist/iconify.js";
|
import { Icon } from "@iconify/react/dist/iconify.js";
|
||||||
import { useGlobalContext } from "@common/contexts/GlobalStateContext";
|
import { GlobalProvider, useGlobalContext } from "@common/contexts/GlobalStateContext";
|
||||||
import { $t } from "@common/locales";
|
import { $t } from "@common/locales";
|
||||||
import WithPermission from "@common/components/aoplatform/WithPermission";
|
import WithPermission from "@common/components/aoplatform/WithPermission";
|
||||||
import InsidePage from "@common/components/aoplatform/InsidePage";
|
import InsidePage from "@common/components/aoplatform/InsidePage";
|
||||||
@@ -149,7 +149,7 @@ export default function ServiceHubManagement() {
|
|||||||
switch (type){
|
switch (type){
|
||||||
case 'add':
|
case 'add':
|
||||||
title=$t('添加消费者')
|
title=$t('添加消费者')
|
||||||
content=<ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} />
|
content=<GlobalProvider><ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} /></GlobalProvider>
|
||||||
break;
|
break;
|
||||||
// case 'edit':{
|
// case 'edit':{
|
||||||
// title='配置 Open Api'
|
// title='配置 Open Api'
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ func NewDynamicClient(client admin_client.Client, resource string) (*DynamicClie
|
|||||||
cfg, has := gateway.GetDynamicResourceDriver(resource)
|
cfg, has := gateway.GetDynamicResourceDriver(resource)
|
||||||
if !has {
|
if !has {
|
||||||
return nil, errors.New("resource not found")
|
return nil, errors.New("resource not found")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &DynamicClient{client: client, profession: cfg.Profession, driver: cfg.Driver}, nil
|
return &DynamicClient{client: client, profession: cfg.Profession, driver: cfg.Driver}, nil
|
||||||
|
|||||||
+36
-4
@@ -57,10 +57,42 @@ var dynamicResourceMap = map[string]Worker{
|
|||||||
Profession: ProfessionCertificate,
|
Profession: ProfessionCertificate,
|
||||||
Driver: "server",
|
Driver: "server",
|
||||||
},
|
},
|
||||||
"loki": {
|
//"openai": {
|
||||||
Profession: ProfessionOutput,
|
// Profession: ProfessionAIProvider,
|
||||||
Driver: "loki",
|
// Driver: "openai",
|
||||||
},
|
//},
|
||||||
|
//"google": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "google",
|
||||||
|
//},
|
||||||
|
//"anthropic": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "anthropic",
|
||||||
|
//},
|
||||||
|
//"moonshot": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "moonshot",
|
||||||
|
//},
|
||||||
|
//"tongyi": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "tongyi",
|
||||||
|
//},
|
||||||
|
//"zhipuai": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "zhipuai",
|
||||||
|
//},
|
||||||
|
//"fireworks": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "fireworks",
|
||||||
|
//},
|
||||||
|
//"novita": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "novita",
|
||||||
|
//},
|
||||||
|
//"mistralai": {
|
||||||
|
// Profession: ProfessionAIProvider,
|
||||||
|
// Driver: "mistralai",
|
||||||
|
//},
|
||||||
}
|
}
|
||||||
|
|
||||||
type Worker struct {
|
type Worker struct {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type IFactory interface {
|
type IFactory interface {
|
||||||
Create(config string) (ILogDriver, map[string]interface{}, error)
|
Create(config string) (ILogDriver, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type factoryManager struct {
|
type factoryManager struct {
|
||||||
|
|||||||
+7
-21
@@ -11,8 +11,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eolinker/eosc/log"
|
|
||||||
|
|
||||||
log_driver "github.com/APIParkLab/APIPark/log-driver"
|
log_driver "github.com/APIParkLab/APIPark/log-driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,7 +21,7 @@ func init() {
|
|||||||
type factory struct {
|
type factory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *factory) Create(config string) (log_driver.ILogDriver, map[string]interface{}, error) {
|
func (f *factory) Create(config string) (log_driver.ILogDriver, error) {
|
||||||
|
|
||||||
return NewDriver(config)
|
return NewDriver(config)
|
||||||
}
|
}
|
||||||
@@ -37,27 +35,24 @@ type Driver struct {
|
|||||||
headers map[string]string
|
headers map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDriver(config string) (*Driver, map[string]interface{}, error) {
|
func NewDriver(config string) (*Driver, error) {
|
||||||
cfg := new(DriverConfig)
|
cfg := new(DriverConfig)
|
||||||
err := json.Unmarshal([]byte(config), cfg)
|
err := json.Unmarshal([]byte(config), cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = cfg.Check()
|
err = cfg.Check()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
headers := map[string]string{}
|
headers := map[string]string{}
|
||||||
for _, h := range cfg.Header {
|
for _, h := range cfg.Header {
|
||||||
headers[h.Key] = h.Value
|
headers[h.Key] = h.Value
|
||||||
}
|
}
|
||||||
return &Driver{
|
return &Driver{
|
||||||
url: cfg.URL,
|
url: cfg.URL,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
}, map[string]interface{}{
|
}, nil
|
||||||
"url": cfg.URL,
|
|
||||||
"headers": headers,
|
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) LogInfo(clusterId string, id string) (*log_driver.LogInfo, error) {
|
func (d *Driver) LogInfo(clusterId string, id string) (*log_driver.LogInfo, error) {
|
||||||
@@ -71,8 +66,6 @@ func (d *Driver) LogInfo(clusterId string, id string) (*log_driver.LogInfo, erro
|
|||||||
queries.Set("start", strconv.FormatInt(start.UnixNano(), 10))
|
queries.Set("start", strconv.FormatInt(start.UnixNano(), 10))
|
||||||
queries.Set("end", strconv.FormatInt(now.UnixNano(), 10))
|
queries.Set("end", strconv.FormatInt(now.UnixNano(), 10))
|
||||||
queries.Set("limit", "1")
|
queries.Set("limit", "1")
|
||||||
log.Debug("query is ", queries.Get("query"))
|
|
||||||
|
|
||||||
list, err := send[LogInfo](http.MethodGet, fmt.Sprintf("%s/loki/api/v1/query_range", d.url), d.headers, queries, "")
|
list, err := send[LogInfo](http.MethodGet, fmt.Sprintf("%s/loki/api/v1/query_range", d.url), d.headers, queries, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -107,13 +100,10 @@ func (d *Driver) LogCount(clusterId string, conditions map[string]string, spendH
|
|||||||
}
|
}
|
||||||
queries := url.Values{}
|
queries := url.Values{}
|
||||||
queries.Set("query", fmt.Sprintf("sum(count_over_time({cluster=\"%s\"} | json %s [%dh])) by (%s)", clusterId, tmpCondition, spendHour, group))
|
queries.Set("query", fmt.Sprintf("sum(count_over_time({cluster=\"%s\"} | json %s [%dh])) by (%s)", clusterId, tmpCondition, spendHour, group))
|
||||||
sendRequestTime := time.Now()
|
|
||||||
list, err := send[LogCount](http.MethodGet, fmt.Sprintf("%s/loki/api/v1/query", d.url), d.headers, queries, "")
|
list, err := send[LogCount](http.MethodGet, fmt.Sprintf("%s/loki/api/v1/query", d.url), d.headers, queries, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.DebugF("send request spend time: %v", time.Now().Sub(sendRequestTime))
|
|
||||||
log.Debug("query is ", queries.Get("query"))
|
|
||||||
result := make(map[string]int64)
|
result := make(map[string]int64)
|
||||||
for _, l := range list {
|
for _, l := range list {
|
||||||
if len(l.Value) != 2 {
|
if len(l.Value) != 2 {
|
||||||
@@ -168,7 +158,6 @@ func (d *Driver) Logs(clusterId string, conditions map[string]string, start time
|
|||||||
queries.Set("limit", strconv.FormatInt(limit, 10))
|
queries.Set("limit", strconv.FormatInt(limit, 10))
|
||||||
queries.Set("direction", "backward")
|
queries.Set("direction", "backward")
|
||||||
queries.Set("start", strconv.FormatInt(start.UnixNano(), 10))
|
queries.Set("start", strconv.FormatInt(start.UnixNano(), 10))
|
||||||
log.Debug("query is ", queries.Get("query"))
|
|
||||||
logs, err := d.recuseLogs(queries, end, offset)
|
logs, err := d.recuseLogs(queries, end, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
@@ -270,13 +259,10 @@ func send[T any](method string, uri string, headers map[string]string, queries u
|
|||||||
for key, value := range headers {
|
for key, value := range headers {
|
||||||
req.Header.Set(key, value)
|
req.Header.Set(key, value)
|
||||||
}
|
}
|
||||||
log.DebugF("do request: %s", uri)
|
|
||||||
doRequestTime := time.Now()
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to send request: %w", err)
|
return nil, fmt.Errorf("failed to send request: %w", err)
|
||||||
}
|
}
|
||||||
log.DebugF("do request spend time: %v", time.Now().Sub(doRequestTime))
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
respData, err := io.ReadAll(resp.Body)
|
respData, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -99,9 +99,6 @@ func (i *imlAuthorizationModule) getApplications(ctx context.Context, appIds []s
|
|||||||
Expire: a.ExpireTime,
|
Expire: a.ExpireTime,
|
||||||
Config: authCfg,
|
Config: authCfg,
|
||||||
HideCredential: a.HideCredential,
|
HideCredential: a.HideCredential,
|
||||||
Label: map[string]string{
|
|
||||||
"authorization": a.UUID,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-189
@@ -4,13 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
|
||||||
|
|
||||||
log_driver "github.com/APIParkLab/APIPark/log-driver"
|
|
||||||
|
|
||||||
"github.com/APIParkLab/APIPark/gateway"
|
|
||||||
|
|
||||||
"github.com/eolinker/go-common/store"
|
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
@@ -20,64 +13,15 @@ import (
|
|||||||
|
|
||||||
log_dto "github.com/APIParkLab/APIPark/module/log/dto"
|
log_dto "github.com/APIParkLab/APIPark/module/log/dto"
|
||||||
"github.com/APIParkLab/APIPark/service/log"
|
"github.com/APIParkLab/APIPark/service/log"
|
||||||
log_print "github.com/eolinker/eosc/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ ILogModule = (*imlLogModule)(nil)
|
var _ ILogModule = (*imlLogModule)(nil)
|
||||||
|
|
||||||
type imlLogModule struct {
|
type imlLogModule struct {
|
||||||
service log.ILogService `autowired:""`
|
service log.ILogService `autowired:""`
|
||||||
clusterService cluster.IClusterService `autowired:""`
|
|
||||||
transaction store.ITransaction `autowired:""`
|
|
||||||
}
|
|
||||||
|
|
||||||
var labels = map[string]string{
|
|
||||||
"cluster": "$cluster",
|
|
||||||
"node": "$node",
|
|
||||||
}
|
|
||||||
var logFormatter = map[string]interface{}{
|
|
||||||
"fields": []string{
|
|
||||||
"$msec",
|
|
||||||
"$service",
|
|
||||||
"$provider",
|
|
||||||
"$scheme as request_scheme",
|
|
||||||
"$url as request_uri",
|
|
||||||
"$host as request_host",
|
|
||||||
"$header as request_header",
|
|
||||||
"$remote_addr",
|
|
||||||
"$request_body",
|
|
||||||
"$proxy_body",
|
|
||||||
"$proxy_method",
|
|
||||||
"$proxy_scheme",
|
|
||||||
"$proxy_uri",
|
|
||||||
"$api",
|
|
||||||
"$proxy_host",
|
|
||||||
"$proxy_header",
|
|
||||||
"$proxy_addr",
|
|
||||||
"$response_headers",
|
|
||||||
"$status",
|
|
||||||
"$content_type",
|
|
||||||
"$proxy_status",
|
|
||||||
"$request_time",
|
|
||||||
"$response_time",
|
|
||||||
"$node",
|
|
||||||
"$cluster",
|
|
||||||
"$application",
|
|
||||||
"$src_ip",
|
|
||||||
"$block_name as strategy",
|
|
||||||
"$request_id",
|
|
||||||
"$request_method",
|
|
||||||
"$authorization",
|
|
||||||
"$response_body",
|
|
||||||
"$proxy_response_body",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imlLogModule) Save(ctx context.Context, driver string, input *log_dto.Save) error {
|
func (i *imlLogModule) Save(ctx context.Context, driver string, input *log_dto.Save) error {
|
||||||
factory, has := log_driver.GetFactory(driver)
|
|
||||||
if !has {
|
|
||||||
return errors.New("driver not found")
|
|
||||||
}
|
|
||||||
input.Cluster = cluster.DefaultClusterID
|
input.Cluster = cluster.DefaultClusterID
|
||||||
var cfg *string
|
var cfg *string
|
||||||
if input.Config != nil {
|
if input.Config != nil {
|
||||||
@@ -85,57 +29,10 @@ func (i *imlLogModule) Save(ctx context.Context, driver string, input *log_dto.S
|
|||||||
tmp := string(data)
|
tmp := string(data)
|
||||||
cfg = &tmp
|
cfg = &tmp
|
||||||
}
|
}
|
||||||
return i.transaction.Transaction(ctx, func(txCtx context.Context) error {
|
return i.service.UpdateLogSource(ctx, driver, &log.Save{
|
||||||
err := i.service.UpdateLogSource(txCtx, driver, &log.Save{
|
ID: input.ID,
|
||||||
ID: input.ID,
|
Cluster: &input.Cluster,
|
||||||
Cluster: &input.Cluster,
|
Config: cfg,
|
||||||
Config: cfg,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
info, err := i.service.GetLogSource(txCtx, driver)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
d, c, err := factory.Create(info.Config)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := i.clusterService.GatewayClient(txCtx, input.Cluster)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer client.Close(txCtx)
|
|
||||||
dynamicClient, err := client.Dynamic(driver)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
attr := make(map[string]interface{})
|
|
||||||
attr["driver"] = driver
|
|
||||||
attr["formatter"] = logFormatter
|
|
||||||
attr["labels"] = labels
|
|
||||||
attr["method"] = "POST"
|
|
||||||
attr["scopes"] = []string{"access_log"}
|
|
||||||
attr["type"] = "json"
|
|
||||||
for k, v := range c {
|
|
||||||
attr[k] = v
|
|
||||||
}
|
|
||||||
err = dynamicClient.Online(txCtx, &gateway.DynamicRelease{
|
|
||||||
BasicItem: &gateway.BasicItem{
|
|
||||||
ID: driver,
|
|
||||||
Description: "collect access log",
|
|
||||||
Version: time.Now().Format("20060102150405"),
|
|
||||||
Resource: gateway.ProfessionOutput,
|
|
||||||
},
|
|
||||||
Attr: attr,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log_driver.SetDriver(driver, d)
|
|
||||||
return nil
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,84 +60,3 @@ func (i *imlLogModule) Get(ctx context.Context, driver string) (*log_dto.LogSour
|
|||||||
UpdateAt: auto.TimeLabel(info.UpdateAt),
|
UpdateAt: auto.TimeLabel(info.UpdateAt),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imlLogModule) OnComplete() {
|
|
||||||
drivers := log_driver.Drivers()
|
|
||||||
if len(drivers) < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx := context.Background()
|
|
||||||
for _, driver := range drivers {
|
|
||||||
factory, has := log_driver.GetFactory(driver)
|
|
||||||
if !has {
|
|
||||||
log_print.Errorf("driver %s not found", driver)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
info, err := i.service.GetLogSource(ctx, driver)
|
|
||||||
if err != nil {
|
|
||||||
log_print.Errorf("get log source %s error: %s", driver, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
d, _, err := factory.Create(info.Config)
|
|
||||||
if err != nil {
|
|
||||||
log_print.Errorf("create driver %s error: %s,config: %s", driver, err, info.Config)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
log_driver.SetDriver(driver, d)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *imlLogModule) initGateway(ctx context.Context, clusterId string, clientDriver gateway.IClientDriver) error {
|
|
||||||
drivers := log_driver.Drivers()
|
|
||||||
if len(drivers) < 1 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, driver := range drivers {
|
|
||||||
factory, has := log_driver.GetFactory(driver)
|
|
||||||
if !has {
|
|
||||||
log_print.Errorf("driver %s not found", driver)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
info, err := i.service.GetLogSource(ctx, driver)
|
|
||||||
if err != nil {
|
|
||||||
log_print.Errorf("get log source %s error: %s", driver, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
d, c, err := factory.Create(info.Config)
|
|
||||||
if err != nil {
|
|
||||||
log_print.Errorf("create driver %s error: %s,config: %s", driver, err, info.Config)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
log_driver.SetDriver(driver, d)
|
|
||||||
dynamicClient, err := clientDriver.Dynamic(driver)
|
|
||||||
if err != nil {
|
|
||||||
log_print.Errorf("get dynamic client %s error: %s", driver, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
attr := make(map[string]interface{})
|
|
||||||
attr["driver"] = driver
|
|
||||||
attr["formatter"] = logFormatter
|
|
||||||
attr["labels"] = labels
|
|
||||||
attr["method"] = "POST"
|
|
||||||
for k, v := range c {
|
|
||||||
attr[k] = v
|
|
||||||
}
|
|
||||||
err = dynamicClient.Online(ctx, &gateway.DynamicRelease{
|
|
||||||
BasicItem: &gateway.BasicItem{
|
|
||||||
ID: driver,
|
|
||||||
Description: "collect access log",
|
|
||||||
Version: time.Now().Format("20060102150405"),
|
|
||||||
Resource: gateway.ProfessionOutput,
|
|
||||||
},
|
|
||||||
Attr: attr,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log_print.Errorf("online driver %s error: %s", driver, err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/eolinker/go-common/autowire"
|
"github.com/eolinker/go-common/autowire"
|
||||||
|
|
||||||
"github.com/APIParkLab/APIPark/gateway"
|
|
||||||
log_dto "github.com/APIParkLab/APIPark/module/log/dto"
|
log_dto "github.com/APIParkLab/APIPark/module/log/dto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,11 +15,7 @@ type ILogModule interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
logModule := new(imlLogModule)
|
|
||||||
|
|
||||||
autowire.Auto[ILogModule](func() reflect.Value {
|
autowire.Auto[ILogModule](func() reflect.Value {
|
||||||
|
return reflect.ValueOf(new(imlLogModule))
|
||||||
gateway.RegisterInitHandleFunc(logModule.initGateway)
|
|
||||||
return reflect.ValueOf(logModule)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -359,36 +359,3 @@ func (i *imlStrategyModule) Delete(ctx context.Context, id string) error {
|
|||||||
}
|
}
|
||||||
return i.strategyService.SortDelete(ctx, id)
|
return i.strategyService.SortDelete(ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imlStrategyModule) initGateway(ctx context.Context, clusterId string, clientDriver gateway.IClientDriver) error {
|
|
||||||
commits, err := i.strategyService.ListLatestStrategyCommit(ctx, strategy_dto.ScopeGlobal, "")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
publishStrategies := make([]*eosc.Base[gateway.StrategyRelease], 0, len(commits))
|
|
||||||
for _, c := range commits {
|
|
||||||
l := c.Data
|
|
||||||
if l.IsDelete {
|
|
||||||
err = i.strategyService.Delete(ctx, l.Id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
d, has := strategy_driver.GetDriver(l.Driver)
|
|
||||||
if !has {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
publishStrategies = append(publishStrategies, d.ToRelease(strategy_dto.ToStrategy(&strategy.Strategy{
|
|
||||||
Id: l.Id,
|
|
||||||
Name: l.Name,
|
|
||||||
Priority: l.Priority,
|
|
||||||
Filters: l.Filters,
|
|
||||||
Config: l.Config,
|
|
||||||
Driver: l.Driver,
|
|
||||||
IsStop: l.IsStop,
|
|
||||||
IsDelete: l.IsDelete,
|
|
||||||
}), nil, 5000))
|
|
||||||
}
|
|
||||||
|
|
||||||
return clientDriver.Strategy().Online(ctx, publishStrategies...)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/APIParkLab/APIPark/gateway"
|
|
||||||
|
|
||||||
"github.com/eolinker/go-common/autowire"
|
"github.com/eolinker/go-common/autowire"
|
||||||
|
|
||||||
_ "github.com/APIParkLab/APIPark/module/strategy/driver/data-masking"
|
_ "github.com/APIParkLab/APIPark/module/strategy/driver/data-masking"
|
||||||
@@ -34,7 +32,6 @@ type IStrategyModule interface {
|
|||||||
func init() {
|
func init() {
|
||||||
strategyModule := new(imlStrategyModule)
|
strategyModule := new(imlStrategyModule)
|
||||||
autowire.Auto[IStrategyModule](func() reflect.Value {
|
autowire.Auto[IStrategyModule](func() reflect.Value {
|
||||||
gateway.RegisterInitHandleFunc(strategyModule.initGateway)
|
|
||||||
return reflect.ValueOf(strategyModule)
|
return reflect.ValueOf(strategyModule)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-2
@@ -25,10 +25,30 @@ type imlLogService struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *imlLogService) OnComplete() {
|
func (i *imlLogService) OnComplete() {
|
||||||
|
drivers := log_driver.Drivers()
|
||||||
|
for _, d := range drivers {
|
||||||
|
factory, has := log_driver.GetFactory(d)
|
||||||
|
if !has {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
s, err := i.GetLogSource(context.Background(), d)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
driver, err := factory.Create(s.Config)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log_driver.SetDriver(d, driver)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *imlLogService) UpdateLogSource(ctx context.Context, driver string, input *Save) error {
|
func (i *imlLogService) UpdateLogSource(ctx context.Context, driver string, input *Save) error {
|
||||||
|
factory, has := log_driver.GetFactory(driver)
|
||||||
|
if !has {
|
||||||
|
return errors.New("driver not found")
|
||||||
|
}
|
||||||
s, err := i.store.First(ctx, map[string]interface{}{"driver": driver})
|
s, err := i.store.First(ctx, map[string]interface{}{"driver": driver})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
@@ -63,12 +83,15 @@ func (i *imlLogService) UpdateLogSource(ctx context.Context, driver string, inpu
|
|||||||
s.Updater = utils.UserId(ctx)
|
s.Updater = utils.UserId(ctx)
|
||||||
s.UpdateAt = time.Now()
|
s.UpdateAt = time.Now()
|
||||||
}
|
}
|
||||||
|
newDriver, err := factory.Create(s.Config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
err = i.store.Save(ctx, s)
|
err = i.store.Save(ctx, s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log_driver.SetDriver(driver, newDriver)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user