Skip to content

Additional time range for alerts doesn't work #237

Closed

Description

@fr05t1k

It seems like an alert window doesn't work.

I specified that I'd like to check 3h window with 1h shift.
image

This window is greater than 20%
image

But the alert checks the whole period of the graph.
image

Activity

  1. fr05t1k commented on Jul 13, 2020

    @fr05t1k
    Author

    Probably this patch could help

    Index: datasource.go
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- datasource.go	(revision 35879b0fd7876201910adacc32de53d46cc90a18)
    +++ datasource.go	(date 1594650002971)
    @@ -63,7 +63,7 @@
     		return nil, fmt.Errorf("invalid status code. status: %v", response.Status)
     	}
     
    -	return parseResponse(body, refId)
    +	return parseResponse(body, refId, req.GetTimeRange())
     }
     
     func createRequest(req *datasource.DatasourceRequest, query string) (*http.Request, error) {
    @@ -143,7 +143,7 @@
     	return request, nil
     }
     
    -func parseResponse(body []byte, refId string) (*datasource.DatasourceResponse, error) {
    +func parseResponse(body []byte, refId string, timeRange *datasource.TimeRange) (*datasource.DatasourceResponse, error) {
     	parsedBody := ClickHouseResponse{}
     	err := json.Unmarshal(body, &parsedBody)
     	if err != nil {
    @@ -165,6 +165,10 @@
     					return nil, fmt.Errorf("unable to parse timestamp with alias t: %w", err)
     				}
     
    +				if timeRange != nil && (timeRange.FromEpochMs > timestamp || timeRange.ToEpochMs < timestamp) {
    +					continue
    +				}
    +
     				point, err := strconv.ParseFloat(v, 64)
     				if err != nil {
     					return nil, fmt.Errorf("unable to parse value for '%s': %w", k, err)
    
  2. Slach commented on Jul 14, 2020

    @Slach
    Collaborator

    @fr05t1k thanks for reporting and provide the solution

    I applied your patch, it works perfectly for use case when dashboard time range interval is bigger than alert part query( query_name, from_time_range, to_time_range)
    for example
    dashboard show last 3 hour
    and have alert FOR min() query(A, 60m, now-30m) IS BELOW 10

    for other use cases, we need another approach for refactoring plugin - try to rewrite query instead of filter query results
    but, original query may not contains "$timeFilter" macro, so currently I don't know how properly refactor plugin code

    @hagen1778 @bmanth60 @simPod maybe you share your opinion and suggest a solution?

  3. self-assigned this
    on Jul 14, 2020
  4. added 2 commits that reference this issue on Jul 24, 2020
  5. Slach commented on Jun 7, 2022

    @Slach
    Collaborator

    @fr05t1k now 2.5.0 release shall calculate time ranges for alerts properly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions