-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Script: fields API for IP mapped type #81396
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
Conversation
Adds support in the scripting fields API for the `ip` mapped type,
including the runtime script type.
Adds a new value object, `IPAddress`, to avoid exposing Java's
`InetAddress`. `InetAddress` may cause name resolution if whitelisted
improperly.
`field('ip')`, implemented by `IpDocValuesField` exposes:
`IPAddress get(IPAddress)`
`IPAddress get(int, IPAddress)`
`Iterator<IPAddress> iterator()`
`List asStrings()`
`String asString(String)`
`String asString(int, String)`
`IPAddress` exposes:
`boolean isV4()`
`boolean isV6()`
`String toString()`
Refs: elastic#79105
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
|
Hi @stu-elastic, I've created a changelog YAML for you. |
jdconrad
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Please do not commit before addressing the plumbing comment. It's also a huge bummer about how there's two different ways we store IP addresses. I wonder if this is something that can be addressed in the future.
| @Override | ||
| public DocValuesField<?> getScriptField(String name) { | ||
| return new DelegateDocValuesField(new Strings(new IpSupplier(getBytesValues())), name); | ||
| return new IpDocValuesField(getBytesValues(), name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take in a ToScriptField and follow our standard plumbing pattern to this point. I think there's a real possibility this may be required for source fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, will fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, done.
| return builder.apply(lower, upper); | ||
| } | ||
|
|
||
| public static final class IpScriptDocValues extends ScriptDocValues<String> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for clarity, this all can be deleted because we use the other version now for doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved it to IpDocValuesField.SortedSetIpSupplier. Seemed to make more sense there.
| } | ||
|
|
||
| public boolean isV4() { | ||
| return address instanceof Inet4Address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big thumbs up for this utility method along with the v6. Annoying that the Java API is like this. (Nothing actionable, just like this solution.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I had to provide these.
Without these two methods there would be no way for users to determine the version of address.
Adds support in the scripting fields API for the
ipmapped type,including the runtime script type.
Adds a new value object,
IPAddress, to avoid exposing Java'sInetAddress.InetAddressmay cause name resolution if whitelistedimproperly.
field('ip'), implemented byIpDocValuesFieldexposes:IPAddress get(IPAddress)IPAddress get(int, IPAddress)Iterator<IPAddress> iterator()List asStrings()String asString(String)String asString(int, String)IPAddressexposes:boolean isV4()boolean isV6()String toString()Refs: #79105