refactor: doris search sql (#2778)
* doris:support search sql with macro * Update doris.go --------- Co-authored-by: Yening Qin <710leo@gmail.com>
This commit is contained in:
parent
fbf1d68b84
commit
a5a43df44f
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/ccfos/nightingale/v6/datasource"
|
"github.com/ccfos/nightingale/v6/datasource"
|
||||||
"github.com/ccfos/nightingale/v6/dskit/doris"
|
"github.com/ccfos/nightingale/v6/dskit/doris"
|
||||||
"github.com/ccfos/nightingale/v6/dskit/types"
|
"github.com/ccfos/nightingale/v6/dskit/types"
|
||||||
|
"github.com/ccfos/nightingale/v6/pkg/macros"
|
||||||
"github.com/ccfos/nightingale/v6/models"
|
"github.com/ccfos/nightingale/v6/models"
|
||||||
|
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
|
@ -32,6 +33,11 @@ type QueryParam struct {
|
||||||
Table string `json:"table" mapstructure:"table"`
|
Table string `json:"table" mapstructure:"table"`
|
||||||
SQL string `json:"sql" mapstructure:"sql"`
|
SQL string `json:"sql" mapstructure:"sql"`
|
||||||
Keys datasource.Keys `json:"keys" mapstructure:"keys"`
|
Keys datasource.Keys `json:"keys" mapstructure:"keys"`
|
||||||
|
Limit int `json:"limit" mapstructure:"limit"`
|
||||||
|
From int64 `json:"from" mapstructure:"from"`
|
||||||
|
To int64 `json:"to" mapstructure:"to"`
|
||||||
|
TimeField string `json:"time_field" mapstructure:"time_field"`
|
||||||
|
TimeFormat string `json:"time_format" mapstructure:"time_format"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Doris) InitClient() error {
|
func (d *Doris) InitClient() error {
|
||||||
|
@ -66,7 +72,7 @@ func (d *Doris) Validate(ctx context.Context) error {
|
||||||
func (d *Doris) Equal(p datasource.Datasource) bool {
|
func (d *Doris) Equal(p datasource.Datasource) bool {
|
||||||
newest, ok := p.(*Doris)
|
newest, ok := p.(*Doris)
|
||||||
if !ok {
|
if !ok {
|
||||||
logger.Errorf("unexpected plugin type, expected is ck")
|
logger.Errorf("unexpected plugin type, expected is doris")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,6 +180,14 @@ func (d *Doris) QueryLog(ctx context.Context, query interface{}) ([]interface{},
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(dorisQueryParam.SQL, "$__") {
|
||||||
|
var err error
|
||||||
|
dorisQueryParam.SQL, err = macros.Macro(dorisQueryParam.SQL, dorisQueryParam.From, dorisQueryParam.To)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
items, err := d.QueryLogs(ctx, &doris.QueryParam{
|
items, err := d.QueryLogs(ctx, &doris.QueryParam{
|
||||||
Database: dorisQueryParam.Database,
|
Database: dorisQueryParam.Database,
|
||||||
Sql: dorisQueryParam.SQL,
|
Sql: dorisQueryParam.SQL,
|
||||||
|
@ -187,7 +201,7 @@ func (d *Doris) QueryLog(ctx context.Context, query interface{}) ([]interface{},
|
||||||
logs = append(logs, items[i])
|
logs = append(logs, items[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
return logs, 0, nil
|
return logs, int64(len(logs)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Doris) DescribeTable(ctx context.Context, query interface{}) ([]*types.ColumnProperty, error) {
|
func (d *Doris) DescribeTable(ctx context.Context, query interface{}) ([]*types.ColumnProperty, error) {
|
||||||
|
|
|
@ -20,8 +20,8 @@ import (
|
||||||
|
|
||||||
// Doris struct to hold connection details and the connection object
|
// Doris struct to hold connection details and the connection object
|
||||||
type Doris struct {
|
type Doris struct {
|
||||||
Addr string `json:"doris.addr" mapstructure:"doris.addr"` // be node
|
Addr string `json:"doris.addr" mapstructure:"doris.addr"` // fe mysql endpoint
|
||||||
FeAddr string `json:"doris.fe_addr" mapstructure:"doris.fe_addr"` // fe node
|
FeAddr string `json:"doris.fe_addr" mapstructure:"doris.fe_addr"` // fe http endpoint
|
||||||
User string `json:"doris.user" mapstructure:"doris.user"` //
|
User string `json:"doris.user" mapstructure:"doris.user"` //
|
||||||
Password string `json:"doris.password" mapstructure:"doris.password"` //
|
Password string `json:"doris.password" mapstructure:"doris.password"` //
|
||||||
Timeout int `json:"doris.timeout" mapstructure:"doris.timeout"`
|
Timeout int `json:"doris.timeout" mapstructure:"doris.timeout"`
|
||||||
|
|
Loading…
Reference in New Issue