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

add macros for raw values of interval, from, to #98

Merged
merged 5 commits into from
Dec 16, 2021

Conversation

DarrenStack
Copy link
Contributor

Hi there,

When using the Grafana plugin, we sometimes have to do some string replacement and casting on the current interval and timeFilter macros in order to use the raw values for calculations.

It would be nicer for us if we could have macros to access those values directly like this PR allows.

Happy to change anything that doesn't fit with your macro standards.

@zoltanbedi
Copy link
Member

@@ -93,4 +93,69 @@ func TestInterpolate(t *testing.T) {
t.Fatalf("Result above tolerated precision %d : %d, %d", precision, numtext, expect)
}
})

t.Run("using timeFrom", func(t *testing.T) {
sqltxt := `$__time_from_raw_ms`
Copy link
Contributor

@nmarrs nmarrs Sep 27, 2021

Choose a reason for hiding this comment

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

Repeating string value in two different files seems a little delicate / prone to potential maintainability issues down the road.

I'm not as familiar with Go / Go conventions, but in naming a const is the naming convention camelCase vs. CONST_VAR (similar to JS / TS?). Making naming of const very clear may help some (starting on line 13 of macros.go) Also, are we able to export individual variables from a file? If so we could export the const string values from macros.go to use them with more confidence in this testing file.

Disclaimer: This may be a premature optimization / me not understanding Go conventions :)

Copy link
Contributor

Choose a reason for hiding this comment

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

The Go standard library uses camel case for consts, since capital = export. They're in the same package, so they actually wouldn't need to be exported to be used in this test. However, I somewhat disagree with using the exact same string object in the code and the test, since I don't think that tests much. (See other comment about using a longer sqltxt string)

Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the contribution! Could you also add these to the macros documentation in src/README.md?

pkg/timestream/macros_test.go Outdated Show resolved Hide resolved
@@ -93,4 +93,69 @@ func TestInterpolate(t *testing.T) {
t.Fatalf("Result above tolerated precision %d : %d, %d", precision, numtext, expect)
}
})

t.Run("using timeFrom", func(t *testing.T) {
sqltxt := `$__time_from_raw_ms`
Copy link
Contributor

Choose a reason for hiding this comment

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

The Go standard library uses camel case for consts, since capital = export. They're in the same package, so they actually wouldn't need to be exported to be used in this test. However, I somewhat disagree with using the exact same string object in the code and the test, since I don't think that tests much. (See other comment about using a longer sqltxt string)

pkg/timestream/macros.go Outdated Show resolved Hide resolved
@DarrenStack
Copy link
Contributor Author

sorry for the delay in getting to this. Hope it looks a little bit better now

Copy link
Contributor

@iwysiu iwysiu left a comment

Choose a reason for hiding this comment

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

Hi @DarrenStack ,

One last thing, but it looks really good!

pkg/timestream/macros.go Outdated Show resolved Hide resolved
@iwysiu
Copy link
Contributor

iwysiu commented Dec 14, 2021

Sorry I missed the review re-request! It looks good now and thanks for the PR! Could you fix the merge conflict before I merge it?

@DarrenStack
Copy link
Contributor Author

No worries! I slightly updated the README again to make the difference between the macros a bit clearer.

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

Successfully merging this pull request may close these issues.

4 participants