Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/grafana/grafana
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Clifford committed Dec 13, 2023
1 parent 9f4a72c commit 7ac2fd7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 74 deletions.
69 changes: 0 additions & 69 deletions pkg/tsdb/influxdb/influxql/influxql.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,75 +68,6 @@ func Query(ctx context.Context, tracer trace.Tracer, dsInfo *models.DatasourceIn
return response, nil
}

func createNewExemplarQuery(rawQuery string) (string, error) {
fromIndex := strings.Index(rawQuery, "FROM")
if fromIndex == -1 {
return "", errors.New("keyword 'FROM' not found in query")
}

prefix := "SELECT * FROM "
suffix := rawQuery[fromIndex+len("FROM")+1:]

endOfTableName := strings.Index(suffix, " ")
if endOfTableName == -1 {
return "", errors.New("space not found after table name in query")
}

tableName := suffix[:endOfTableName]
modifiedTableName := strings.TrimSuffix(tableName, "\"") + "_exemplar\""
remainder := suffix[endOfTableName:]

return prefix + modifiedTableName + remainder, nil
}

// QueryExemplarData function returns a slice of models.Exemplar
func QueryExemplarData(ctx context.Context, dsInfo *models.DatasourceInfo, req *backend.QueryDataRequest) ([]models.Exemplar, error) {
logger := glog.FromContext(ctx)
var exemplars []models.Exemplar // Declare a slice of models.Exemplar

for _, reqQuery := range req.Queries {
query, err := models.QueryParse(reqQuery)
if err != nil {
return nil, err
}

rawQuery, err := query.Build(req)
if err != nil {
return nil, err
}

modifiedQuery, err := createNewExemplarQuery(rawQuery)
if err != nil {
return nil, err
}

logger.Info("Influxdb exemplar query", "raw exemplar query", modifiedQuery)

query.RefID = reqQuery.RefID
query.RawQuery = modifiedQuery

if setting.Env == setting.Dev {
logger.Debug("Influxdb query", "raw query", rawQuery)
}

request, err := createRequest(ctx, logger, dsInfo, rawQuery, query.Policy)
if err != nil {
return nil, err
}

resp, err := execute(dsInfo, logger, query, request)
if err != nil {
return nil, err
}

// Transform the frames to exemplars and append them to the exemplars slice
exemplars = append(exemplars, transformToExemplars(resp.Frames)...)

}
logger.Info("exemplars", "exemplars", exemplars)
return exemplars, nil
}

func createRequest(ctx context.Context, logger log.Logger, dsInfo *models.DatasourceInfo, queryStr string, retentionPolicy string) (*http.Request, error) {
u, err := url.Parse(dsInfo.URL)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions public/app/features/explore/TraceView/createSpanLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,17 +569,17 @@ function getQueryForInfluxSQL(
}
console.log('get query for influx sql');

let query = "SELECT * FROM logs WHERE time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time DESC";
let query = "SELECT time, attributes, \"event.name\" FROM logs WHERE time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time";

if (filterByTraceID && span.traceID && filterBySpanID && span.spanID) {
query =
"SELECT * FROM logs WHERE \"trace_id\" LIKE '%${__span.traceId}' AND \"span_id\" LIKE '%${__span.spanId}' AND time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time DESC";
"SELECT time, attributes, \"event.name\" FROM logs WHERE \"trace_id\" LIKE '%${__span.traceId}' AND \"span_id\" LIKE '%${__span.spanId}' AND time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time";
} else if (filterByTraceID && span.traceID) {
query =
"SELECT * FROM logs WHERE \"trace_id\" LIKE '%${__span.traceId}' AND time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time DESC";
"SELECT time, attributes, \"event.name\" FROM logs WHERE \"trace_id\" LIKE '%${__span.traceId}' AND time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time";
} else if (filterBySpanID && span.spanID) {
query =
"SELECT * FROM logs WHERE \"span_id\" LIKE '%${__span.traceId}' AND time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time DESC";
"SELECT time, attributes, \"event.name\" FROM logs WHERE \"span_id\" LIKE '%${__span.traceId}' AND time >= '${__from:date}' AND time <= '${__to:date}' ORDER BY time";
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
onUpdateDatasourceJsonDataOptionSelect,
onUpdateDatasourceOption,
onUpdateDatasourceSecureJsonDataOption,
updateDatasourcePluginJsonDataOption,
SelectableValue,
updateDatasourcePluginResetOption,
} from '@grafana/data';
Expand Down

0 comments on commit 7ac2fd7

Please sign in to comment.