Skip to content

Commit

Permalink
feat: add query filters for dependency #314 #290
Browse files Browse the repository at this point in the history
  • Loading branch information
sunface committed Oct 27, 2023
1 parent d292693 commit 682e8f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
29 changes: 27 additions & 2 deletions query/internal/plugins/builtin/datav/api/serviceGraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package api
import (
"fmt"
"strconv"
"strings"

ch "github.com/ClickHouse/clickhouse-go/v2"
datavmodels "github.com/DataObserve/datav/query/internal/plugins/builtin/datav/models"
datavutils "github.com/DataObserve/datav/query/internal/plugins/builtin/datav/utils"
pluginUtils "github.com/DataObserve/datav/query/internal/plugins/utils"
"github.com/DataObserve/datav/query/pkg/config"
"github.com/DataObserve/datav/query/pkg/models"
Expand All @@ -16,6 +18,29 @@ func GetDependencyGraph(c *gin.Context, ds *models.Datasource, conn ch.Conn, par
start, _ := strconv.ParseInt(c.Query("start"), 10, 64)
end, _ := strconv.ParseInt(c.Query("end"), 10, 64)

source := datavutils.GetValueListFromParams(params, "source")
target := datavutils.GetValueListFromParams(params, "target")
environment := datavutils.GetValueListFromParams(params, "environment")
cluster := datavutils.GetValueListFromParams(params, "cluster")
namespace := datavutils.GetValueListFromParams(params, "namespace")

var domainQuery string
if source != nil {
domainQuery += fmt.Sprintf(" AND src in ('%s')", strings.Join(source, "','"))
}
if target != nil {
domainQuery += fmt.Sprintf(" AND dest in ('%s')", strings.Join(target, "','"))
}
if environment != nil {
domainQuery += fmt.Sprintf(" AND environment in ('%s')", strings.Join(environment, "','"))
}
if cluster != nil {
domainQuery += fmt.Sprintf(" AND cluster in ('%s')", strings.Join(cluster, "','"))
}
if namespace != nil {
domainQuery += fmt.Sprintf(" AND namespace in ('%s')", strings.Join(namespace, "','"))
}

query := fmt.Sprintf(`WITH
quantilesMergeState(0.5, 0.75, 0.9, 0.95, 0.99)(duration_quantiles_state) AS duration_quantiles_state,
finalizeAggregation(duration_quantiles_state) AS result
Expand All @@ -30,8 +55,8 @@ SELECT
sum(total_count) as calls,
sum(error_count) as errors
FROM %s.%s
WHERE toUInt64(toDateTime(timestamp)) >= ? AND toUInt64(toDateTime(timestamp)) <= ? GROUP BY src, dest`,
config.Data.Observability.DefaultTraceDB, datavmodels.DefaultDependencyGraphTable)
WHERE toUInt64(toDateTime(timestamp)) >= ? AND toUInt64(toDateTime(timestamp)) <= ? %s GROUP BY src, dest`,
config.Data.Observability.DefaultTraceDB, datavmodels.DefaultDependencyGraphTable, domainQuery)

rows, err := conn.Query(c.Request.Context(), query, start, end)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ const apiList = [{
paramsDesc: [
["namespace", "such as dev, test, prod etc", "", ""],
["service", "filter by service names, e.g datav|driver", "", ""],
["host", "filter by host names, e.g datav-1", "", ""],
["severity", "logs severity, e.g error,info", "", "debug | info | warn | error | fatal"],
["host", "filter by host names, e.g datav-1|datav-2", "", ""],
["severity", "logs severity, e.g error|info", "", "debug| info | warn | error | fatal"],
["perPage", "page size of logs when query from datasource", "100", "any number"],
["orderByTimestamp", "order by timestamp", "desc", "asc | desc"],
],
Expand All @@ -175,8 +175,11 @@ const apiList = [{
params: `{
}`,
paramsDesc: [
["namespace", "such as dev, test, prod etc", "", ""],
["service", "filter by service names, e.g datav|driver", "", ""],
["environment", "such as dev, test, prod etc", "", ""],
["cluster", "e.g k8s cluster name", "", ""],
["namespace", "e.g k8s namespace name", "", ""],
["source", "service name list, e.g datav|mysql","",""],
["target", "service name list, e.g datav|mysql","",""]
],
format: DataFormat.NodeGraph
}
Expand Down

0 comments on commit 682e8f5

Please sign in to comment.