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

Feat: Add promql trigonometric functions #940

Merged
merged 8 commits into from
May 23, 2024

Conversation

Jiale-Fang
Copy link
Contributor

Description

Add promql trigonometric functions: https://prometheus.io/docs/prometheus/latest/querying/functions/#trigonometric-functions

Testing

Describe how you tested this code. How can the reviewers reproduce your tests?

Checklist:

Before marking your pull request as ready for review, complete the following.

  • I have self-reviewed this PR.
  • I have removed all print-debugging and commented-out code that should not be merged.
  • I have added sufficient comments in my code, particularly in hard-to-understand areas.
  • I have formatted the code, if applicable. For Go, I have run goimports -w ..

Comment on lines 315 to 321
case segutils.Atanh:
err = evaluateWithErr(ts, func(val float64) (float64, error) {
if val < -1 || val > 1 {
return val, fmt.Errorf("evaluateWithErr: atanh evaluate values in the range [-1,1]")
}
return math.Atanh(val), nil
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it! I just have a doubt. When I use a function to evaluate the value inside timeSeries map[uint32]float64, for some input, the function will return NaN or Inf. But since the map's value is float64, I cannot return NaN or Inf in this case. So I return an error instead. Is this the correct approach? What do you think?

Copy link
Contributor Author

@Jiale-Fang Jiale-Fang May 23, 2024

Choose a reason for hiding this comment

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

E.g.: Atanh(1) = +Inf, Atanh(-1) = -Inf, Atanh(x) = NaN if x < -1 or x > 1
https://pkg.go.dev/math#Atanh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am curious because promql will return NaN in this case
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I think returning an error when the value is outside function's domain is a good approach. Otherwise the frontend has to somehow display NaNs to the user, which could be confusing.

Later if we get feedback from users that they'd rather get Nans and Infs rather than errors, we can change this behavior

Copy link
Collaborator

Choose a reason for hiding this comment

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

You have basically the same code runTrigonometricFunctionTest() three times. You can clean this up by making the timeseries a parameter to it; that way you only need to define the function once. And maybe add another parameter for whether metricsResults.ApplyFunctionsToResults(8, function) should error, so that you can test erroring states like you do in the last two versions of the function

@AndrewHess AndrewHess merged commit 862aad7 into siglens:develop May 23, 2024
2 checks passed
navyayy pushed a commit to navyayy/siglens that referenced this pull request May 28, 2024
* Allow parsing promql trigonometric functions

* Add promql trigonometric functions processing logic

* Add metrics prompt json

* Add unit tests

* Fix up
sonamgupta21 added a commit that referenced this pull request May 29, 2024
* feat: Update dashboard panels layout and positioning

* Fix columnsOrder issue (#934)

* logsearch page -Wildcard and autocomplete support for index Search (#932)

* logsearch page -Wildcard Option, Index Search

* address PR comments

---------

Co-authored-by: Kunal Nawale <knawale@sigscalr.io>

* Return resultType matrix for range queries (#935)

Co-authored-by: Kunal Nawale <knawale@sigscalr.io>

* Feat: Promql <aggregation>_over_time funcs Completion (#929)

* Add <aggregation>_over_time funcs processing logic

* Add <aggregation>_over_time funcs parsing logic

* Add metrics prompt json

* Add unit tests

* Add e2e tests

* Remove unused code

* Add unit tests

* Update OTSDB metric ingestion url on sigclient (#939)

Co-authored-by: Kunal Nawale <knawale@sigscalr.io>

* Fix: Single line & wrap line view (#942)

* Fix frontend console errors (#938)

* Fix interleaved socket timings

* Make doSearch return a promise

---------

Co-authored-by: Sonam Gupta <71771131+sonamgupta21@users.noreply.github.com>

* Flag to prevent multiple simultaneous fetches (#944)

* added delete index functionality on clusterstats page (#943)

Co-authored-by: Sonam Gupta <71771131+sonamgupta21@users.noreply.github.com>

* Fix: Unrotated segment range checking logic (#945)

* Add qid to the log msg

* Fix unrotated segment range checking logic

* Feat: Add promql trigonometric functions (#940)

* Allow parsing promql trigonometric functions

* Add promql trigonometric functions processing logic

* Add metrics prompt json

* Add unit tests

* Fix up

* Feat: Add promql funcs predict_linear() (#946)

* Fix up

* Add promql funcs parsing logic

* Add promql funcs processing logic

* Add metrics prompt json

* Add test cases

---------

Co-authored-by: Andrew Hess <ahess@sigscalr.io>

* Remove live tail on UI (#947)

* Remove live tail on UI

* remove live tail

* Fix: Increase tolerance for approximate equality in metrics test (#949)

* Increase tolerance for approximate equality in metrics test

* Fix up

* Add metrics and traces count (#950)

* Add metrics and traces count

* address ineff assign

---------

Co-authored-by: Andrew Hess <ahess@sigscalr.io>

* Store all incoming queries to query.log (#948)

* Store all incoming queries to query.log

* optimize file handling and log restart events

* use common method for logging

* rename mu to fileMutex

* Discard stale data (#952)

* Truncate slices to discard stale data

The SegmentFileReader.deTlv in particular was holding on to stale data
and then iterating over it; sometimes leading to getting garbage data,
and other times causing a panic.

* Add basic unit test

* Update the unit test

* Fix linting

* Add promql funcs hour,minute,month,year,day_of_month,day_of_week,day_of_year,days_in_month (#937)

* Add promql funcs

promql functions hour(),minute(),month(),year(),day_of_month(),day_of_week(),day_of_year(),days_in_month()

* add testcases

* add cicd tests and update var names

* update example queries

* formatting

* address comments

* update desc

---------

Signed-off-by: Venkatesha Matam <113487319+venkateshamatam@users.noreply.github.com>
Co-authored-by: Andrew Hess <ahess@sigscalr.io>

* Fix metrics test (#956)

Signed-off-by: Kunal Nawale <knawale@sigscalr.io>

* Refactor http errors (#955)

* Refactor sending http errors

* Add unit test

---------

Co-authored-by: Kunal Nawale <knawale@sigscalr.io>

* Refactor resizing a slice (#954)

* Add util to resize a slice

* Expand to capacity to avoid unnecessary appending

* Refactor to use ResizeSlice() util

---------

Co-authored-by: Kunal Nawale <knawale@sigscalr.io>

* Persistent Available Fields (#951)

Co-authored-by: Kunal Nawale <knawale@sigscalr.io>

* release 0.2.8 (#957)

Signed-off-by: Kunal Nawale <knawale@sigscalr.io>

* Update version.go (#959)

* fix: increase width by 1

* fix: increased the width

* fix: reverted the previous dashboard.js

* Added gridstack.all.js.map (#969)

* fix: formatting

* fix: formatting

---------

Signed-off-by: Venkatesha Matam <113487319+venkateshamatam@users.noreply.github.com>
Signed-off-by: Kunal Nawale <knawale@sigscalr.io>
Co-authored-by: Kunal Nawale <knawale@sigscalr.io>
Co-authored-by: Jiale Fang <67371917+Jiale-Fang@users.noreply.github.com>
Co-authored-by: Sunita <skawane@sigscalr.io>
Co-authored-by: Venkatesha Matam <113487319+venkateshamatam@users.noreply.github.com>
Co-authored-by: Sonam Gupta <71771131+sonamgupta21@users.noreply.github.com>
Co-authored-by: Andrew Hess <ahess@sigscalr.io>
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.

None yet

2 participants