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

Support for exclude include #212

Merged
merged 11 commits into from
Jul 9, 2018
Merged

Support for exclude include #212

merged 11 commits into from
Jul 9, 2018

Conversation

michalpristas
Copy link
Member

@michalpristas michalpristas commented Jul 4, 2018

I was thinking about two options here, first one with strong ordering and first rule matching wins.
The second one a bit complicated to implement but easier to use. No ordering reqs for user to take into account.

I went with second as it is more fun to write and the user is happier.

Based on filter.conf file proxy decides which modules to process and which not.
If there is '-' rule for module or one of its parents it will not process the module and won't report cache miss to Olympus either.

Example

- a
+ a/b/c

this will process:

  • d
  • a/b/c
  • a/b/c/d

wont process

  • a
  • a/b

Second example

-
+ a/b/c

notice - with nothing after it - it means global exclude
This won't process everything except a/b/c and its children (a/b/c/d)

So the way it is decided for a/b/c/d is to check rule for a/b/c/d and then iterate upwards until non-default rule is found (rules: Default, Exclude, Include)

Fixes #96

}

func getConfigLines() ([]string, error) {
configName := configurationFileName
Copy link
Member Author

Choose a reason for hiding this comment

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

this i will update with new config package once it's in

@codecov-io
Copy link

codecov-io commented Jul 4, 2018

Codecov Report

Merging #212 into master will decrease coverage by 0.46%.
The diff coverage is 58.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #212      +/-   ##
==========================================
- Coverage    45.8%   45.34%   -0.47%     
==========================================
  Files          84       88       +4     
  Lines        2039     2245     +206     
==========================================
+ Hits          934     1018      +84     
- Misses        990     1111     +121     
- Partials      115      116       +1
Impacted Files Coverage Δ
pkg/module/errors.go 0% <0%> (ø)
cmd/proxy/actions/cache_miss_reporter.go 0% <0%> (ø) ⬆️
cmd/proxy/actions/cache_miss_fetcher.go 0% <0%> (ø) ⬆️
cmd/proxy/actions/app_proxy.go 100% <100%> (ø) ⬆️
cmd/proxy/actions/cache_miss_handler.go 2.77% <11.11%> (-0.35%) ⬇️
cmd/proxy/actions/app.go 66.66% <50%> (+0.46%) ⬆️
pkg/module/filter.go 70.94% <70.94%> (ø)
pkg/module/parser.go 0% <0%> (ø)
pkg/module/module.go 0% <0%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bcc7272...81b9814. Read the comment docs.

Copy link
Member

@arschles arschles left a comment

Choose a reason for hiding this comment

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

❤️ !

A few administrative comments @michalpristas

)

// ModFilter is a filter of modules
type ModFilter struct {
Copy link
Member

Choose a reason for hiding this comment

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

can you name this Filter? that way, the type will read mod.Filter when it's used - instead of the redundant mod.ModFilter

// -
// + github.com/a
// will exclude all items from communication except github.com/a
func NewModFilter() *ModFilter {
Copy link
Member

Choose a reason for hiding this comment

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

can you name this NewFilter()? then the call will be mod.NewFilter() which will be less redundant

Copy link
Member

Choose a reason for hiding this comment

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

also, do you mind adding a note here that this struct is not concurrency safe? not sure if that matters right now, but it'll be nice to have that later on at least as a reminder 😄

return func(args worker.Args) (err error) {
module, version, err := parseArgs(args)
if err != nil {
return err
}

if !mf.ShouldProcess(module) {
return fmt.Errorf("Module %s is excluded", module)
Copy link
Member

Choose a reason for hiding this comment

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

can you make this an error type so we can check for it in other places?

"github.com/gomods/athens/pkg/paths"
"github.com/gomods/athens/pkg/storage"
)

func cacheMissHandler(next buffalo.Handler, w worker.Worker) buffalo.Handler {
func cacheMissHandler(next buffalo.Handler, w worker.Worker, mf *modfilter.ModFilter) buffalo.Handler {
return func(c buffalo.Context) error {
nextErr := next(c)
Copy link
Member

Choose a reason for hiding this comment

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

wouldn't we want to check if the module should not be processed before we go to the next step?

Copy link
Member

@arschles arschles left a comment

Choose a reason for hiding this comment

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

@michalpristas looks great, thanks!

// If no filename is specified it fallbacks to 'filter.conf'
func IncludeExcludeFileName() string {
return envy.Get("ATHENS_FILTER_FILENAME", defaultConfigurationFileName)
}
Copy link
Member

Choose a reason for hiding this comment

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

I ❤️ this env package!

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.

3 participants