-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Display automatic deployment annotations correctly #102020
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,181 @@ | ||||||||||
/* | ||||||||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||||||||||
* or more contributor license agreements. Licensed under the Elastic License | ||||||||||
* 2.0; you may not use this file except in compliance with the Elastic License | ||||||||||
* 2.0. | ||||||||||
*/ | ||||||||||
|
||||||||||
import expect from '@kbn/expect'; | ||||||||||
import { APIReturnType } from '../../../../plugins/apm/public/services/rest/createCallApmApi'; | ||||||||||
import { createApmApiSupertest } from '../../common/apm_api_supertest'; | ||||||||||
import { FtrProviderContext } from '../../common/ftr_provider_context'; | ||||||||||
import { registry } from '../../common/registry'; | ||||||||||
|
||||||||||
export default function annotationApiTests({ getService }: FtrProviderContext) { | ||||||||||
const supertestRead = createApmApiSupertest(getService('supertestAsApmReadUser')); | ||||||||||
const es = getService('es'); | ||||||||||
|
||||||||||
const dates = [ | ||||||||||
new Date('2021-02-01T00:00:00.000Z'), | ||||||||||
new Date('2021-02-01T01:00:00.000Z'), | ||||||||||
new Date('2021-02-01T02:00:00.000Z'), | ||||||||||
new Date('2021-02-01T03:00:00.000Z'), | ||||||||||
]; | ||||||||||
|
||||||||||
const indexName = 'apm-8.0.0-transaction'; | ||||||||||
|
||||||||||
registry.when( | ||||||||||
'Derived deployment annotations with a basic license', | ||||||||||
{ config: 'basic', archives: [] }, | ||||||||||
() => { | ||||||||||
describe('when there are multiple service versions', () => { | ||||||||||
let response: APIReturnType<'GET /api/apm/services/{serviceName}/annotation/search'>; | ||||||||||
|
||||||||||
before(async () => { | ||||||||||
const { body: indexExists } = await es.indices.exists({ index: indexName }); | ||||||||||
if (indexExists) { | ||||||||||
await es.indices.delete({ | ||||||||||
index: indexName, | ||||||||||
}); | ||||||||||
} | ||||||||||
|
||||||||||
await es.indices.create({ | ||||||||||
index: indexName, | ||||||||||
body: { | ||||||||||
mappings: { | ||||||||||
properties: { | ||||||||||
service: { | ||||||||||
properties: { | ||||||||||
name: { | ||||||||||
type: 'keyword', | ||||||||||
}, | ||||||||||
version: { | ||||||||||
type: 'keyword', | ||||||||||
}, | ||||||||||
environment: { | ||||||||||
type: 'keyword', | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
transaction: { | ||||||||||
properties: { | ||||||||||
type: { | ||||||||||
type: 'keyword', | ||||||||||
}, | ||||||||||
duration: { | ||||||||||
type: 'long', | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
observer: { | ||||||||||
properties: { | ||||||||||
version_major: { | ||||||||||
type: 'byte', | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
processor: { | ||||||||||
properties: { | ||||||||||
event: { | ||||||||||
type: 'keyword', | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
}); | ||||||||||
|
||||||||||
const docs = dates.flatMap((date, index) => { | ||||||||||
const defaults = { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: naming
Suggested change
or
Suggested change
|
||||||||||
transaction: { | ||||||||||
type: 'request', | ||||||||||
duration: 1000000, | ||||||||||
}, | ||||||||||
|
||||||||||
service: { | ||||||||||
name: 'opbeans-java', | ||||||||||
environment: 'production', | ||||||||||
version: index + 1, | ||||||||||
}, | ||||||||||
observer: { | ||||||||||
version_major: 8, | ||||||||||
}, | ||||||||||
processor: { | ||||||||||
event: 'transaction', | ||||||||||
}, | ||||||||||
}; | ||||||||||
return [ | ||||||||||
{ | ||||||||||
...defaults, | ||||||||||
'@timestamp': date.toISOString(), | ||||||||||
}, | ||||||||||
{ | ||||||||||
...defaults, | ||||||||||
'@timestamp': new Date(date.getTime() + 30000), | ||||||||||
}, | ||||||||||
{ | ||||||||||
...defaults, | ||||||||||
'@timestamp': new Date(date.getTime() + 60000), | ||||||||||
}, | ||||||||||
]; | ||||||||||
}); | ||||||||||
|
||||||||||
await es.bulk({ | ||||||||||
index: indexName, | ||||||||||
body: docs.flatMap((doc) => [{ index: {} }, doc]), | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you adding an empty doc for every annotation doc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not, I think? This is how the bulk API works: an operation (in this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes. i forgot that's how it works. So weird that the ES client doesn't abstract that away if you ask me. |
||||||||||
refresh: true, | ||||||||||
}); | ||||||||||
|
||||||||||
response = ( | ||||||||||
await supertestRead({ | ||||||||||
endpoint: 'GET /api/apm/services/{serviceName}/annotation/search', | ||||||||||
params: { | ||||||||||
path: { | ||||||||||
serviceName: 'opbeans-java', | ||||||||||
}, | ||||||||||
query: { | ||||||||||
start: dates[1].toISOString(), | ||||||||||
end: dates[2].toISOString(), | ||||||||||
environment: 'production', | ||||||||||
}, | ||||||||||
}, | ||||||||||
}) | ||||||||||
).body; | ||||||||||
}); | ||||||||||
|
||||||||||
it('annotations are displayed for the service versions in the given time range', async () => { | ||||||||||
expect(response.annotations.length).to.be(2); | ||||||||||
expect(response.annotations[0]['@timestamp']).to.be(dates[1].getTime()); | ||||||||||
expect(response.annotations[1]['@timestamp']).to.be(dates[2].getTime()); | ||||||||||
|
||||||||||
expectSnapshot(response.annotations[0]).toMatchInline(` | ||||||||||
Object { | ||||||||||
"@timestamp": 1612141200000, | ||||||||||
"id": "2", | ||||||||||
"text": "2", | ||||||||||
"type": "version", | ||||||||||
} | ||||||||||
`); | ||||||||||
}); | ||||||||||
|
||||||||||
it('annotations are not displayed for the service versions outside of the given time range', () => { | ||||||||||
expect( | ||||||||||
response.annotations.some((annotation) => { | ||||||||||
return ( | ||||||||||
annotation['@timestamp'] !== dates[0].getTime() && | ||||||||||
annotation['@timestamp'] !== dates[2].getTime() | ||||||||||
); | ||||||||||
}) | ||||||||||
); | ||||||||||
}); | ||||||||||
|
||||||||||
after(async () => { | ||||||||||
await es.indices.delete({ | ||||||||||
index: indexName, | ||||||||||
}); | ||||||||||
}); | ||||||||||
}); | ||||||||||
} | ||||||||||
); | ||||||||||
} |
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.
Do you really need to create the index before calling the API? I thought that happened automatically
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.
If you create an index template yes, otherwise you have to create it manually right?