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

Refactor Response Parser #309

Merged
merged 5 commits into from
Nov 21, 2023
Merged

Refactor Response Parser #309

merged 5 commits into from
Nov 21, 2023

Conversation

sarahzinger
Copy link
Member

While working on adding backend support for traces as part of #287 I noticed that our response parser could use some refactoring improvements. To make the prs easier to read I've broken them up.

Changes:

  • rename newTimeSeriesQuery to newQueryRequest. It seems a bit confusing to describe all the work that happens in there as timeSeries queries (although I do think they often---always?-- have a time field attached).
  • similarly rename getTimeSeries to parseQuery I think this more accurately describes what's happening. The request has already been made, the responses just need to be parsed and again I think describing all of the types we support as timeseries feels a bit misleading maybe?
  • Pass Datasource Settings in to newQueryRequest, luceneHandler, and ultimately to the requestParser. This will eventually be necessary when adding traces to the request parser because we need to use the datasourceUID and datasource Name to add to the field for TraceId, so that all traceIds are clickable and open an individual trace view. I could have possibly instead accessed this off of client the way we do with configurable fields, but it felt a bit strange to me to add a getter in client to access the datasource, when client's main responsibility is to communicate with open search.
  • Pass Configurable Fields to the responseparser when we make it, rather than to the function that parses responses. It felt a bit confusing to me to have multiple places where we pick up inputs.
  • Move debugInfo within the if conditional's scipe where it's used inside of parseQuery.
  • Add some comments (I was adding them mostly for me as I walked through the code, and I'm note entirely sure they are still valuable but they might be?)

@sarahzinger sarahzinger requested a review from a team as a code owner November 20, 2023 00:55
@sarahzinger sarahzinger requested review from fridgepoet and kevinwcyu and removed request for a team November 20, 2023 00:55
@sarahzinger sarahzinger force-pushed the sarahzinger/refactor-parser branch from ed7e5b5 to 7dfbf2f Compare November 20, 2023 01:12
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
pkg/opensearch/response_parser.go Outdated Show resolved Hide resolved
@@ -13,6 +13,7 @@ import (
simplejson "github.com/bitly/go-simplejson"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/opensearch-datasource/pkg/opensearch/client"
Copy link
Contributor

Choose a reason for hiding this comment

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

this line can be removed following the two code suggestions below.

Copy link
Member Author

Choose a reason for hiding this comment

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

great catch thank you!

@sarahzinger sarahzinger merged commit a1b7ef7 into main Nov 21, 2023
2 checks passed
@sarahzinger sarahzinger deleted the sarahzinger/refactor-parser branch November 21, 2023 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants