Skip to content

Commit d4de825

Browse files
[BUGFIX] Add lint command in ClickHouse and fix linter errors (#547)
* linter fix Signed-off-by: rafi <rafialam@appscode.com> * fix type error in test file Signed-off-by: rafi <rafialam@appscode.com> --------- Signed-off-by: rafi <rafialam@appscode.com>
1 parent ccfbe97 commit d4de825

10 files changed

Lines changed: 27 additions & 23 deletions

File tree

clickhouse/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"build:cjs": "swc ./src -d dist/lib/cjs --strip-leading-paths --config-file ../.cjs.swcrc",
99
"build:esm": "swc ./src -d dist/lib --strip-leading-paths --config-file ../.swcrc",
1010
"build:types": "tsc --project tsconfig.build.json",
11+
"lint": "eslint src --ext .ts,.tsx",
1112
"test": "cross-env LC_ALL=C TZ=UTC jest",
1213
"type-check": "tsc --noEmit"
1314
},

clickhouse/src/datasources/click-house-datasource/ClickHouseDatasource.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
// limitations under the License.
1313

1414
import { DatasourcePlugin } from '@perses-dev/plugin-system';
15+
import { query } from '../../model/click-house-client';
1516
import { ClickHouseDatasourceSpec, ClickHouseDatasourceClient } from './click-house-datasource-types';
1617
import { ClickHouseDatasourceEditor } from './ClickHouseDatasourceEditor';
17-
import { query } from '../../model/click-house-client';
1818

