Skip to content

Parse JSON String arrays properly so string elements can be retrieved#11921

Merged
paul1r merged 8 commits intomainfrom
paul1r/json_array_loki_issue_9179
Feb 13, 2024
Merged

Parse JSON String arrays properly so string elements can be retrieved#11921
paul1r merged 8 commits intomainfrom
paul1r/json_array_loki_issue_9179

Conversation

@paul1r
Copy link
Copy Markdown
Collaborator

@paul1r paul1r commented Feb 12, 2024

What this PR does / why we need it:
This PR imports the newly forked grafana/jsonparser over the buger/jsonparser module. The latter has seemingly been abandoned. PR 10690 introduces a fix to the jsonparser module, which has been incorporated into the grafana fork of the module.

The PR is designed to fix accessing string array elements from within a JSON structure. For example, with the following JSON:
{"log":{"message":{"content":{"misses":["a","b","c","d"]}}}}

The Loki code, before this PR, when searching for json misses = "log.message.content.misses[0]" will result in an "Unknown value type error". After this PR is merged, the result will assign a to the misses variable.

Which issue(s) this PR fixes:
Fixes #9179
#10690

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@paul1r paul1r added type/bug Somehing is not working as expected add-to-release-notes labels Feb 12, 2024
@paul1r paul1r requested review from a team, periklis and xperimental as code owners February 12, 2024 16:49
@paul1r paul1r changed the title Paul1r/json array loki issue 9179 Parse JSON String arrays properly so string elements can be retrieved Feb 12, 2024
Copy link
Copy Markdown
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@MichelHollands MichelHollands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Can you add the unit tests from https://github.com/grafana/loki/pull/10690/files?

Comment thread operator/.bingo/go.mod Outdated
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files. No newline at end of file
module _ // Fake go.mod auto-created by 'bingo' for go -moddir compatibility with non-Go projects. Commit this file, together with other .mod files.

go 1.21
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Perhaps we shouldn't change operator files.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can revert, this was picked up through one of the build commands

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

Copy link
Copy Markdown
Contributor

@MichelHollands MichelHollands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We'll need a CHANGELOG entry though as this is user visible.

@paul1r paul1r merged commit 472496f into main Feb 13, 2024
@paul1r paul1r deleted the paul1r/json_array_loki_issue_9179 branch February 13, 2024 13:58
grafanabot added a commit that referenced this pull request Feb 13, 2024
paul1r added a commit that referenced this pull request Feb 13, 2024
…erly so string elements can be retrieved (#11931)

Add PR #11921 to release notes for next release

---------

Co-authored-by: Paul Rogers <paul.rogers@grafana.com>
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
…grafana#11921)

**What this PR does / why we need it**:
This PR imports the newly forked grafana/jsonparser over the
buger/jsonparser module. The latter has seemingly been abandoned. PR
10690 introduces a fix to the jsonparser module, which has been
incorporated into the grafana fork of the module.

The PR is designed to fix accessing string array elements from within a
JSON structure. For example, with the following JSON:
`{"log":{"message":{"content":{"misses":["a","b","c","d"]}}}}`

The Loki code, before this PR, when searching for `json misses =
"log.message.content.misses[0]" ` will result in an "Unknown value type
error". After this PR is merged, the result will assign `a` to the
`misses` variable.

**Which issue(s) this PR fixes**:
Fixes #[9179](grafana#9179)
grafana#10690

**Special notes for your reviewer**:

**Checklist**
- [x] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [ ] Documentation added
- [x] Tests updated
- [x] `CHANGELOG.md` updated
- [x] If the change is worth mentioning in the release notes, add
`add-to-release-notes` label
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/setup/upgrade/_index.md`
- [ ] For Helm chart changes bump the Helm chart version in
`production/helm/loki/Chart.yaml` and update
`production/helm/loki/CHANGELOG.md` and
`production/helm/loki/README.md`. [Example
PR](grafana@d10549e)
- [ ] If the change is deprecating or removing a configuration option,
update the `deprecated-config.yaml` and `deleted-config.yaml` files
respectively in the `tools/deprecated-config-checker` directory.
[Example
PR](grafana@0d4416a)
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
…ys properly so string elements can be retrieved (grafana#11931)

Add PR grafana#11921 to release notes for next release

---------

Co-authored-by: Paul Rogers <paul.rogers@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add-to-release-notes size/M type/bug Somehing is not working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants