Skip to content

Commit

Permalink
fix: flux error properly read by cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
lesam committed Aug 31, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 1755b8f commit 82a4039
Showing 5 changed files with 39 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
- [#22283](https://github.com/influxdata/influxdb/pull/22283): fix: require database authorization to see continuous queries
- [#22273](https://github.com/influxdata/influxdb/pull/22273): fix: return correct count of ErrNotExecuted
- [#22338](https://github.com/influxdata/influxdb/pull/22338): fix: TSI logfile race
- [#22348](https://github.com/influxdata/influxdb/pull/22348): fix: flux error properly read by cloud

v1.9.2 [unreleased]
- [#21631](https://github.com/influxdata/influxdb/pull/21631): fix: group by returns multiple results per group in some circumstances
2 changes: 1 addition & 1 deletion query/executor_test.go
Original file line number Diff line number Diff line change
@@ -541,7 +541,7 @@ func checkNotExecutedResults(t *testing.T, results <-chan *query.Result, testNam
}
}
if notExecutedIndex != lenQuery {
t.Fatalf("wrong number of results from %s with fail index of %d - got: %d, expected: %d", testName, failIndex, notExecutedIndex - (1 + failIndex), lenQuery-(1+failIndex))
t.Fatalf("wrong number of results from %s with fail index of %d - got: %d, expected: %d", testName, failIndex, notExecutedIndex-(1+failIndex), lenQuery-(1+failIndex))
}
}

9 changes: 6 additions & 3 deletions services/httpd/handler.go
Original file line number Diff line number Diff line change
@@ -298,9 +298,7 @@ func NewHandler(c Config) *Handler {
}

if !c.FluxEnabled {
fluxRoute.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Flux query service disabled. Verify flux-enabled=true in the [http] section of the InfluxDB config.", http.StatusForbidden)
}
fluxRoute.HandlerFunc = h.serveFluxQueryDisabled
} else {
fluxRoute.HandlerFunc = h.serveFluxQuery
}
@@ -1439,6 +1437,11 @@ func (h *Handler) serveFluxQuery(w http.ResponseWriter, r *http.Request, user me
}
}

func (h *Handler) serveFluxQueryDisabled(w http.ResponseWriter, r *http.Request, user meta.User) {
h.Logger.Warn("Received flux query but flux-enabled=false in [http] section of InfluxDB config")
h.httpError(w, "Flux query service disabled. Verify flux-enabled=true in the [http] section of the InfluxDB config.", http.StatusForbidden)
}

func (h *Handler) logFluxQuery(n int64, stats flux.Statistics, compiler flux.Compiler, err error) {
var q string
switch c := compiler.(type) {
25 changes: 25 additions & 0 deletions tests/server_test.go
Original file line number Diff line number Diff line change
@@ -10237,6 +10237,31 @@ func TestFluxRegressionEndToEnd(t *testing.T) {
}
}

func TestFluxDisabled(t *testing.T) {
config := NewConfig()
s := OpenServer(config)
defer s.Close()

s.CreateDatabase(t.Name())
defer s.DropDatabase(t.Name())
u, err := url.Parse(s.URL())
assert.NoError(t, err)
u.Path = "/api/v2/query"

var query fluxClient.QueryRequest
query.Query = "buckets()"
query.Type = "flux"
query.Dialect.Annotations = csv.DefaultDialect().Annotations
body, err := json.Marshal(query)
require.NoError(t, err)
resp, err := http.Post(u.String(), "application/json", bytes.NewBuffer(body))
require.NoError(t, err)
assert.Equal(t, 403, resp.StatusCode)
body, err = ioutil.ReadAll(resp.Body)
require.NoError(t, err)
assert.Equal(t, `{"error":"Flux query service disabled. Verify flux-enabled=true in the [http] section of the InfluxDB config."}`+"\n", string(body))
}

var FluxEndToEndSkipList = map[string]map[string]string{
"universe": {
// TODO(adam) determine the reason for these test failures.
12 changes: 6 additions & 6 deletions tsdb/engine/tsm1/engine_test.go
Original file line number Diff line number Diff line change
@@ -2873,12 +2873,12 @@ func MustParsePointString(buf string) models.Point { return MustParsePointsStrin
type mockPlanner struct{}

func (m *mockPlanner) Plan(lastWrite time.Time) ([]tsm1.CompactionGroup, int64) { return nil, 0 }
func (m *mockPlanner) PlanLevel(level int) ([]tsm1.CompactionGroup, int64) { return nil, 0 }
func (m *mockPlanner) PlanOptimize() ([]tsm1.CompactionGroup, int64) { return nil, 0 }
func (m *mockPlanner) Release(groups []tsm1.CompactionGroup) {}
func (m *mockPlanner) FullyCompacted() (bool, string) { return false, "not compacted" }
func (m *mockPlanner) ForceFull() {}
func (m *mockPlanner) SetFileStore(fs *tsm1.FileStore) {}
func (m *mockPlanner) PlanLevel(level int) ([]tsm1.CompactionGroup, int64) { return nil, 0 }
func (m *mockPlanner) PlanOptimize() ([]tsm1.CompactionGroup, int64) { return nil, 0 }
func (m *mockPlanner) Release(groups []tsm1.CompactionGroup) {}
func (m *mockPlanner) FullyCompacted() (bool, string) { return false, "not compacted" }
func (m *mockPlanner) ForceFull() {}
func (m *mockPlanner) SetFileStore(fs *tsm1.FileStore) {}

// ParseTags returns an instance of Tags for a comma-delimited list of key/values.
func ParseTags(s string) query.Tags {

0 comments on commit 82a4039

Please sign in to comment.