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

Feature: Replace stage in pipeline #2060

Merged
merged 1 commit into from
Jun 1, 2020

Conversation

adityacs
Copy link
Collaborator

@adityacs adityacs commented May 10, 2020

What this PR does / why we need it:
Adds Replace stage in pipeline. Supports, replacing log lines based on captured groups.

Which issue(s) this PR fixes:
Fixes #2033

Checklist

  • Documentation added
  • Tests updated

@adityacs adityacs force-pushed the 2033_replace_regex branch 2 times, most recently from 1b55961 to d676c3d Compare May 10, 2020 09:11
@codecov-io
Copy link

codecov-io commented May 10, 2020

Codecov Report

Merging #2060 into master will decrease coverage by 0.00%.
The diff coverage is 63.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2060      +/-   ##
==========================================
- Coverage   61.31%   61.30%   -0.01%     
==========================================
  Files         146      147       +1     
  Lines       11189    11316     +127     
==========================================
+ Hits         6860     6937      +77     
- Misses       3784     3816      +32     
- Partials      545      563      +18     
Impacted Files Coverage Δ
pkg/logentry/stages/stage.go 47.36% <50.00%> (+0.19%) ⬆️
pkg/logentry/stages/replace.go 64.22% <64.22%> (ø)
pkg/promtail/targets/tailer.go 76.13% <0.00%> (-2.28%) ⬇️
pkg/logql/evaluator.go 90.69% <0.00%> (-0.59%) ⬇️

@adityacs adityacs marked this pull request as draft May 12, 2020 14:58
@adityacs adityacs force-pushed the 2033_replace_regex branch 4 times, most recently from bc11d7b to f37f68b Compare May 14, 2020 20:53
@adityacs adityacs marked this pull request as ready for review May 14, 2020 20:58
@adityacs adityacs requested a review from cyriltovena May 14, 2020 20:58
@adityacs adityacs changed the title Feature: Replace substage for regex Feature: Replace stage in pipeline May 25, 2020
@adityacs adityacs requested a review from cyriltovena May 25, 2020 05:43
@codecov-commenter
Copy link

codecov-commenter commented May 25, 2020

Codecov Report

Merging #2060 into master will decrease coverage by 0.05%.
The diff coverage is 62.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2060      +/-   ##
==========================================
- Coverage   61.31%   61.25%   -0.06%     
==========================================
  Files         146      147       +1     
  Lines       11189    11295     +106     
==========================================
+ Hits         6860     6919      +59     
- Misses       3784     3815      +31     
- Partials      545      561      +16     
Impacted Files Coverage Δ
pkg/logentry/stages/stage.go 47.36% <50.00%> (+0.19%) ⬆️
pkg/logentry/stages/replace.go 62.74% <62.74%> (ø)
pkg/promtail/targets/tailer.go 73.86% <0.00%> (-4.55%) ⬇️
pkg/promtail/targets/filetarget.go 68.67% <0.00%> (-1.81%) ⬇️

@adityacs adityacs force-pushed the 2033_replace_regex branch 3 times, most recently from 7ee362e to 8678482 Compare May 26, 2020 17:28
@adityacs adityacs force-pushed the 2033_replace_regex branch 2 times, most recently from afc3fcf to c342759 Compare May 27, 2020 05:32
}

// All the named captured group will be extracted
for i, name := range r.expression.SubexpNames() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is useful ?

Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of you code would be much simpler.

Let's drop this for now. You can have a regex to do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Let's drop this for now. You can have a regex to do that

This is just for reducing using different stages in pipeline. If user wants to extract variable and then template the extracted variable he should use regex stage and then template stage. This would reduce that effort

A lot of you code would be much simpler.

Sure. Let me know where I have to improve.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's start with this.

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit 38ee57c into grafana:master Jun 1, 2020
@pyr0hu
Copy link
Contributor

pyr0hu commented Jul 27, 2020

Is there any ETA when will this feature be released? Latest 1.5.0 seems to be released on May 20 and this was merged on Jun 1.

}

if c.Replace == "" {
return nil, errors.New(ErrEmptyReplaceStageConfig)
Copy link
Contributor

Choose a reason for hiding this comment

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

also, I know this PR is merged, but why is this validated? If, for example, I want to remove part of the log, I cannot use replace pipeline as it won't accept an empty replace. I could use a whitespace, but then it looks funny

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a fair request. You can open a PR or may be @adityacs is up for it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'll have some free time today or tomorrow to do a PR. Just wanted to ask your opinions about it :)

@cyriltovena
Copy link
Contributor

Is there any ETA when will this feature be released? Latest 1.5.0 seems to be released on May 20 and this was merged on Jun 1.

@slim-bean probably has an idea for the ETA.

@slim-bean
Copy link
Collaborator

This week!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace pipeline stage
6 participants