Skip to content

Commit befc1f8

Browse files
committed
Merge branch 'main' of github.com:data-observe/datav into panel-edit
2 parents 5c220b8 + 78cb184 commit befc1f8

File tree

14 files changed

+158
-106
lines changed

14 files changed

+158
-106
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ It can help users quickly create online observability scenarios such as monitori
3030

3131
## Roadmap to V1.0
3232

33-
Till now, we have implemented the UI part of Datav, which can aslo be used as an alternative to Grafana.
33+
Till now, we have implemented the UI part of Datav, which can also be used as an alternative to Grafana.
3434

3535
We are now still working on the observability part, and it will be released in [V1.0](https://github.com/data-observe/datav/milestone/7).
3636

@@ -48,7 +48,7 @@ We are now still working on the observability part, and it will be released in [
4848

4949
6. **Modern UI design**: supports large data screens, and is perfectly compatible with mobile devices.
5050

51-
7. **Programmability**: powerful programmability and developer-friendly for customizations, e.g Datav agent support use webassembly to develop your own plugins and data process pipleines.
51+
7. **Programmability**: powerful programmability and developer-friendly for customizations, e.g Datav agent support use webassembly to develop your own plugins and data process pipelines.
5252

5353
8. **Community**: comes with a permissive open-source license, extensive documentation, and rapid community support response.
5454

query/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/golang/snappy v0.0.4
1313
github.com/gosimple/slug v1.9.0
1414
github.com/inconshreveable/log15 v0.0.0-20201112154412-8562bdadbbac
15+
github.com/lib/pq v1.10.9
1516
github.com/lithammer/shortuuid/v3 v3.0.5
1617
github.com/mattn/go-sqlite3 v1.14.17
1718
github.com/spf13/cobra v1.6.1
@@ -58,7 +59,6 @@ require (
5859
github.com/klauspost/compress v1.16.7 // indirect
5960
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
6061
github.com/leodido/go-urn v1.2.4 // indirect
61-
github.com/lib/pq v1.10.9 // indirect
6262
github.com/mattn/go-colorable v0.1.13 // indirect
6363
github.com/mattn/go-isatty v0.0.19 // indirect
6464
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package builtin
22

33
import (
4+
_ "github.com/DataObserve/datav/query/internal/plugins/builtin/datav"
45
_ "github.com/DataObserve/datav/query/internal/plugins/builtin/mysql"
56
_ "github.com/DataObserve/datav/query/internal/plugins/builtin/postgresql"
67
)

query/internal/plugins/external/clickhouse/clickhouse.go

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package clickhouse
22

33
import (
4-
"reflect"
54
"sync"
6-
"time"
75

86
ch "github.com/ClickHouse/clickhouse-go/v2"
97
pluginUtils "github.com/DataObserve/datav/query/internal/plugins/utils"
@@ -43,46 +41,14 @@ func (p *ClickHousePlugin) Query(c *gin.Context, ds *models.Datasource) models.P
4341
}
4442
defer rows.Close()
4543

46-
columns := rows.Columns()
47-
columnTypes := rows.ColumnTypes()
48-
types := make(map[string]string)
49-
data := make([][]interface{}, 0)
50-
for rows.Next() {
51-
v := make([]interface{}, len(columns))
52-
for i := range v {
53-
t := columnTypes[i].ScanType()
54-
v[i] = reflect.New(t).Interface()
44+
colorlog.RootLogger.Info("Query from clickhouse", "query", query)
5545

56-
tp := t.String()
57-
if tp == "time.Time" {
58-
types[columns[i]] = "time"
59-
}
60-
}
61-
62-
err = rows.Scan(v...)
63-
if err != nil {
64-
colorlog.RootLogger.Info("Error scan clickhouse :", "error", err, "ds_id", ds.Id)
65-
continue
66-
}
67-
68-
for i, v0 := range v {
69-
v1, ok := v0.(*time.Time)
70-
if ok {
71-
v[i] = v1.Unix()
72-
}
73-
}
74-
75-
data = append(data, v)
46+
res, err := pluginUtils.ConvertDbRowsToPluginData(rows)
47+
if err != nil {
48+
return models.GenPluginResult(models.PluginStatusError, err.Error(), nil)
7649
}
7750

78-
return models.PluginResult{
79-
Status: models.PluginStatusSuccess,
80-
Error: "",
81-
Data: models.PluginResultData{
82-
Columns: columns,
83-
Data: data,
84-
ColumnTypes: types,
85-
}}
51+
return models.GenPluginResult(models.PluginStatusSuccess, "", res)
8652
}
8753

8854
func (p *ClickHousePlugin) TestDatasource(c *gin.Context) models.PluginResult {

query/internal/plugins/utils/clickhouse.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package pluginUtils
33
import (
44
"context"
55
"net"
6+
"reflect"
67
"strings"
78
"time"
89

10+
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
11+
912
ch "github.com/ClickHouse/clickhouse-go/v2"
1013
"github.com/DataObserve/datav/query/pkg/models"
1114
"github.com/gin-gonic/gin"
@@ -78,3 +81,42 @@ func TestClickhouseDatasource(c *gin.Context) models.PluginResult {
7881

7982
return models.GenPluginResult(models.PluginStatusSuccess, "", nil)
8083
}
84+
85+
func ConvertDbRowsToPluginData(rows driver.Rows) (*models.PluginResultData, error) {
86+
columns := rows.Columns()
87+
columnTypes := rows.ColumnTypes()
88+
types := make(map[string]string)
89+
data := make([][]interface{}, 0)
90+
for rows.Next() {
91+
v := make([]interface{}, len(columns))
92+
for i := range v {
93+
t := columnTypes[i].ScanType()
94+
v[i] = reflect.New(t).Interface()
95+
96+
tp := t.String()
97+
if tp == "time.Time" {
98+
types[columns[i]] = "time"
99+
}
100+
}
101+
102+
err := rows.Scan(v...)
103+
if err != nil {
104+
return nil, err
105+
}
106+
107+
for i, v0 := range v {
108+
v1, ok := v0.(*time.Time)
109+
if ok {
110+
v[i] = v1.Unix()
111+
}
112+
}
113+
114+
data = append(data, v)
115+
}
116+
117+
return &models.PluginResultData{
118+
Columns: columns,
119+
Data: data,
120+
ColumnTypes: types,
121+
}, nil
122+
}

query/pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type Config struct {
9999
DisablePanels []string `yaml:"disable_panels"`
100100
DisableDatasources []string `yaml:"disable_datasources"`
101101
}
102-
Observability
102+
Observability Observability
103103
}
104104

105105
type Observability struct {

query/pkg/models/plugin.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package models
22

33
import (
4-
"reflect"
5-
"time"
6-
7-
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
84
"github.com/gin-gonic/gin"
95
)
106

@@ -54,42 +50,3 @@ func GenPluginResult(status, err string, data interface{}) PluginResult {
5450
Data: data,
5551
}
5652
}
57-
58-
func ConvertDbRowsToPluginData(rows driver.Rows) (*PluginResultData, error) {
59-
columns := rows.Columns()
60-
columnTypes := rows.ColumnTypes()
61-
types := make(map[string]string)
62-
data := make([][]interface{}, 0)
63-
for rows.Next() {
64-
v := make([]interface{}, len(columns))
65-
for i := range v {
66-
t := columnTypes[i].ScanType()
67-
v[i] = reflect.New(t).Interface()
68-
69-
tp := t.String()
70-
if tp == "time.Time" {
71-
types[columns[i]] = "time"
72-
}
73-
}
74-
75-
err := rows.Scan(v...)
76-
if err != nil {
77-
return nil, err
78-
}
79-
80-
for i, v0 := range v {
81-
v1, ok := v0.(*time.Time)
82-
if ok {
83-
v[i] = v1.Unix()
84-
}
85-
}
86-
87-
data = append(data, v)
88-
}
89-
90-
return &PluginResultData{
91-
Columns: columns,
92-
Data: data,
93-
ColumnTypes: types,
94-
}, nil
95-
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2023 Datav.io Team
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
import { Box, Input, Popover, PopoverBody, PopoverContent, PopoverTrigger, useDisclosure } from "@chakra-ui/react"
15+
import React from "react"
16+
17+
const InputWithTips = ({ value, onChange, onConfirm=null, width, children, placeholder = "Enter....", variant = "flushed", size = "md" }) => {
18+
const { isOpen, onToggle, onClose } = useDisclosure()
19+
return (<>
20+
<Input value={value} onChange={e => onChange(e.currentTarget.value)} width={width} size={size} variant={variant} placeholder={placeholder} onFocus={onToggle} onBlur={onToggle} onKeyDown={e => {
21+
if (onConfirm && e.key === 'Enter') {
22+
onConfirm()
23+
}
24+
}} />
25+
<Popover
26+
returnFocusOnClose={false}
27+
isOpen={isOpen}
28+
onClose={onClose}
29+
placement='bottom'
30+
closeOnBlur={false}
31+
autoFocus={false}
32+
>
33+
<PopoverTrigger>
34+
<Box position="absolute" top="40px"></Box>
35+
</PopoverTrigger>
36+
<PopoverContent width={width}>
37+
<PopoverBody>
38+
{children}
39+
</PopoverBody>
40+
</PopoverContent>
41+
</Popover>
42+
</>)
43+
}
44+
45+
export default InputWithTips

ui/src/types/format.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum DataFormat {
22
TimeSeries = "timeseries",
33
Table = "table",
4+
Logs = "logs"
45
}

ui/src/views/dashboard/plugins/built-in/datasource/datav/DatasourceEditor.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Datasource } from "types/datasource"
1414
import React from "react";
1515
import FormItem from "components/form/Item";
1616
import { Input, Text } from "@chakra-ui/react";
17+
import { isEmpty } from "utils/validate";
1718
interface Props {
1819
datasource: Datasource
1920
onChange: any
@@ -27,7 +28,7 @@ const DatasourceEditor = ({ datasource, onChange }: Props) => {
2728
return
2829
}
2930

30-
if (!datasource.data) {
31+
if (isEmpty(datasource.data)) {
3132
onChange(d => { d.data = defaultData})
3233
return
3334
}

0 commit comments

Comments
 (0)