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(tsdb): Implement delete with predicate. #20236

Merged
merged 1 commit into from
Dec 2, 2020
Merged

feat(tsdb): Implement delete with predicate. #20236

merged 1 commit into from
Dec 2, 2020

Conversation

benbjohnson
Copy link
Contributor

@benbjohnson benbjohnson commented Dec 2, 2020

Overview

This pull request implements the "delete with predicate" API that was previously disabled. It works by implementing a new tsdb.Store.DeleteSeriesWithPredicate() function that operates on a predicate directly instead of an influxql.Expr. This PR also adds a PredicateSeriesIDIterator that filters an underlying iterator by predicate.

Note: The predicate does not currently support OR. That will need to be implemented separately.

Closes #19635

Usage

Write two points into the influx bucket:

$ influx write -b influx "cpu,region=us-east-1 value=1"
$ influx write -b influx "cpu,region=us-west-1 value=1"

Query to verify points exist.

$ influx query 'from(bucket:"influx")|>range(start:0)' 
Result: _result
Table: keys: [_start, _stop, _field, _measurement, region]
                   _start:time                      _stop:time           _field:string     _measurement:string           region:string                      _time:time                  _value:float  
------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------  
1970-01-01T00:00:00.000000000Z  2020-12-02T17:00:07.917155000Z                   value                     cpu               us-east-1  2020-12-02T17:00:03.448750000Z                             1  
Table: keys: [_start, _stop, _field, _measurement, region]
                   _start:time                      _stop:time           _field:string     _measurement:string           region:string                      _time:time                  _value:float  
------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------  
1970-01-01T00:00:00.000000000Z  2020-12-02T17:00:07.917155000Z                   value                     cpu               us-west-1  2020-12-02T17:00:06.027808000Z                             1  

Delete point in us-west-1 using predicate:

$ influx delete --org influx --bucket influx --start 2020-12-01T00:00:00Z --stop 2020-12-31T00:00:00Z --predicate '_measurement="cpu" AND region="us-west-1"'

Query again to verify only one point exists:

$ influx query 'from(bucket:"influx")|>range(start:0)' 
Result: _result
Table: keys: [_start, _stop, _field, _measurement, region]
                   _start:time                      _stop:time           _field:string     _measurement:string           region:string                      _time:time                  _value:float  
------------------------------  ------------------------------  ----------------------  ----------------------  ----------------------  ------------------------------  ----------------------------  
1970-01-01T00:00:00.000000000Z  2020-12-02T17:01:17.979115000Z                   value                     cpu               us-east-1  2020-12-02T17:00:03.448750000Z                             1  

TODO

  • CHANGELOG.md updated with a link to the PR (not the Issue)
  • Well-formatted commit messages
  • Rebased/mergeable
  • Tests pass
  • http/swagger.yml updated (if modified Go structs or API)
  • Feature flagged (if modified API)
  • Documentation updated or issue created (provide link to issue/pr)
  • Signed CLA (if not already signed)

@benbjohnson benbjohnson self-assigned this Dec 2, 2020
@danxmoran danxmoran changed the title Delete with predicate feat(tsdb): Implement delete with predicate. Dec 2, 2020
Copy link
Contributor

@danxmoran danxmoran left a comment

Choose a reason for hiding this comment

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

Obligatory nitpick: can you add a line to CHANGELOG.md?

Copy link
Contributor

@danxmoran danxmoran left a comment

Choose a reason for hiding this comment

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

Some cleanup questions, but overall LGTM. Thanks for adding the test!

tsdb/store.go Outdated Show resolved Hide resolved
tsdb/store.go Show resolved Hide resolved
@zbot473
Copy link

zbot473 commented Dec 2, 2020

Do I have to build this myself, or will the nightly version build later?

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.

Support delete with predicate functionality via /api/v2/delete
3 participants