Skip to content

Commit

Permalink
Merge pull request #1623 from merico-dev/1622-ignore-optionshost-from…
Browse files Browse the repository at this point in the history
…-httpmerico_metric-query

1622 ignore optionshost from httpmerico metric query
  • Loading branch information
GerilLeto authored Feb 18, 2025
2 parents 178165b + eac8270 commit c4fc3c8
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/api",
"version": "14.12.0",
"version": "14.13.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions api/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"ACCOUNT_NOT_FOUND": "Account not found",
"ACCOUNT_NO_DELETE_SUPERADMIN": "Can not delete superadmin account",
"DATASOURCE_HTTP_REQUIRED_FIELDS": "Pre processing and post processing are both required for HTTP datasource",
"DATASOURCE_HTTP_MISSING_HOST": "Host info is required but missing in this HTTP datasource",
"DATASOURCE_MMS_MISSING_HOST": "Host info is required but missing in this Merico Metric System datasource",
"DATASOURCE_DB_REQUIRED_FIELDS": "Mysql|Postgresql config must contain [port, username, password, database]",
"DATASOURCE_RENAME_SAME_KEY": "New key is the same as the old one",
"DATASOURCE_NO_DELETE_PRESET": "Can not delete preset datasources",
Expand Down
2 changes: 2 additions & 0 deletions api/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"ACCOUNT_NOT_FOUND": "账户不存在",
"ACCOUNT_NO_DELETE_SUPERADMIN": "无法删除超级管理员",
"DATASOURCE_HTTP_REQUIRED_FIELDS": "HTTP数据源需要预处理和后处理",
"DATASOURCE_HTTP_MISSING_HOST": "请求的HTTP数据源未配置Host信息",
"DATASOURCE_MMS_MISSING_HOST": "请求的指标系统数据源未配置Host信息",
"DATASOURCE_DB_REQUIRED_FIELDS": "Mysql|Postgresql配置必须包含[port,username,password,database]",
"DATASOURCE_RENAME_SAME_KEY": "新key与旧key相同",
"DATASOURCE_NO_DELETE_PRESET": "无法删除预设数据源",
Expand Down
18 changes: 9 additions & 9 deletions api/src/services/query.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class QueryService {
locale: string,
auth?: Account | ApiKey,
): Promise<any> {
const result = await this.mericoMetricQuery(key, query);
const result = await this.mericoMetricQuery(key, query, locale);
return result;
}
async queryStructure(
Expand Down Expand Up @@ -281,11 +281,11 @@ export class QueryService {
break;

case 'http':
result = await this.httpQuery(parsedKey, q);
result = await this.httpQuery(parsedKey, q, locale);
break;

case 'merico_metric_system':
result = await this.mericoMetricQuery(parsedKey, q);
result = await this.mericoMetricQuery(parsedKey, q, locale);
break;

default:
Expand Down Expand Up @@ -424,23 +424,23 @@ export class QueryService {
return source.query(sql);
}

private async httpQuery(key: string, query: string): Promise<any> {
private async httpQuery(key: string, query: string, locale: string): Promise<any> {
const options = validateClass(HttpParams, JSON.parse(query));
const sourceConfig = await DataSourceService.getByTypeKey('http', key);
let { host } = sourceConfig.config;
const { host } = sourceConfig.config;
if (!host) {
host = options.host;
throw new ApiError(BAD_REQUEST, { message: translate('DATASOURCE_HTTP_MISSING_HOST', locale) });
}
return APIClient.request(host)(options);
}

private async mericoMetricQuery(key: string, query: string): Promise<any> {
private async mericoMetricQuery(key: string, query: string, locale: string): Promise<any> {
// const options = validateClass(HttpParams, JSON.parse(query));
const options = JSON.parse(query);
const sourceConfig = await DataSourceService.getByTypeKey('merico_metric_system', key);
let { host } = sourceConfig.config;
const { host } = sourceConfig.config;
if (!host) {
host = options.host;
throw new ApiError(BAD_REQUEST, { message: translate('DATASOURCE_MMS_MISSING_HOST', locale) });
}
return APIClient.request(host)(options, (err) => _.get(err, 'response.data.detail.message', err.message));
}
Expand Down
3 changes: 2 additions & 1 deletion api/src/utils/api_client.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import axios, { AxiosError, AxiosRequestConfig } from 'axios';
import { HttpParams } from '../api_models/query';
import log, { LOG_LABELS, LOG_LEVELS } from './logger';
import _ from 'lodash';

export const APIClient = {
request(host: string) {
return (options: HttpParams, errorMessageGetter?: (err: AxiosError) => string) => {
const { method, url, headers, params, data, ...restOptions } = options;
const { method, url, headers, params, data, ...restOptions } = _.omit(options, 'host');

const conf: AxiosRequestConfig = {
baseURL: host,
Expand Down
2 changes: 2 additions & 0 deletions api/src/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ type ACCOUNT_KEYS =

type DATASOURCE_KEYS =
| 'DATASOURCE_HTTP_REQUIRED_FIELDS'
| 'DATASOURCE_HTTP_MISSING_HOST'
| 'DATASOURCE_MMS_MISSING_HOST'
| 'DATASOURCE_DB_REQUIRED_FIELDS'
| 'DATASOURCE_RENAME_SAME_KEY'
| 'DATASOURCE_NO_DELETE_PRESET'
Expand Down
2 changes: 1 addition & 1 deletion dashboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/dashboard",
"version": "14.12.0",
"version": "14.13.0",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/root",
"version": "14.12.0",
"version": "14.13.0",
"private": true,
"workspaces": [
"api",
Expand Down
2 changes: 1 addition & 1 deletion settings-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devtable/settings-form",
"version": "14.12.0",
"version": "14.13.0",
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
Expand Down
3 changes: 2 additions & 1 deletion settings-form/src/datasource/add-data-source/forms/http.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export function AddDataSourceForm_HTTP({ submit, styles = defaultStyles }: IAddD
<TextInput
mb={styles.spacing}
size={styles.size}
label={t('datasource.http.base_url')}
required
label={t('datasource.http.host')}
sx={{ flexGrow: 1 }}
{...field}
/>
Expand Down
3 changes: 2 additions & 1 deletion settings-form/src/datasource/edit-data-source/forms/http.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export function EditDataSourceForm_HTTP({ name, config, submit, styles = default
<TextInput
mb={styles.spacing}
size={styles.size}
label={t('datasource.http.base_url')}
required
label={t('datasource.http.host')}
sx={{ flexGrow: 1 }}
{...field}
/>
Expand Down
2 changes: 1 addition & 1 deletion settings-form/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const en = {
cant_delete_preset: 'This is a preset datasource, it can not be deleted',
},
http: {
base_url: 'Base URL',
host: 'Host',
processing: {
pre: {
label: 'Pre processing of queries',
Expand Down
2 changes: 1 addition & 1 deletion settings-form/src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const zh = {
cant_delete_preset: '这是预设数据源,不可删除',
},
http: {
base_url: '访问地址',
host: 'Host',
processing: {
pre: {
label: '查询请求预处理',
Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@devtable/website",
"private": true,
"license": "Apache-2.0",
"version": "14.12.0",
"version": "14.13.0",
"scripts": {
"dev": "vite",
"preview": "vite preview"
Expand Down

0 comments on commit c4fc3c8

Please sign in to comment.