Skip to content

Commit

Permalink
[querier] Modify metric not found error
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoren1 authored and SongZhen0704 committed Oct 19, 2023
1 parent 5a1ad5b commit ddb42c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package service
package common

import (
"encoding/json"
Expand Down
18 changes: 9 additions & 9 deletions server/querier/engine/clickhouse/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ func GetPrometheusFilter(promTag, table, op, value string) (string, error) {
}
labelNameID, ok := Prometheus.LabelNameToID[nameNoPreffix]
if !ok {
if value == "" {
filter = "1=1"
if value == "''" {
filter = fmt.Sprintf("1%s1", op)
} else {
filter = "1!=1"
}
Expand All @@ -821,8 +821,8 @@ func GetPrometheusFilter(promTag, table, op, value string) (string, error) {
for _, appLabel := range appLabels {
if appLabel.AppLabelName == nameNoPreffix {
isAppLabel = true
if value == "" {
filter = fmt.Sprintf("app_label_value_id_%d = 0", appLabel.appLabelColumnIndex)
if value == "''" {
filter = fmt.Sprintf("app_label_value_id_%d %s 0", appLabel.appLabelColumnIndex, op)
return filter, nil
}
if strings.Contains(op, "match") {
Expand Down Expand Up @@ -852,12 +852,12 @@ func GetRemoteReadFilter(promTag, table, op, value, originFilter string, e *CHEn
metricID, ok := Prometheus.MetricNameToID[table]
if !ok {
errorMessage := fmt.Sprintf("%s not found", table)
return filter, errors.New(errorMessage)
return filter, common.NewError(common.RESOURCE_NOT_FOUND, errorMessage)
}
labelNameID, ok := Prometheus.LabelNameToID[nameNoPreffix]
if !ok {
if value == "" {
filter = "1=1"
if value == "''" {
filter = fmt.Sprintf("1%s1", op)
} else {
filter = "1!=1"
}
Expand All @@ -879,8 +879,8 @@ func GetRemoteReadFilter(promTag, table, op, value, originFilter string, e *CHEn
return filter, nil
}
}
if value == "" {
filter = fmt.Sprintf("app_label_value_id_%d = 0", appLabel.appLabelColumnIndex)
if value == "''" {
filter = fmt.Sprintf("app_label_value_id_%d %s 0", appLabel.appLabelColumnIndex, op)
entryValue := common.EntryValue{Time: time.Now(), Filter: filter}
prometheusSubqueryCache.PrometheusSubqueryCache.Add(originFilter, entryValue)
return filter, nil
Expand Down
3 changes: 1 addition & 2 deletions server/querier/router/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/gin-gonic/gin"

"github.com/deepflowio/deepflow/server/querier/common"
"github.com/deepflowio/deepflow/server/querier/service"
)

type Response struct {
Expand Down Expand Up @@ -68,7 +67,7 @@ func InternalErrorResponse(c *gin.Context, data interface{}, debug interface{},
func JsonResponse(c *gin.Context, data interface{}, debug interface{}, err error) {
if err != nil {
switch t := err.(type) {
case *service.ServiceError:
case *common.ServiceError:
switch t.Status {
case common.RESOURCE_NOT_FOUND, common.INVALID_POST_DATA, common.RESOURCE_NUM_EXCEEDED,
common.SELECTED_RESOURCES_NUM_EXCEEDED:
Expand Down

0 comments on commit ddb42c9

Please sign in to comment.