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

[BUG] [object Object] is not valid JSON in prometheus metrics #1665

Closed
shotor opened this issue Mar 30, 2024 · 4 comments
Closed

[BUG] [object Object] is not valid JSON in prometheus metrics #1665

shotor opened this issue Mar 30, 2024 · 4 comments
Assignees
Labels
bug Something isn't working v2.14.0

Comments

@shotor
Copy link

shotor commented Mar 30, 2024

What is the bug?
A clear and concise description of the bug.

I added Prometheus as a data source. But when I go to /app/observability-metrics I see a quick flash of the metrics in the sidebar and then the content goes blank with a JS error in the console:

VM206:1 Uncaught (in promise) SyntaxError: "[object Object]" is not valid JSON
    at JSON.parse (<anonymous>)
    at displayVisualization (observabilityDashboards.plugin.js:1633:114610)
    at observabilityDashboards.chunk.4.js:1:411757
    at Object.fa [as useMemo] (osd-ui-shared-deps.js:435:61568)
    at t.useMemo (osd-ui-shared-deps.js:419:5984)
    at VisualizationContainer (observabilityDashboards.chunk.4.js:1:410467)
    at $i (osd-ui-shared-deps.js:435:57931)
    at Na (osd-ui-shared-deps.js:435:66792)
    at gs (osd-ui-shared-deps.js:435:105389)
    at uc (osd-ui-shared-deps.js:435:96718)

I put a breakpoint in displayVisualization (observabilityDashboards.plugin.js:1633:114610)

And I can see that metaData.userConfigs is a JavaScript object and not a string.

metaData.userConfigs = JSON.parse(metaData.userConfigs)

If I remove the JSON.parse in my Chrome devtools I can see the metrics in the sidebar. When I click a metric it goes blank again because my Chrome devtools is not making the change persistent. Not sure how to do that.

From source:

metaData.userConfigs = JSON.parse(metaData.userConfigs);

An easy fix would be to check if it's already an object. But not sure why the expected value is string.

How can one reproduce the bug?

  1. Add Prometheus metrics datasource
  2. Click on it
  3. Click on Query Data
  4. See error

What is the expected behavior?

It should show the metrics

What is your host/environment?

  • OS: debian12
  • Docker 25.0.5
  • Version 2.12.0

Do you have any additional context?

I'm getting metrics from:

  • cAdvisor
  • Metrics from the Prometheus instance itself
@shotor shotor added bug Something isn't working untriaged labels Mar 30, 2024
@shotor shotor changed the title [BUG] [object Object]" is not valid JSON [BUG] [object Object] is not valid JSON Mar 30, 2024
@Swiddis Swiddis removed the untriaged label Apr 1, 2024
@Swiddis
Copy link
Collaborator

Swiddis commented Apr 1, 2024

Thanks for the bug report! Tried following the refs to derive what the intended type is and it does look like it's inconsistently being used as a string and object. In a similar position: I tried refactoring to make a safer userConfig parser

const parseMetadataUserConfig = (
  userConfigs?: string | SavedObjectAttributes
): SavedObjectAttributes => {
  if (userConfigs === undefined || userConfigs === '') {
    return {};
  } else if (typeof userConfigs === 'string') {
    return JSON.parse(userConfigs);
  } else {
    return userConfigs;
  }
};

export const displayVisualization = (
  metaData: SavedVisualizationType | undefined,
  data: ExplorerData | undefined,
  type: string
) => {
  if (metaData === undefined || isEmpty(metaData)) {
    return <></>;
  }

  metaData.userConfigs = parseMetadataUserConfig(metaData.userConfigs);
  
  // And refactoring all the redundant spreads:
  const dataConfig = metaData.userConfigs?.dataConfig || {};

  // ...
}

And it seems to work to clear out most type errors, but I'm also missing context on what the prometheus flow should look like to begin with. Will see if I can find someone who knows it better.

@Swiddis Swiddis assigned Swiddis and unassigned Swiddis Apr 1, 2024
@Swiddis Swiddis added the v2.14.0 label Apr 1, 2024
@Swiddis Swiddis changed the title [BUG] [object Object] is not valid JSON [BUG] [object Object] is not valid JSON in prometheus metrics Apr 3, 2024
@Swiddis
Copy link
Collaborator

Swiddis commented Apr 3, 2024

More prometheus issues:

Looks like this is a testing blindspot. Assigning this to myself and @RyanL1997 for these issues and improving our testing.

@Swiddis Swiddis assigned Swiddis and RyanL1997 and unassigned Swiddis Apr 3, 2024
@akshatmisra198808
Copy link

There is a bug for this created with all the details opensearch-project/sql#2541

YANG-DB added a commit to YANG-DB/dashboards-observability that referenced this issue Apr 29, 2024
YANG-DB added a commit that referenced this issue Apr 30, 2024
Signed-off-by: YANGDB <[email protected]>
Swiddis pushed a commit to Swiddis/dashboards-observability that referenced this issue Apr 30, 2024
Swiddis added a commit that referenced this issue May 1, 2024
* Add 2.14 release notes

Signed-off-by: Simeon Widdis <[email protected]>

* fix issue #1665 (#1757)

Signed-off-by: YANGDB <[email protected]>

* Revert "Add 2.14 release notes"

This reverts commit 42ac9c4.

Signed-off-by: Simeon Widdis <[email protected]>

---------

Signed-off-by: Simeon Widdis <[email protected]>
Signed-off-by: YANGDB <[email protected]>
Co-authored-by: YANGDB <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this issue May 1, 2024
* Add 2.14 release notes

Signed-off-by: Simeon Widdis <[email protected]>

* fix issue #1665 (#1757)

Signed-off-by: YANGDB <[email protected]>

* Revert "Add 2.14 release notes"

This reverts commit 42ac9c4.

Signed-off-by: Simeon Widdis <[email protected]>

---------

Signed-off-by: Simeon Widdis <[email protected]>
Signed-off-by: YANGDB <[email protected]>
Co-authored-by: YANGDB <[email protected]>
(cherry picked from commit f9a6e49)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Swiddis added a commit that referenced this issue May 1, 2024
* Add 2.14 release notes



* fix issue #1665 (#1757)



* Revert "Add 2.14 release notes"

This reverts commit 42ac9c4.



---------




(cherry picked from commit f9a6e49)

Signed-off-by: Simeon Widdis <[email protected]>
Signed-off-by: YANGDB <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: YANGDB <[email protected]>
Co-authored-by: Simeon Widdis <[email protected]>
@Swiddis
Copy link
Collaborator

Swiddis commented May 1, 2024

Completed by #1757 and ready to go for 2.14

@Swiddis Swiddis closed this as completed May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2.14.0
Projects
None yet
Development

No branches or pull requests

4 participants