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

add geoip processor #365

Closed
wants to merge 2 commits into from
Closed

Conversation

DpoBoceka
Copy link
Contributor

hey, look what I've done.
Closes #277

Not sure If I handled closing handler to db right.

Have a look at it, please, and I'll add some tests if everything in order.

pipeline:
  processors: 
  - geoip:
      arg: "city"  # or "asn"
      base: "path/to/db"

@Jeffail
Copy link
Collaborator

Jeffail commented Feb 1, 2020

Hey @DpoBoceka, this looks good but I would rename the fields to be database and database_type.

@DpoBoceka DpoBoceka requested a review from Jeffail February 5, 2020 11:00
@DpoBoceka
Copy link
Contributor Author

@Jeffail, Is there anything else I should fix?

if err != nil {
return nil, err
}
return res, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Returning a *City type might cause issues downstream as it's a struct. If you don't want to map the entire struct into map[string]interface{} then I'll forgive the lazier approach of json.Marshal(res) into raw bytes and use part.Set. Considering we're doing a DB call here I don't think the performance impact is something to worry about.

Same goes for asnReader.

// GeoIP is a processor that looks up IP addresses.
type GeoIP struct {
parts []int
handler *geoip2.Reader
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you change this for a interface with the methods City and ASN then we can use a mock type for unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't exactly understand, could you clarify a couple of things for me, please?
I could use an interface for replacing current GeoIP.reader an mock it but in order for that test/code to work I would be forced to explicitly declare processor.Geoip, not by calling NewGeoIP, because this would fail https://github.com/Jeffail/benthos/pull/365/files#diff-a4df8555a7687abaed0682a67d09ea3dR114
Is it ok to omit test for NewGeoIP or there is another way to refactor that code?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah that's fine, I'm mostly interested in testing ProcessMessage so I'm fine with declaring the struct instead of using NewGeoIP.

@Jeffail
Copy link
Collaborator

Jeffail commented Feb 7, 2020

Hey @DpoBoceka, left some comments. Does a unit test here make any sense? Would be good to get some coverage here even if it's wrapping a mock implementation. I'm happy to do the docs when I have time.

@Jeffail
Copy link
Collaborator

Jeffail commented Sep 5, 2020

Hey @DpoBoceka, I think it makes sense to rework this into a bloblang method if you're open to that as it's much more flexible. I can take over if you don't have time.

@DpoBoceka
Copy link
Contributor Author

Hey @Jeffail, that would be just great.

If you don't mind implementing that yourself I'd be delightful as I need to invest some time in figuring out the bloblang internals( I didn't use benthos for quite a while now, hence absence of my activity)

@Jeffail
Copy link
Collaborator

Jeffail commented Jan 21, 2022

Merged from #1068

@Jeffail Jeffail closed this Jan 21, 2022
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.

add processor "GeoLite2"
2 participants