Description
Component(s)
processor/geoip
Is your feature request related to a problem? Please describe.
The initial proposal of the GeoIP processor was to work with the MaxMind GeoLite2 database to retrieve geolocation metadata. After discussions with the community, it was determined that the processor should be agnostic to the geolocation metadata provider. Therefore, it not strictly require a MaxMind database nor a license. This issue aims to track the proposal and implementation of this interface.
Any provider should be able to provide all attributes defined in #32663
Describe the solution you'd like
The interface shouldn't be exported, implementations should remain within the collector, for example, geoiprocessor/internal/provider/geoipprovider.go
:
// GeoIPProvider defines methods for obtaining the geographical location based on the provided IP address.
type GeoIPProvider interface {
// Location returns a set of attributes representing the geographical location for the given IP address. It requires a context for managing request lifetime.
Location(context.Context, net.IP) (attribute.Set, error)
}
Configuration
The user should be able to define multiple providers (e.g., for data fallback). The configuration could include a map of providers to be used:
type Config struct {
// Providers specifies the sources to extract geographical information about a given IP (e.g., GeoLite2).
Providers map[string]provider.Config
...
}
Similar to other components, the processor's factory will have access to a factory of providers, enabling it to create them on demand.
Describe alternatives you've considered
Another option is to define a more fine-grained interface based on the different types of location attributes the processor can add, thus improving the performance when only a subset of attributes is desired. For example:
// GeoIPProvider defines methods for obtaining the geographical location based on the provided IP address.
type GeoIPProvider interface {
// Country returns a set of attributes representing the country location for the given IP address.
Country(context.Context, net.IP) (attribute.Set, error)
// City returns a set of attributes representing the city location for the given IP address.
City(context.Context, net.IP) (attribute.Set, error)
// Isp returns a set of attributes representing the ISP for the given IP address.
Isp(context.Context, net.IP) (attribute.Set, error)
// Asn returns a set of attributes representing the AS for the given IP address.
Asn(context.Context, net.IP) (attribute.Set, error)
// Domain returns a set of attributes representing the domain for the given IP address.
Domain(context.Context, net.IP) (attribute.Set, error)
}
I find this approach impractical due to the numerous methods involved, which some providers might not support for retrieving all attributes. This limitaion could be resolved by adding a filter or namespace parameter:
// GeoIPProvider defines methods for obtaining the geographical location based on the provided IP address.
type GeoIPProvider interface {
// Location returns a set of attributes representing the geographical location for the given IP address. It requires a context for managing request lifetime. An optional list of namespaces can be provided to specify the desired attributes to retrieve (e.g city, country, asn, etc.).
Location(context.Context, net.IP, ...string) (attribute.Set, error)
}
Additional context
PoC: https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/33268/files
Please don't hesitate to ask if you need any modifications or clarifications. Any feedback or suggestions are highly appreciated.