1919
const createClient: DatasourcePlugin<ClickHouseDatasourceSpec, ClickHouseDatasourceClient>['createClient'] = (
2020
spec,

clickhouse/src/datasources/click-house-datasource/click-house-datasource-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface ClickHouseDatasourceResponse {
3434
status: string;
3535
warnings?: string[];
3636
// TODO: adjust this type to match your datasource response shape
37-
data: any;
37+
data: unknown;
3838
}
3939

4040
export interface ClickHouseDatasourceClient extends DatasourceClient {

clickhouse/src/model/click-house-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface ClickHouseQueryOptions {
2525

2626
export interface ClickHouseQueryResponse {
2727
status: 'success' | 'error';
28-
data: any;
28+
data: unknown;
2929
}
3030

3131
export interface ClickHouseClient {

clickhouse/src/model/click-house-data-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
import { LogEntry, LogData, TimeSeriesData } from '@perses-dev/core';
14+
import { LogData, TimeSeriesData } from '@perses-dev/core';
1515

1616
export interface ClickHouseTimeSeriesData extends TimeSeriesData {
1717
logs?: LogData;

clickhouse/src/queries/click-house-log-query/get-click-house-log-data.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
import { replaceVariables } from '@perses-dev/plugin-system';
1515
import { LogEntry, LogData } from '@perses-dev/core';
1616
import { ClickHouseClient, ClickHouseQueryResponse } from '../../model/click-house-client';
17-
import { ClickHouseLogQuerySpec } from './click-house-log-query-types';
1817
import { DEFAULT_DATASOURCE } from '../constants';
18+
import { ClickHouseLogQuerySpec } from './click-house-log-query-types';
1919
import { LogQueryPlugin } from './log-query-plugin-interface';
2020

2121
function flattenObject(
22-
obj: Record<string, any>,
22+
obj: Record<string, unknown>,
2323
parentKey = '',
24-
result: Record<string, any> = {}
25-
): Record<string, any> {
24+
result: Record<string, unknown> = {}
25+
): Record<string, unknown> {
2626
for (const [key, value] of Object.entries(obj)) {
2727
const newKey = parentKey ? `${parentKey}.${key}` : key;
2828
if (value && typeof value === 'object' && !Array.isArray(value)) {
29-
flattenObject(value, newKey, result);
29+
flattenObject(value as Record<string, unknown>, newKey, result);
3030
} else {
3131
result[newKey] = value;
3232
}
@@ -37,13 +37,13 @@ function flattenObject(
3737

3838
function convertStreamsToLogs(streams: LogEntry[]): LogData {
3939
const entries: LogEntry[] = streams.map((entry) => {
40-
const flattened = flattenObject(entry);
40+
const flattened = flattenObject(entry as unknown as Record<string, unknown>);
4141

42-
if (!flattened.Timestamp && flattened.log_time) {
43-
flattened.Timestamp = flattened.log_time;
42+
if (!flattened['Timestamp'] && flattened['log_time']) {
43+
flattened['Timestamp'] = flattened['log_time'];
4444
}
4545

46-
const sortedEntry: Record<string, any> = {};
46+
const sortedEntry: Record<string, unknown> = {};
4747
Object.keys(flattened)
4848
.sort((a, b) => a.localeCompare(b))
4949
.forEach((key) => {
@@ -56,8 +56,8 @@ function convertStreamsToLogs(streams: LogEntry[]): LogData {
5656
.join(' ');
5757

5858
return {
59-
timestamp: sortedEntry?.Timestamp,
60-
labels: sortedEntry,
59+
timestamp: sortedEntry?.['Timestamp'] as unknown as number,
60+
labels: sortedEntry as Record<string, string>,
6161
line,
6262
} as LogEntry;
6363
});
@@ -92,7 +92,7 @@ export const getClickHouseLogData: LogQueryPlugin<ClickHouseLogQuerySpec>['getLo
9292

9393
return {
9494
timeRange: { start, end },
95-
logs: convertStreamsToLogs(response.data),
95+
logs: convertStreamsToLogs(response.data as LogEntry[]),
9696
metadata: {
9797
executedQueryString: query,
9898
},

clickhouse/src/queries/click-house-time-series-query/click-house-query-types.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const getDatasource: jest.Mock = jest.fn((): DatasourceSpec<ClickHouseDatasource
5454
});
5555

5656
const createStubContext = (): TimeSeriesQueryContext => {
57-
const stubTimeSeriesContext: TimeSeriesQueryContext = {
57+
const stubTimeSeriesContext: Partial<TimeSeriesQueryContext> = {
5858
datasourceStore: {
5959
getDatasource: getDatasource,
6060
getDatasourceClient: getDatasourceClient,
@@ -70,7 +70,7 @@ const createStubContext = (): TimeSeriesQueryContext => {
7070
},
7171
variableState: {},
7272
};
73-
return stubTimeSeriesContext;
73+
return stubTimeSeriesContext as TimeSeriesQueryContext;
7474
};
7575

7676
describe('ClickHouseTimeSeriesQuery', () => {

clickhouse/src/queries/click-house-time-series-query/click-house-query-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ export interface ClickHouseTimeSeriesQuerySpec {
2121
// TODO: import this type from your datasource or an existing datasource plugin
2222
export type DatasourceQueryResponse = {
2323
status: string;
24-
data: any;
24+
data: unknown;
2525
warnings?: string[];
2626
};

clickhouse/src/queries/click-house-time-series-query/get-click-house-data.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@
1313

1414
import { TimeSeries } from '@perses-dev/core';
1515
import { TimeSeriesQueryPlugin, replaceVariables } from '@perses-dev/plugin-system';
16-
import { ClickHouseTimeSeriesQuerySpec, DatasourceQueryResponse } from './click-house-query-types';
1716
import { DEFAULT_DATASOURCE } from '../constants';
1817
import { TimeSeriesEntry } from '../../model/click-house-data-types';
1918
import { ClickHouseClient, ClickHouseQueryResponse } from '../../model/click-house-client';
19+
import { ClickHouseTimeSeriesQuerySpec, DatasourceQueryResponse } from './click-house-query-types';
2020

2121
function buildTimeSeries(response?: DatasourceQueryResponse): TimeSeries[] {
22-
if (!response || !response.data || response.data.length === 0) {
22+
const data = response?.data as TimeSeriesEntry[];
23+
if (!response || !data || data.length === 0) {
2324
return [];
2425
}
2526

26-
const values: Array<[number, number]> = response.data.map((row: TimeSeriesEntry) => {
27+
const values: Array<[number, number]> = data.map((row: TimeSeriesEntry) => {
2728
const timestamp = new Date(row.time).getTime();
2829
const value = Number(row.log_count);
2930
return [timestamp, value];

clickhouse/src/queries/query-editor-model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ type ClickHouseQuerySpec = {
2828
* changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview
2929
* every time the user types.
3030
*/
31-
export function useQueryState<T extends ClickHouseQuerySpec>(props: OptionsEditorProps<T>): {
31+
export function useQueryState<T extends ClickHouseQuerySpec>(
32+
props: OptionsEditorProps<T>
33+
): {
3234
query: string;
3335
handleQueryChange: (e: string) => void;
3436
handleQueryBlur: () => void;

0 commit comments

Comments
 (0)