Skip to content

Commit

Permalink
Use a slice of strings for the labels instead of a map[string]struct{}
Browse files Browse the repository at this point in the history
There seems to be no value having a struct because we store an empty
struct so what gives?
This makes sure that whatever is the order in the query is what we have
for the ordering of labels
  • Loading branch information
mpatou committed Nov 7, 2023
1 parent 66d0ee0 commit 22ad61c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Changelog

## 0.2.1

### Build
* Fixed issues with ordering of values, we now respect the order specified in the query

## 0.2.0

### Build
* Update go-rockset-client SDK
* Update grafana plugin SDK
* Add e2e tests
* Move build from CircleCI to Github Actions
* Move build from CircleCI to Github Actions
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rockset-backend-datasource",
"version": "0.2.0",
"version": "0.2.1",
"description": "Rockset backend datasource",
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
Expand Down
18 changes: 11 additions & 7 deletions pkg/rockset.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ func (d *Datasource) query(ctx context.Context, rs *rockset.RockClient, query ba
log.DefaultLogger.Error(errMsg)
return backend.ErrDataResponse(backend.StatusUnknown, errMsg)
}
log.DefaultLogger.Debug("labels", "values", labelValues)

for label := range labelValues {
log.DefaultLogger.Debug("labels", "values", labelValues)
for _, label := range labelValues {
for i, c := range qr.ColumnFields {
// skip the time field and the label column
if c.Name == qm.QueryTimeField || c.Name == qm.QueryLabelColumn {
Expand Down Expand Up @@ -186,13 +186,13 @@ func (d *Datasource) query(ctx context.Context, rs *rockset.RockClient, query ba
}

// extract the set of label values from the label column
func generateLabelValues(labelColumn string, results []map[string]interface{}) (map[string]struct{}, error) {
labels := make(map[string]struct{})
func generateLabelValues(labelColumn string, results []map[string]interface{}) ([]string, error) {
labels := make([]string, 0)
seen := make(map[string]struct{})

// if there isn't any label column specified, add an empty string so we can use it as a special case
if labelColumn == "" {
labels[""] = struct{}{}
return labels, nil
return []string{""}, nil
}

for _, m := range results {
Expand All @@ -206,7 +206,11 @@ func generateLabelValues(labelColumn string, results []map[string]interface{}) (
log.DefaultLogger.Error("could not cast label column value to string", "label", label)
continue
}
labels[l] = struct{}{}
_, found = seen[l]
if !found {
labels = append(labels, l)
seen[l] = struct{}{}
}
}

if len(labels) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions src/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
}
],
"screenshots": [],
"version": "0.2.0",
"updated": "2023-01-13"
"version": "0.2.1",
"updated": "2023-11-05"
},
"dependencies": {
"grafanaDependency": "^9.2.5",
Expand Down

0 comments on commit 22ad61c

Please sign in to comment.