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 the XPath/RegEx Data Extractor and Expression Evaluation for HTTP Probe #192

Merged
merged 5 commits into from
Aug 15, 2022

Conversation

haoel
Copy link
Contributor

@haoel haoel commented Aug 10, 2022

try to support the following expression evaluation.

http:
  - name: EaseProbe RSS Feed
    url: https://github.com/megaease/easeprobe/releases.atom
    eval:
      doc : XML # <-- document type, currently support HTML, XML, JSON, TEXT
      expression: "updated > '2022-07-01'"  # <-- the expression need to be evaluated.
      # define how the variable `updated` come from
      variables: 
         - name: updated
           type: time # support int/float/string/bool/time/duration 
           query: "//feed/updated" # XPath 
           time_format: "2006-01-02T15:04:05Z07:00"

or simple one

http:
  - name: EaseProbe RSS Feed
    url: https://github.com/megaease/easeprobe/releases.atom
    proxy: socks5://localhost:1085
    eval:
      doc : XML
      expression: "x_time('//feed/updated') > '2022-07-01'"

Note: x_str(), x_int(), x_float(), x_time(), x_bool(), x_duration() are the functions can extract the data by using XPath or Regex expression

Please focus on those files

  • eval/*.go
  • probe/http/http.go

Note:

There are many files that have been changed because of the go 1.19 format.

@codecov-commenter
Copy link

codecov-commenter commented Aug 10, 2022

Codecov Report

Merging #192 (f36cc03) into main (504c529) will increase coverage by 0.41%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
+ Coverage   93.92%   94.34%   +0.41%     
==========================================
  Files          46       49       +3     
  Lines        3655     3926     +271     
==========================================
+ Hits         3433     3704     +271     
  Misses        155      155              
  Partials       67       67              
Impacted Files Coverage Δ
conf/conf.go 80.61% <ø> (ø)
conf/log.go 85.48% <ø> (ø)
probe/data.go 65.18% <ø> (ø)
probe/status.go 76.47% <ø> (ø)
report/common.go 96.59% <ø> (ø)
eval/eval.go 100.00% <100.00%> (ø)
eval/extract.go 100.00% <100.00%> (ø)
eval/types.go 100.00% <100.00%> (ø)
probe/http/http.go 97.97% <100.00%> (+0.17%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@zhao-kun zhao-kun left a comment

Choose a reason for hiding this comment

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

IMHO, If I implemented the feature, I would prefer to splitting the Evaluator and Configuration into different objects, and the Evaluator object has only one in the global, configuration object for each HTTP prober.

Just a different design style

return false, err
}

expression, err := govaluate.NewEvaluableExpressionWithFunctions(e.Expression, e.EvalFuncs)
Copy link
Contributor

Choose a reason for hiding this comment

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

The result of govaluate.NewEvaluableExpressionWithFunctions(e.Expression, e.EvalFuncs) can be cached which should minor improve performance. [1]

[1] https://github.com/Knetic/govaluate/blob/master/benchmarks_test.go#L104-L114

@haoel
Copy link
Contributor Author

haoel commented Aug 12, 2022

IMHO, If I implemented the feature, I would prefer to splitting the Evaluator and Configuration into different objects, and the Evaluator object has only one in the global, configuration object for each HTTP prober.

Just a different design style

I considered separating the Evaluator and Configuration, but they are the exactly same object which would introduce the duplication code we have to maintain their consistency. And there is a Variable object inside, so finally, just use one struct for both of them.

If we only use one global Evaluator object for all HTTP probers, then we have to manage the different configurations for different HTTP probers, as they would have different document format(xml/html/json/txt) and different expressions. And this also would introduce multiple threads complexity. I prefer to have the dedicated Evaluator object for each HTTP probers.

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

4 participants