mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
update APM reindex script (#30761)
This commit is contained in:
parent
4125c0f991
commit
00ed5eb5b5
1 changed files with 79 additions and 19 deletions
|
@ -94,9 +94,13 @@ export const apmReindexScript = `
|
|||
HashMap context = ctx._source.remove("context");
|
||||
if (context != null) {
|
||||
// context.process -> process
|
||||
if (context.containsKey("process")) {
|
||||
ctx._source.process = context.remove("process");
|
||||
ctx._source.process.args = ctx._source.process.remove("argv");
|
||||
def process = context.remove("process");
|
||||
if (process != null) {
|
||||
def args = process.remove("argv");
|
||||
if (args != null) {
|
||||
process.args = args;
|
||||
}
|
||||
ctx._source.process = process;
|
||||
}
|
||||
|
||||
// context.response -> http.response
|
||||
|
@ -121,8 +125,25 @@ export const apmReindexScript = `
|
|||
ctx._source.http.version = http_version;
|
||||
}
|
||||
|
||||
ctx._source.http.request = new HashMap();
|
||||
|
||||
// context.request.socket -> request.socket
|
||||
def socket = request.remove("socket");
|
||||
if (socket != null) {
|
||||
def add_socket = false;
|
||||
def new_socket = new HashMap();
|
||||
def remote_address = socket.remove("remote_address");
|
||||
if (remote_address != null) {
|
||||
add_socket = true;
|
||||
new_socket.remote_address = remote_address;
|
||||
}
|
||||
def encrypted = socket.remove("encrypted");
|
||||
if (encrypted != null) {
|
||||
add_socket = true;
|
||||
new_socket.encrypted = encrypted;
|
||||
}
|
||||
if (add_socket) {
|
||||
request.socket = new_socket;
|
||||
}
|
||||
}
|
||||
|
||||
// context.request.url -> url
|
||||
HashMap url = request.remove("url");
|
||||
|
@ -211,16 +232,18 @@ export const apmReindexScript = `
|
|||
}
|
||||
|
||||
// context.user.ip -> client.ip
|
||||
if (user.containsKey("ip")) {
|
||||
def userip = user.remove("ip");
|
||||
if (userip != null) {
|
||||
ctx._source.client = new HashMap();
|
||||
ctx._source.client.ip = user.remove("ip");
|
||||
ctx._source.client.ip = userip;
|
||||
}
|
||||
|
||||
// move user-agent info
|
||||
def ua = user.remove("user-agent");
|
||||
if (ua != null) {
|
||||
ctx._source.user_agent = new HashMap();
|
||||
// setting original and original.text is not possible in painless
|
||||
// as original is a keyword in ES template we cannot set it to a HashMap here,
|
||||
// as original is a keyword in ES template we cannot set it to a HashMap here,
|
||||
// so the following is the only possible solution:
|
||||
ctx._source.user_agent.original = ua.substring(0, Integer.min(1024, ua.length()));
|
||||
}
|
||||
|
@ -234,12 +257,18 @@ export const apmReindexScript = `
|
|||
def osminor = pua.remove("os_minor");
|
||||
def osmajor = pua.remove("os_major");
|
||||
def osname = pua.remove("os_name");
|
||||
if (osminor != null || osmajor != null || osname != null){
|
||||
ctx._source.user_agent.os = new HashMap();
|
||||
ctx._source.user_agent.os.full = os;
|
||||
ctx._source.user_agent.os.version = osmajor + "." + osminor;
|
||||
ctx._source.user_agent.os.name = osname;
|
||||
|
||||
def newos = new HashMap();
|
||||
if (os != null){
|
||||
newos.full = os;
|
||||
}
|
||||
if (osmajor != null || osminor != null){
|
||||
newos.version = osmajor + "." + osminor;
|
||||
}
|
||||
if (osname != null){
|
||||
newos.name = osname;
|
||||
}
|
||||
ctx._source.user_agent.os = newos;
|
||||
|
||||
def device = pua.remove("device");
|
||||
if (device != null){
|
||||
|
@ -247,15 +276,42 @@ export const apmReindexScript = `
|
|||
ctx._source.user_agent.device.name = device;
|
||||
}
|
||||
// not exactly reflecting 7.0, but the closes we can get
|
||||
def patch = pua.remove("patch");
|
||||
def minor = pua.remove("minor");
|
||||
def major = pua.remove("major");
|
||||
if (patch != null || minor != null || major != null){
|
||||
ctx._source.user_agent.version = major + "." + minor + "." + patch;
|
||||
if (major != null){
|
||||
def version = major;
|
||||
def minor = pua.remove("minor");
|
||||
if (minor != null){
|
||||
version += "." + minor;
|
||||
def patch = pua.remove("patch");
|
||||
if (patch != null){
|
||||
version += "." + patch
|
||||
}
|
||||
}
|
||||
ctx._source.user_agent.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
ctx._source.user = user;
|
||||
// remove unknown fields from user, like is_authenticated
|
||||
def add_user = false;
|
||||
def new_user = new HashMap();
|
||||
def email = user.remove("email");
|
||||
if (email != null) {
|
||||
add_user = true;
|
||||
new_user.email = email;
|
||||
}
|
||||
def id = user.remove("id");
|
||||
if (id != null) {
|
||||
add_user = true;
|
||||
new_user.id = String.valueOf(id);
|
||||
}
|
||||
def name = user.remove("name");
|
||||
if (name != null) {
|
||||
add_user = true;
|
||||
new_user.name = name;
|
||||
}
|
||||
if (add_user) {
|
||||
ctx._source.user = new_user;
|
||||
}
|
||||
}
|
||||
|
||||
// context.custom -> error,transaction,span.custom
|
||||
|
@ -273,6 +329,10 @@ export const apmReindexScript = `
|
|||
// context.db -> span.db
|
||||
def db = context.remove("db");
|
||||
if (db != null) {
|
||||
def db_user = db.remove("user");
|
||||
if (db_user != null) {
|
||||
db.user = ["name": db_user];
|
||||
}
|
||||
ctx._source.span.db = db;
|
||||
}
|
||||
|
||||
|
@ -300,7 +360,7 @@ export const apmReindexScript = `
|
|||
if (ts != null && !ctx._source.containsKey("timestamp")) {
|
||||
// add span.start to @timestamp for rum documents v1
|
||||
if (ctx._source.context.service.agent.name == "js-base" && ctx._source.span.start.containsKey("us")) {
|
||||
ts += ctx._source.span.start.us/1000;
|
||||
ts += ctx._source.span.start.us/1000;
|
||||
}
|
||||
}
|
||||
if (ctx._source.span.containsKey("hex_id")) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue