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

[7.x] update APM migration reindex script #34801

Merged
merged 1 commit into from Apr 12, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 35 additions & 2 deletions x-pack/plugins/upgrade_assistant/server/lib/apm/index.ts
Expand Up @@ -62,7 +62,7 @@ export const isLegacyApmIndex = (
// source: https://github.com/elastic/apm-integration-testing/blob/master/tests/server/test_upgrade.py
export const apmReindexScript = `
// add ecs version
ctx._source.ecs = ['version': '1.0.0-beta2'];
ctx._source.ecs = ['version': '1.1.0-dev'];
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the dev pre-release tag for?

Copy link
Member Author

Choose a reason for hiding this comment

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

that matches the version of the published ecs schema 7.0.1 is aligned with. This is something inherited from libbeat, not directly set by apm-server


// beat -> observer
def beat = ctx._source.remove("beat");
Expand Down Expand Up @@ -129,6 +129,23 @@ export const apmReindexScript = `
ctx._source.http.version = http_version;
}

if (request.containsKey("headers")) {
// copy user-agent header
def ua;
for (entry in request["headers"].entrySet()) {
if (entry.getKey().toLowerCase() == "user-agent") {
ua = entry.getValue();
}
}
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,
// so the following is the only possible solution:
ctx._source.user_agent.original = ua.substring(0, Integer.min(1024, ua.length()));
}
}

// context.request.socket -> request.socket
def socket = request.remove("socket");
if (socket != null) {
Expand Down Expand Up @@ -202,7 +219,6 @@ export const apmReindexScript = `
ctx._source.http.request.body = new HashMap();
ctx._source.http.request.body.original = body;
}

}

// bump timestamp.us by span.start.us for spans
Expand Down Expand Up @@ -256,6 +272,7 @@ export const apmReindexScript = `
}

// move user-agent info
// this will overwrite the value from http.request.headers if set
def ua = user.remove("user-agent");
if (ua != null) {
ctx._source.user_agent = new HashMap();
Expand Down Expand Up @@ -384,6 +401,22 @@ export const apmReindexScript = `
}
}

// per https://github.com/elastic/apm/issues/21
// if kubernetes.node.name is set, copy it to host.hostname
// else if other kubernetes.* is set, remove host.hostname
// else leave it alone
// relies on system.hostname -> host.hostname already happening earlier in this script
if (ctx._source.kubernetes?.node?.name != null) {
if (! ctx._source.containsKey("host")) {
ctx._source.host = new HashMap();
}
ctx._source.host.hostname = ctx._source.kubernetes.node.name;
} else if (ctx._source.containsKey("kubernetes")) {
if (ctx._source.host?.hostname != null) {
ctx._source.host.remove("hostname");
}
}

if (ctx._source.processor.event == "span") {
def hex_id = ctx._source.span.remove("hex_id");
def span_id = ctx._source.span.remove("id");
Expand Down