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

Iterate through child array with labels in parent? #168

Closed
liam-hogan opened this issue Jul 22, 2022 · 1 comment
Closed

Iterate through child array with labels in parent? #168

liam-hogan opened this issue Jul 22, 2022 · 1 comment

Comments

@liam-hogan
Copy link

liam-hogan commented Jul 22, 2022

Hi all, I am thoroughly enjoying this tool, but I have reached a weird obstacle regarding parsing through data.

Here's the issue:
I have a JSON file that is structured like so:

{
    "title": "JSON data",
    "timestart": "07/21/2022 13:53:20",
    "timeend": "07/21/2022 13:55:00",
    "table": [
        {array: value,
          of: value,
          items: value},
        {array: value,
          of: value,
          items: value},
        {array: value,
          of: value,
          items: value}]
}

I had to remove important data for this example, but this should suffice.

This works fine when I set the config.yml to something like this:

headers:
  MyHeader: MyHeaderValue
modules:
  default:
    metrics:
    - name: JSON_DATA
      type: object
      help: JSON_DATA test
      path: '{.table[*]}'
      labels:
        id: '{.array}'
      values:
        of: '{.of}'
        items: '{.items}'

However, if I wish to use any of the parent nodes (title, timestart, timeend) in my labels as well as a label from the underlying table array, this becomes difficult. I understand that setting the path as a child node makes "looking up" to the parent impossible, so I thought I could traverse down:

headers:
  MyHeader: MyHeaderValue
modules:
  default:
    metrics:
    - name: JSON_DATA
      type: object
      help: JSON_DATA test
      path: '{$}'
      labels:
        id: '{.table[*].array}'
        timestart: '{.timestart}'
      values:
        of: '{.table[*].of}'
        items: '{.table[*].items}'

This does not work. I have some issues getting this to work properly, and it's definitely in part to my inexperience with JSONPath. I have been able to get an error where the data is ingested, but it is done in a way that instead of having one metric per instance, it gets every instance of that metric (causing an error).

Does anyone have suggestions on how to go about traversing and pairing the elements from the parents with the elements from the child array?

Also, I think the timestart is failing due to how the timestamp is formatted. Based on this documentation as well as the guide found here, I see the need for an object type, but I cannot find any reference for these object types. Does anyone have any information regarding this?

Thank you,
Liam Hogan

@rustycl0ck
Copy link
Member

Duplicate of #133

@rustycl0ck rustycl0ck marked this as a duplicate of #133 Nov 30, 2022
@SuperQ SuperQ closed this as completed Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants