Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[InfluxDB Scaler] Allow queries that return integers in addition to those that return floats #1973

Closed
philomory opened this issue Jul 21, 2021 · 5 comments · Fixed by #1977
Closed
Labels
feature-request All issues for new features that have not been committed to needs-discussion

Comments

@philomory
Copy link
Contributor

Proposal

The InfluxDB scaler should continue to function if the query used returns an integer rather than a float. At the moment, there is an undocumented requirement that queries must return floats.

Use-Case

I'd like to query values from InfluxDB that happen to be stored as integers (event counters and such) without having to remember to manually convert those values to floats in each Flux query.

Anything else?

influxdb_scaler.go lines 173 to 176 contains the following code:

val, ok := result.Record().Value().(float64)
if !ok {
    return 0, fmt.Errorf("value could not be parsed into a float")
}

It seems like adding an additional branch that handles integers wouldn't be a huge burden.

@philomory philomory added feature-request All issues for new features that have not been committed to needs-discussion labels Jul 21, 2021
@zroubalik
Copy link
Member

Seems like a fair requests, I don't think there is something that prevents us in using int there as well. @yquansah wdyt?

@philomory Are you willing to contribute this one?

@yquansah
Copy link
Contributor

@zroubalik I mean it eventually does get truncated to an integer

Value: *resource.NewQuantity(int64(value), resource.DecimalSI),

but there is some assumptions being made here. Is there a particular error or something you are encountering? @philomory

@philomory
Copy link
Contributor Author

philomory commented Jul 22, 2021

@zroubalik Yes, I think I'd be able to contribute a fix. At the very least, I can give it a shot.

@yquansah Yes, if you start with a query that returns an integer the entire process fails, while logging the error "value could not be parsed into a float".

For example, if I try to use the following query:

from(bucket: "example")
  |> range(start: -5m)
  |> filter(fn: (r) => r._measurement == "job_stats" and r._field == "backlog_size")
  |> last()

... this will return the number of jobs in a backlog, which is an integer. Used as-is, this causes the scaler to fail; if I want it to work, I have to manually convert my data to floats within my query, e.g.:

from(bucket: "example")
  |> range(start: -5m)
  |> filter(fn: (r) => r._measurement == "job_stats" and r._field == "backlog_size")
  |> last()
  |> map(fn: (r) => ({r with _value: float(v: r._value)})

@yquansah
Copy link
Contributor

@philomory Got you. Okay this should be something I can write a fix for

@zroubalik
Copy link
Member

@yquansah the PR is already opened, feel free to do a review
#1977

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request All issues for new features that have not been committed to needs-discussion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants