Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Convert field type problems - out of a Loki datasource #63947

Closed
JoachimSchiewek opened this issue Mar 1, 2023 · 4 comments
Closed

Convert field type problems - out of a Loki datasource #63947

JoachimSchiewek opened this issue Mar 1, 2023 · 4 comments

Comments

@JoachimSchiewek
Copy link

I have a problem to convert the filed type to number as the datasource is from Loki:

As an example I get 3 Values from an ordinary grafana.log:
Value 1 is a DATE, The user-ID stands for NUMBER 1 and the duration for NUMBER 2. Just to have some numbers.

Out of Loki, all the values are string type values.
To create a graph, I have to convert them to numbers.

Here is what happend..:

Test_1

when I convert them to number - it crashed. Cant do that.

This problem occures since Grafana 9.3.6

more examples in the community
Anything else we need to know?:

Environment:

  • Grafana version: 9.4.1
  • Data source type & version:
  • OS Grafana is installed on: Windows
  • User OS & Browser:
  • Grafana plugins:
  • Others:

Hope someone can help and fix the situation.
In my case I can fix the problem by convert to json and not to number.

@usmangt usmangt added datasource/Loki area/transformations triage/needs-confirmation used for OSS triage rotation - reported issue needs to be reproduced labels Mar 1, 2023
@matyax matyax added this to Dashboards Mar 3, 2023
@github-project-automation github-project-automation bot moved this to 🗂️ Needs Triage in Dashboards Mar 3, 2023
@matyax
Copy link
Contributor

matyax commented Mar 3, 2023

@grafana/dashboards-squad could you please a look at this one? If there’s anything we can help with, just ping us. Thanks!

@ivanahuckova ivanahuckova removed datasource/Loki triage/needs-confirmation used for OSS triage rotation - reported issue needs to be reproduced labels Mar 10, 2023
@ivanahuckova
Copy link
Member

I removed Loki label as this seems like an issue with transformations and not issue with Loki data source.

@mckamyk
Copy link

mckamyk commented Apr 13, 2023

EDIT: Apologies, appears to have already been resolved in the above listed PR.

It appears the file grafana/packages/grafana-data/src/transformations/transformers/convertFieldType.ts has the following function.

function fieldToNumberField(field: Field): Field {
  const numValues = field.values.toArray().slice();

  // in my case, numValues appears to be [undefined, "2.3", undefined, "12.1", ...]

  const valuesAsStrings = numValues.some((v) => typeof v === 'string');

  for (let n = 0; n < numValues.length; n++) {
    let toBeConverted = numValues[n];

    if (valuesAsStrings) {
      // some numbers returned from datasources have commas
      // strip the commas, coerce the string to a number
      toBeConverted = toBeConverted.replace(/,/g, '');
    }

    const number = +toBeConverted;

    numValues[n] = Number.isFinite(number) ? number : null;
  }

  return {
    ...field,
    type: FieldType.number,
    values: new ArrayVector(numValues),
  };
}

This does not account for sparse data, where some of the records have undefined as the value for the targetted field. the

if (valuesAsStrings) {
  // some numbers returned from datasources have commas
  // strip the commas, coerce the string to a number
  toBeConverted = toBeConverted.replace(/,/g, '');
}

errors as cannot read property ".replace" of undefined.

Could this be simply remedied with the following snipped?

if (valuesAsStrings && toBeConverted) { // check toBeConverted exists.
  // some numbers returned from datasources have commas
  // strip the commas, coerce the string to a number
  toBeConverted = toBeConverted.replace(/,/g, '');
}

@zoltanbedi
Copy link
Member

Fixed in #66807 The fix will be out in Grafana 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants