Merge "Added timestamp field, changed duration field type; improve doc"

This commit is contained in:
Zuul 2021-01-15 14:54:36 +00:00 committed by Gerrit Code Review
commit a6c780a4b9
4 changed files with 16 additions and 4 deletions

View File

@ -88,9 +88,9 @@ Example of driver configuration:
.. code-block:: text
[connection elasticsearch]
driver=elasticsearch
uri=https://managesf.sftests.com:9200
[connection elasticsearch]
driver=elasticsearch
uri=https://managesf.sftests.com:9200
Additional parameters to authenticate to the Elasticsearch server you

View File

@ -14,6 +14,7 @@
import textwrap
import time
import types
import sqlalchemy as sa
@ -703,6 +704,13 @@ class TestElasticsearchConnection(AnsibleZuulTestCase):
build_doc['job_returned_vars'], {'foo': 'bar'})
self.assertEqual(self.history[0].uuid, build_doc['uuid'])
self.assertIn('duration', build_doc)
self.assertTrue(type(build_doc['duration']) is int)
doc_gen = self.scheds.first.connections.connections[
'elasticsearch'].gen(indexed_docs, index)
self.assertIsInstance(doc_gen, types.GeneratorType)
self.assertTrue('@timestamp' in list(doc_gen)[0]['_source'])
def test_elasticsearch_secret_leak(self):
expected_secret = [{

View File

@ -15,6 +15,7 @@
import yaml
import logging
from datetime import datetime
from elasticsearch import Elasticsearch
from elasticsearch.client import IndicesClient
from elasticsearch.helpers import bulk
@ -32,6 +33,7 @@ class ElasticsearchConnection(BaseConnection):
"build_type": {"type": "keyword"},
"result": {"type": "keyword"},
"duration": {"type": "integer"},
"@timestamp": {"type": "date"},
# BuildSet type specific attributes
"zuul_ref": {"type": "keyword"},
"pipeline": {"type": "keyword"},
@ -108,6 +110,8 @@ class ElasticsearchConnection(BaseConnection):
def gen(self, it, index):
for source in it:
d = {}
source['@timestamp'] = datetime.fromtimestamp(
int(source['start_time'])).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
d['_index'] = index
d['_type'] = 'zuul'
d['_op_type'] = 'index'

View File

@ -86,7 +86,7 @@ class ElasticsearchReporter(BaseReporter):
"result": result,
"start_time": str(start_time),
"end_time": str(end_time),
"duration": str(end_time - start_time),
"duration": end_time - start_time,
"voting": build.job.voting,
"log_url": url,
}