├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTORS ├── Gemfile ├── LICENSE ├── NOTICE.TXT ├── README.md ├── Rakefile ├── docs └── index.asciidoc ├── lib └── logstash │ └── filters │ └── elapsed.rb ├── logstash-filter-elapsed.gemspec └── spec └── filters └── elapsed_spec.rb /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Logstash 2 | 3 | All contributions are welcome: ideas, patches, documentation, bug reports, 4 | complaints, etc! 5 | 6 | Programming is not a required skill, and there are many ways to help out! 7 | It is more important to us that you are able to contribute. 8 | 9 | That said, some basic guidelines, which you are free to ignore :) 10 | 11 | ## Want to learn? 12 | 13 | Want to lurk about and see what others are doing with Logstash? 14 | 15 | * The irc channel (#logstash on irc.freenode.org) is a good place for this 16 | * The [forum](https://discuss.elastic.co/c/logstash) is also 17 | great for learning from others. 18 | 19 | ## Got Questions? 20 | 21 | Have a problem you want Logstash to solve for you? 22 | 23 | * You can ask a question in the [forum](https://discuss.elastic.co/c/logstash) 24 | * Alternately, you are welcome to join the IRC channel #logstash on 25 | irc.freenode.org and ask for help there! 26 | 27 | ## Have an Idea or Feature Request? 28 | 29 | * File a ticket on [GitHub](https://github.com/elastic/logstash/issues). Please remember that GitHub is used only for issues and feature requests. If you have a general question, the [forum](https://discuss.elastic.co/c/logstash) or IRC would be the best place to ask. 30 | 31 | ## Something Not Working? Found a Bug? 32 | 33 | If you think you found a bug, it probably is a bug. 34 | 35 | * If it is a general Logstash or a pipeline issue, file it in [Logstash GitHub](https://github.com/elasticsearch/logstash/issues) 36 | * If it is specific to a plugin, please file it in the respective repository under [logstash-plugins](https://github.com/logstash-plugins) 37 | * or ask the [forum](https://discuss.elastic.co/c/logstash). 38 | 39 | # Contributing Documentation and Code Changes 40 | 41 | If you have a bugfix or new feature that you would like to contribute to 42 | logstash, and you think it will take more than a few minutes to produce the fix 43 | (ie; write code), it is worth discussing the change with the Logstash users and developers first! You can reach us via [GitHub](https://github.com/elastic/logstash/issues), the [forum](https://discuss.elastic.co/c/logstash), or via IRC (#logstash on freenode irc) 44 | Please note that Pull Requests without tests will not be merged. If you would like to contribute but do not have experience with writing tests, please ping us on IRC/forum or create a PR and ask our help. 45 | 46 | ## Contributing to plugins 47 | 48 | Check our [documentation](https://www.elastic.co/guide/en/logstash/current/contributing-to-logstash.html) on how to contribute to plugins or write your own! It is super easy! 49 | 50 | ## Contribution Steps 51 | 52 | 1. Test your changes! [Run](https://github.com/elastic/logstash#testing) the test suite 53 | 2. Please make sure you have signed our [Contributor License 54 | Agreement](https://www.elastic.co/contributor-agreement/). We are not 55 | asking you to assign copyright to us, but to give us the right to distribute 56 | your code without restriction. We ask this of all contributors in order to 57 | assure our users of the origin and continuing existence of the code. You 58 | only need to sign the CLA once. 59 | 3. Send a pull request! Push your changes to your fork of the repository and 60 | [submit a pull 61 | request](https://help.github.com/articles/using-pull-requests). In the pull 62 | request, describe what your changes do and mention any bugs/issues related 63 | to the pull request. 64 | 65 | 66 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please post all product and debugging questions on our [forum](https://discuss.elastic.co/c/logstash). Your questions will reach our wider community members there, and if we confirm that there is a bug, then we can open a new issue here. 2 | 3 | For all general issues, please provide the following details for fast resolution: 4 | 5 | - Version: 6 | - Operating System: 7 | - Config File (if you have sensitive info, please remove it): 8 | - Sample Data: 9 | - Steps to Reproduce: 10 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thanks for contributing to Logstash! If you haven't already signed our CLA, here's a handy link: https://www.elastic.co/contributor-agreement/ 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | .bundle 4 | vendor 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | import: 2 | - logstash-plugins/.ci:travis/travis.yml@1.x -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 4.1.0 2 | - Added option `keep_start_event` to manage what to do when several messages matched 3 | as a start event were received before the end event for the specified ID. 4 | [#35](https://github.com/logstash-plugins/logstash-filter-elapsed/pull/35) 5 | 6 | ## 4.0.5 7 | - Fixed default to true for the periodic_flush option in order for the caching expiration to work [#36](https://github.com/logstash-plugins/logstash-filter-elapsed/pull/36) 8 | 9 | ## 4.0.4 10 | - Update gemspec summary 11 | 12 | ## 4.0.3 13 | - Fix some documentation issues 14 | 15 | # 4.0.1 16 | - Docs: Fix docgen issues by removing extraneous comments 17 | 18 | # 4.0.0 19 | - Use the new Event Api used in v5.0.0+ 20 | 21 | # 3.0.2 22 | - Depend on logstash-core-plugin-api instead of logstash-core, removing the need to mass update plugins on major releases of logstash 23 | 24 | # 3.0.1 25 | - New dependency requirements for logstash-core for the 5.0 release 26 | 27 | ## 3.0.0 28 | - Elasticsearch 2.0 does not allow field names with dots in them. This is a 29 | breaking change which replaces the `.` with an underscore, `_` 30 | 31 | ## 2.0.0 32 | - Plugins were updated to follow the new shutdown semantic, this mainly allows Logstash to instruct input plugins to terminate gracefully, 33 | instead of using Thread.raise on the plugins' threads. Ref: https://github.com/elastic/logstash/pull/3895 34 | - Dependency on logstash-core update to 2.0 35 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | The following is a list of people who have contributed ideas, code, bug 2 | reports, or in general have helped logstash along its way. 3 | 4 | Contributors: 5 | * Aaron Mildenstein (untergeek) 6 | * Andrea Forni (andreaforni) 7 | * Pier-Hugues Pellerin (ph) 8 | * Richard Pijnenburg (electrical) 9 | * Suyog Rao (suyograo) 10 | * karsaroth 11 | * Pere Urbón (purbon) 12 | * Colin Surprenant (colinsurprenant) 13 | 14 | Note: If you've sent us patches, bug reports, or otherwise contributed to 15 | Logstash, and you aren't on the list above and want to be, please let us know 16 | and we'll make sure you're here. Contributions from folks like you are what make 17 | open source awesome. 18 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash" 6 | use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1" 7 | 8 | if Dir.exist?(logstash_path) && use_logstash_source 9 | gem 'logstash-core', :path => "#{logstash_path}/logstash-core" 10 | gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api" 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2020 Elastic and contributors 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /NOTICE.TXT: -------------------------------------------------------------------------------- 1 | Elasticsearch 2 | Copyright 2012-2015 Elasticsearch 3 | 4 | This product includes software developed by The Apache Software 5 | Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Logstash Plugin 2 | 3 | [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-filter-elapsed.svg)](https://travis-ci.com/logstash-plugins/logstash-filter-elapsed) 4 | 5 | This is a plugin for [Logstash](https://github.com/elastic/logstash). 6 | 7 | It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way. 8 | 9 | ## Documentation 10 | 11 | Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/). 12 | 13 | - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive 14 | - For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide 15 | 16 | ## Need Help? 17 | 18 | Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum. 19 | 20 | ## Developing 21 | 22 | ### 1. Plugin Developement and Testing 23 | 24 | #### Code 25 | - To get started, you'll need JRuby with the Bundler gem installed. 26 | 27 | - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example). 28 | 29 | - Install dependencies 30 | ```sh 31 | bundle install 32 | ``` 33 | 34 | #### Test 35 | 36 | - Update your dependencies 37 | 38 | ```sh 39 | bundle install 40 | ``` 41 | 42 | - Run tests 43 | 44 | ```sh 45 | bundle exec rspec 46 | ``` 47 | 48 | ### 2. Running your unpublished Plugin in Logstash 49 | 50 | #### 2.1 Run in a local Logstash clone 51 | 52 | - Edit Logstash `Gemfile` and add the local plugin path, for example: 53 | ```ruby 54 | gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome" 55 | ``` 56 | - Install plugin 57 | ```sh 58 | # Logstash 2.3 and higher 59 | bin/logstash-plugin install --no-verify 60 | 61 | # Prior to Logstash 2.3 62 | bin/plugin install --no-verify 63 | 64 | ``` 65 | - Run Logstash with your plugin 66 | ```sh 67 | bin/logstash -e 'filter {awesome {}}' 68 | ``` 69 | At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash. 70 | 71 | #### 2.2 Run in an installed Logstash 72 | 73 | You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using: 74 | 75 | - Build your plugin gem 76 | ```sh 77 | gem build logstash-filter-awesome.gemspec 78 | ``` 79 | - Install the plugin from the Logstash home 80 | ```sh 81 | # Logstash 2.3 and higher 82 | bin/logstash-plugin install --no-verify 83 | 84 | # Prior to Logstash 2.3 85 | bin/plugin install --no-verify 86 | 87 | ``` 88 | - Start Logstash and proceed to test the plugin 89 | 90 | ## Contributing 91 | 92 | All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin. 93 | 94 | Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here. 95 | 96 | It is more important to the community that you are able to contribute. 97 | 98 | For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file. -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | @files=[] 2 | 3 | task :default do 4 | system("rake -T") 5 | end 6 | 7 | require "logstash/devutils/rake" 8 | -------------------------------------------------------------------------------- /docs/index.asciidoc: -------------------------------------------------------------------------------- 1 | :plugin: elapsed 2 | :type: filter 3 | 4 | /////////////////////////////////////////// 5 | START - GENERATED VARIABLES, DO NOT EDIT! 6 | /////////////////////////////////////////// 7 | :version: %VERSION% 8 | :release_date: %RELEASE_DATE% 9 | :changelog_url: %CHANGELOG_URL% 10 | :include_path: ../../../../logstash/docs/include 11 | /////////////////////////////////////////// 12 | END - GENERATED VARIABLES, DO NOT EDIT! 13 | /////////////////////////////////////////// 14 | 15 | [id="plugins-{type}s-{plugin}"] 16 | 17 | === Elapsed filter plugin 18 | 19 | include::{include_path}/plugin_header.asciidoc[] 20 | 21 | ==== Description 22 | 23 | The elapsed filter tracks a pair of start/end events and uses their 24 | timestamps to calculate the elapsed time between them. 25 | 26 | The filter has been developed to track the execution time of processes and 27 | other long tasks. 28 | 29 | The configuration looks like this: 30 | [source,ruby] 31 | filter { 32 | elapsed { 33 | start_tag => "start event tag" 34 | end_tag => "end event tag" 35 | unique_id_field => "id field name" 36 | timeout => seconds 37 | new_event_on_match => true/false 38 | } 39 | } 40 | 41 | The events managed by this filter must have some particular properties. 42 | The event describing the start of the task (the "start event") must contain 43 | a tag equal to `start_tag`. On the other side, the event describing the end 44 | of the task (the "end event") must contain a tag equal to `end_tag`. Both 45 | these two kinds of event need to own an ID field which identify uniquely that 46 | particular task. The name of this field is stored in `unique_id_field`. 47 | 48 | You can use a Grok filter to prepare the events for the elapsed filter. 49 | An example of configuration can be: 50 | [source,ruby] 51 | filter { 52 | grok { 53 | match => { "message" => "%{TIMESTAMP_ISO8601} START id: (?.*)" } 54 | add_tag => [ "taskStarted" ] 55 | } 56 | 57 | grok { 58 | match => { "message" => "%{TIMESTAMP_ISO8601} END id: (?.*)" } 59 | add_tag => [ "taskTerminated" ] 60 | } 61 | 62 | elapsed { 63 | start_tag => "taskStarted" 64 | end_tag => "taskTerminated" 65 | unique_id_field => "task_id" 66 | } 67 | } 68 | 69 | The elapsed filter collects all the "start events". If two, or more, "start 70 | events" have the same ID, only the first one is recorded, the others are 71 | discarded. 72 | 73 | When an "end event" matching a previously collected "start event" is 74 | received, there is a match. The configuration property `new_event_on_match` 75 | tells where to insert the elapsed information: they can be added to the 76 | "end event" or a new "match event" can be created. Both events store the 77 | following information: 78 | 79 | * the tags `elapsed` and `elapsed_match` 80 | * the field `elapsed_time` with the difference, in seconds, between 81 | the two events timestamps 82 | * an ID filed with the task ID 83 | * the field `elapsed_timestamp_start` with the timestamp of the start event 84 | 85 | If the "end event" does not arrive before "timeout" seconds, the 86 | "start event" is discarded and an "expired event" is generated. This event 87 | contains: 88 | 89 | * the tags `elapsed` and `elapsed_expired_error` 90 | * a field called `elapsed_time` with the age, in seconds, of the 91 | "start event" 92 | * an ID filed with the task ID 93 | * the field `elapsed_timestamp_start` with the timestamp of the "start event" 94 | 95 | 96 | [id="plugins-{type}s-{plugin}-options"] 97 | ==== Elapsed Filter Configuration Options 98 | 99 | This plugin supports the following configuration options plus the <> described later. 100 | 101 | [cols="<,<,<",options="header",] 102 | |======================================================================= 103 | |Setting |Input type|Required 104 | | <> |<>|Yes 105 | | <> |<>|No 106 | | <> |<>|Yes 107 | | <> |<>|No 108 | | <> |<>|Yes 109 | | <> |<>|No 110 | |======================================================================= 111 | 112 | Also see <> for a list of options supported by all 113 | filter plugins. 114 | 115 |   116 | 117 | [id="plugins-{type}s-{plugin}-end_tag"] 118 | ===== `end_tag` 119 | 120 | * This is a required setting. 121 | * Value type is <> 122 | * There is no default value for this setting. 123 | 124 | The name of the tag identifying the "end event" 125 | 126 | [id="plugins-{type}s-{plugin}-new_event_on_match"] 127 | ===== `new_event_on_match` 128 | 129 | * Value type is <> 130 | * Default value is `false` 131 | 132 | This property manage what to do when an "end event" matches a "start event". 133 | If it's set to `false` (default value), the elapsed information are added 134 | to the "end event"; if it's set to `true` a new "match event" is created. 135 | 136 | [id="plugins-{type}s-{plugin}-start_tag"] 137 | ===== `start_tag` 138 | 139 | * This is a required setting. 140 | * Value type is <> 141 | * There is no default value for this setting. 142 | 143 | The name of the tag identifying the "start event" 144 | 145 | [id="plugins-{type}s-{plugin}-timeout"] 146 | ===== `timeout` 147 | 148 | * Value type is <> 149 | * Default value is `1800` 150 | 151 | The amount of seconds after an "end event" can be considered lost. 152 | The corresponding "start event" is discarded and an "expired event" 153 | is generated. The default value is 30 minutes (1800 seconds). 154 | 155 | [id="plugins-{type}s-{plugin}-unique_id_field"] 156 | ===== `unique_id_field` 157 | 158 | * This is a required setting. 159 | * Value type is <> 160 | * There is no default value for this setting. 161 | 162 | The name of the field containing the task ID. 163 | This value must uniquely identify the task in the system, otherwise 164 | it's impossible to match the couple of events. 165 | 166 | [id="plugins-{type}s-{plugin}-keep_start_event"] 167 | ===== `keep_start_event` 168 | 169 | * Value type is <> 170 | * Default value is `first` 171 | 172 | This property manages what to do when several events matched as a start one 173 | were received before the end event for the specified ID. There are two 174 | supported values: `first` or `last`. If it's set to `first` (default value), 175 | the first event matched as a start will be used; if it's set to `last`, 176 | the last one will be used. 177 | 178 | 179 | [id="plugins-{type}s-{plugin}-common-options"] 180 | include::{include_path}/{type}.asciidoc[] -------------------------------------------------------------------------------- /lib/logstash/filters/elapsed.rb: -------------------------------------------------------------------------------- 1 | require "logstash/filters/base" 2 | require "logstash/namespace" 3 | require 'thread' 4 | require 'socket' 5 | 6 | # The elapsed filter tracks a pair of start/end events and uses their 7 | # timestamps to calculate the elapsed time between them. 8 | # 9 | # The filter has been developed to track the execution time of processes and 10 | # other long tasks. 11 | # 12 | # The configuration looks like this: 13 | # [source,ruby] 14 | # filter { 15 | # elapsed { 16 | # start_tag => "start event tag" 17 | # end_tag => "end event tag" 18 | # unique_id_field => "id field name" 19 | # timeout => seconds 20 | # new_event_on_match => true/false 21 | # } 22 | # } 23 | # 24 | # The events managed by this filter must have some particular properties. 25 | # The event describing the start of the task (the "start event") must contain 26 | # a tag equal to `start_tag`. On the other side, the event describing the end 27 | # of the task (the "end event") must contain a tag equal to `end_tag`. Both 28 | # these two kinds of event need to own an ID field which identify uniquely that 29 | # particular task. The name of this field is stored in `unique_id_field`. 30 | # 31 | # You can use a Grok filter to prepare the events for the elapsed filter. 32 | # An example of configuration can be: 33 | # [source,ruby] 34 | # filter { 35 | # grok { 36 | # match => { "message" => "%{TIMESTAMP_ISO8601} START id: (?.*)" } 37 | # add_tag => [ "taskStarted" ] 38 | # } 39 | # 40 | # grok { 41 | # match => { "message" => "%{TIMESTAMP_ISO8601} END id: (?.*)" } 42 | # add_tag => [ "taskTerminated" ] 43 | # } 44 | # 45 | # elapsed { 46 | # start_tag => "taskStarted" 47 | # end_tag => "taskTerminated" 48 | # unique_id_field => "task_id" 49 | # } 50 | # } 51 | # 52 | # The elapsed filter collects all the "start events". If two, or more, "start 53 | # events" have the same ID, only the first one is recorded, the others are 54 | # discarded. 55 | # 56 | # When an "end event" matching a previously collected "start event" is 57 | # received, there is a match. The configuration property `new_event_on_match` 58 | # tells where to insert the elapsed information: they can be added to the 59 | # "end event" or a new "match event" can be created. Both events store the 60 | # following information: 61 | # 62 | # * the tags `elapsed` and `elapsed_match` 63 | # * the field `elapsed_time` with the difference, in seconds, between 64 | # the two events timestamps 65 | # * an ID filed with the task ID 66 | # * the field `elapsed_timestamp_start` with the timestamp of the start event 67 | # 68 | # If the "end event" does not arrive before "timeout" seconds, the 69 | # "start event" is discarded and an "expired event" is generated. This event 70 | # contains: 71 | # 72 | # * the tags `elapsed` and `elapsed_expired_error` 73 | # * a field called `elapsed_time` with the age, in seconds, of the 74 | # "start event" 75 | # * an ID filed with the task ID 76 | # * the field `elapsed_timestamp_start` with the timestamp of the "start event" 77 | # 78 | class LogStash::Filters::Elapsed < LogStash::Filters::Base 79 | PREFIX = "elapsed_" 80 | ELAPSED_FIELD = PREFIX + "time" 81 | TIMESTAMP_START_EVENT_FIELD = PREFIX + "timestamp_start" 82 | HOST_FIELD = "host" 83 | 84 | ELAPSED_TAG = "elapsed" 85 | EXPIRED_ERROR_TAG = PREFIX + "expired_error" 86 | END_WITHOUT_START_TAG = PREFIX + "end_without_start" 87 | MATCH_TAG = PREFIX + "match" 88 | 89 | config_name "elapsed" 90 | 91 | # The name of the tag identifying the "start event" 92 | config :start_tag, :validate => :string, :required => true 93 | 94 | # The name of the tag identifying the "end event" 95 | config :end_tag, :validate => :string, :required => true 96 | 97 | # The name of the field containing the task ID. 98 | # This value must uniquely identify the task in the system, otherwise 99 | # it's impossible to match the couple of events. 100 | config :unique_id_field, :validate => :string, :required => true 101 | 102 | # The amount of seconds after an "end event" can be considered lost. 103 | # The corresponding "start event" is discarded and an "expired event" 104 | # is generated. The default value is 30 minutes (1800 seconds). 105 | config :timeout, :validate => :number, :required => false, :default => 1800 106 | 107 | # This property manage what to do when an "end event" matches a "start event". 108 | # If it's set to `false` (default value), the elapsed information are added 109 | # to the "end event"; if it's set to `true` a new "match event" is created. 110 | config :new_event_on_match, :validate => :boolean, :required => false, :default => false 111 | 112 | # This property manage what to do when several "start events" were received 113 | # before an "end event" for a concrete ID. If it's set to `first` (default 114 | # value), the first "start event" will be used; if it's set to `last`, 115 | # the last "start event" will be used. 116 | config :keep_start_event, :validate => ['first', 'last'], :required => false, :default => 'first' 117 | 118 | # This filter must have its flush function called periodically to be able to purge 119 | # expired stored start events. 120 | config :periodic_flush, :validate => :boolean, :default => true 121 | 122 | public 123 | def register 124 | @mutex = Mutex.new 125 | # This is the state of the filter. The keys are the "unique_id_field", 126 | # the values are couples of values: 127 | @start_events = {} 128 | 129 | @logger.info("Elapsed, timeout: #{@timeout} seconds") 130 | end 131 | 132 | # Getter method used for the tests 133 | def start_events 134 | @start_events 135 | end 136 | 137 | def filter(event) 138 | 139 | 140 | unique_id = event.get(@unique_id_field) 141 | return if unique_id.nil? 142 | 143 | if(start_event?(event)) 144 | filter_matched(event) 145 | @logger.debug("Elapsed, 'start event' received", start_tag: @start_tag, unique_id_field: @unique_id_field) 146 | 147 | @mutex.synchronize do 148 | unless(@keep_start_event == 'first' && @start_events.has_key?(unique_id)) 149 | @start_events[unique_id] = LogStash::Filters::Elapsed::Element.new(event) 150 | end 151 | end 152 | 153 | elsif(end_event?(event)) 154 | filter_matched(event) 155 | @logger.debug("Elapsed, 'end event' received", end_tag: @end_tag, unique_id_field: @unique_id_field) 156 | 157 | @mutex.lock 158 | if(@start_events.has_key?(unique_id)) 159 | start_event = @start_events.delete(unique_id).event 160 | @mutex.unlock 161 | elapsed = event.get("@timestamp") - start_event.get("@timestamp") 162 | if(@new_event_on_match) 163 | elapsed_event = new_elapsed_event(elapsed, unique_id, start_event.get("@timestamp")) 164 | filter_matched(elapsed_event) 165 | yield elapsed_event if block_given? 166 | else 167 | return add_elapsed_info(event, elapsed, unique_id, start_event.get("@timestamp")) 168 | end 169 | else 170 | @mutex.unlock 171 | # The "start event" did not arrive. 172 | event.tag(END_WITHOUT_START_TAG) 173 | end 174 | end 175 | end # def filter 176 | 177 | # The method is invoked by LogStash every 5 seconds. 178 | def flush(options = {}) 179 | expired_elements = [] 180 | 181 | @mutex.synchronize do 182 | increment_age_by(5) 183 | expired_elements = remove_expired_elements() 184 | end 185 | 186 | return create_expired_events_from(expired_elements) 187 | end 188 | 189 | private 190 | def increment_age_by(seconds) 191 | @start_events.each_pair do |key, element| 192 | element.age += seconds 193 | end 194 | end 195 | 196 | # Remove the expired "start events" from the internal 197 | # buffer and return them. 198 | def remove_expired_elements() 199 | expired = [] 200 | @start_events.delete_if do |key, element| 201 | if(element.age >= @timeout) 202 | expired << element 203 | next true 204 | end 205 | next false 206 | end 207 | 208 | return expired 209 | end 210 | 211 | def create_expired_events_from(expired_elements) 212 | events = [] 213 | expired_elements.each do |element| 214 | error_event = LogStash::Event.new 215 | error_event.tag(ELAPSED_TAG) 216 | error_event.tag(EXPIRED_ERROR_TAG) 217 | 218 | error_event.set(HOST_FIELD, Socket.gethostname) 219 | error_event.set(@unique_id_field, element.event.get(@unique_id_field) ) 220 | error_event.set(ELAPSED_FIELD, element.age) 221 | error_event.set(TIMESTAMP_START_EVENT_FIELD, element.event.get("@timestamp") ) 222 | 223 | events << error_event 224 | filter_matched(error_event) 225 | end 226 | 227 | return events 228 | end 229 | 230 | def start_event?(event) 231 | return (event.get("tags") != nil && event.get("tags").include?(@start_tag)) 232 | end 233 | 234 | def end_event?(event) 235 | return (event.get("tags") != nil && event.get("tags").include?(@end_tag)) 236 | end 237 | 238 | def new_elapsed_event(elapsed_time, unique_id, timestamp_start_event) 239 | new_event = LogStash::Event.new 240 | new_event.set(HOST_FIELD, Socket.gethostname) 241 | return add_elapsed_info(new_event, elapsed_time, unique_id, timestamp_start_event) 242 | end 243 | 244 | def add_elapsed_info(event, elapsed_time, unique_id, timestamp_start_event) 245 | event.tag(ELAPSED_TAG) 246 | event.tag(MATCH_TAG) 247 | 248 | event.set(ELAPSED_FIELD, elapsed_time) 249 | event.set(@unique_id_field, unique_id) 250 | event.set(TIMESTAMP_START_EVENT_FIELD, timestamp_start_event) 251 | 252 | return event 253 | end 254 | end # class LogStash::Filters::Elapsed 255 | 256 | class LogStash::Filters::Elapsed::Element 257 | attr_accessor :event, :age 258 | 259 | def initialize(event) 260 | @event = event 261 | @age = 0 262 | end 263 | end 264 | -------------------------------------------------------------------------------- /logstash-filter-elapsed.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | 3 | s.name = 'logstash-filter-elapsed' 4 | s.version = '4.1.0' 5 | s.licenses = ['Apache License (2.0)'] 6 | s.summary = "Calculates the elapsed time between a pair of events" 7 | s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program" 8 | s.authors = ["Elastic"] 9 | s.email = 'info@elastic.co' 10 | s.homepage = "http://www.elastic.co/guide/en/logstash/current/index.html" 11 | s.require_paths = ["lib"] 12 | 13 | # Files 14 | s.files = Dir["lib/**/*","spec/**/*","*.gemspec","*.md","CONTRIBUTORS","Gemfile","LICENSE","NOTICE.TXT", "vendor/jar-dependencies/**/*.jar", "vendor/jar-dependencies/**/*.rb", "VERSION", "docs/**/*"] 15 | 16 | # Tests 17 | s.test_files = s.files.grep(%r{^(test|spec|features)/}) 18 | 19 | # Special flag to let us know this is actually a logstash plugin 20 | s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" } 21 | 22 | # Gem dependencies 23 | s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99" 24 | 25 | s.add_development_dependency 'logstash-devutils' 26 | s.add_development_dependency 'insist' 27 | end 28 | -------------------------------------------------------------------------------- /spec/filters/elapsed_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require "logstash/devutils/rspec/spec_helper" 3 | require "insist" 4 | require "logstash/filters/elapsed" 5 | require "logstash/event" 6 | require "socket" 7 | 8 | describe LogStash::Filters::Elapsed do 9 | START_TAG = "startTag" 10 | END_TAG = "endTag" 11 | ID_FIELD = "uniqueIdField" 12 | 13 | def event(data) 14 | data["message"] ||= "Log message" 15 | LogStash::Event.new(data) 16 | end 17 | 18 | def start_event(data) 19 | data["tags"] ||= [] 20 | data["tags"] << START_TAG 21 | event(data) 22 | end 23 | 24 | def end_event(data = {}) 25 | data["tags"] ||= [] 26 | data["tags"] << END_TAG 27 | event(data) 28 | end 29 | 30 | before(:each) do 31 | setup_filter() 32 | end 33 | 34 | def setup_filter(config = {}) 35 | @config = {"start_tag" => START_TAG, "end_tag" => END_TAG, "unique_id_field" => ID_FIELD} 36 | @config.merge!(config) 37 | @filter = LogStash::Filters::Elapsed.new(@config) 38 | @filter.register 39 | end 40 | 41 | context "General validation" do 42 | describe "receiving an event without start or end tag" do 43 | it "does not record it" do 44 | @filter.filter(event("message" => "Log message")) 45 | insist { @filter.start_events.size } == 0 46 | end 47 | end 48 | 49 | describe "receiving an event with a different start/end tag from the ones specified in the configuration" do 50 | it "does not record it" do 51 | @filter.filter(event("tags" => ["tag1", "tag2"])) 52 | insist { @filter.start_events.size } == 0 53 | end 54 | end 55 | end 56 | 57 | context "Start event" do 58 | describe "receiving an event with a valid start tag" do 59 | describe "but without an unique id field" do 60 | it "does not record it" do 61 | @filter.filter(event("tags" => ["tag1", START_TAG])) 62 | insist { @filter.start_events.size } == 0 63 | end 64 | end 65 | 66 | describe "and a valid id field" do 67 | it "records it" do 68 | event = start_event(ID_FIELD => "id123") 69 | @filter.filter(event) 70 | 71 | insist { @filter.start_events.size } == 1 72 | insist { @filter.start_events["id123"].event } == event 73 | end 74 | end 75 | end 76 | 77 | describe "receiving two 'start events' for the same id field" do 78 | context "if 'keep_start_event' is set to 'last'" do 79 | before(:each) do 80 | setup_filter("keep_start_event" => 'last') 81 | end 82 | 83 | it "keeps the second one and does not save the first one" do 84 | args = {"tags" => [START_TAG], ID_FIELD => "id123"} 85 | first_event = event(args) 86 | second_event = event(args) 87 | 88 | @filter.filter(first_event) 89 | @filter.filter(second_event) 90 | 91 | insist { @filter.start_events.size } == 1 92 | insist { @filter.start_events["id123"].event } == second_event 93 | end 94 | end 95 | 96 | context "if 'keep_start_event' is set to 'first'" do 97 | it "keeps the first one and does not save the second one" do 98 | args = {"tags" => [START_TAG], ID_FIELD => "id123"} 99 | first_event = event(args) 100 | second_event = event(args) 101 | 102 | @filter.filter(first_event) 103 | @filter.filter(second_event) 104 | 105 | insist { @filter.start_events.size } == 1 106 | insist { @filter.start_events["id123"].event } == first_event 107 | end 108 | end 109 | end 110 | end 111 | 112 | context "End event" do 113 | describe "receiving an event with a valid end tag" do 114 | describe "and without an id" do 115 | it "does nothing" do 116 | insist { @filter.start_events.size } == 0 117 | @filter.filter(end_event()) 118 | insist { @filter.start_events.size } == 0 119 | end 120 | end 121 | 122 | describe "and with an id" do 123 | describe "but without a previous 'start event'" do 124 | it "adds a tag 'elapsed_end_witout_start' to the 'end event'" do 125 | end_event = end_event(ID_FIELD => "id_123") 126 | 127 | @filter.filter(end_event) 128 | 129 | insist { end_event.get("tags").include?("elapsed_end_without_start") } == true 130 | end 131 | end 132 | end 133 | end 134 | end 135 | 136 | context "Start/end events interaction" do 137 | describe "receiving a 'start event'" do 138 | before(:each) do 139 | @id_value = "id_123" 140 | @start_event = start_event(ID_FIELD => @id_value) 141 | @filter.filter(@start_event) 142 | end 143 | 144 | describe "and receiving an event with a valid end tag" do 145 | describe "and without an id" do 146 | it "does nothing" do 147 | @filter.filter(end_event()) 148 | insist { @filter.start_events.size } == 1 149 | insist { @filter.start_events[@id_value].event } == @start_event 150 | end 151 | end 152 | 153 | describe "and an id different from the one of the 'start event'" do 154 | it "does nothing" do 155 | different_id_value = @id_value + "_different" 156 | @filter.filter(end_event(ID_FIELD => different_id_value)) 157 | 158 | insist { @filter.start_events.size } == 1 159 | insist { @filter.start_events[@id_value].event } == @start_event 160 | end 161 | end 162 | 163 | describe "and the same id of the 'start event'" do 164 | it "deletes the recorded 'start event'" do 165 | insist { @filter.start_events.size } == 1 166 | 167 | @filter.filter(end_event(ID_FIELD => @id_value)) 168 | 169 | insist { @filter.start_events.size } == 0 170 | end 171 | 172 | shared_examples_for "match event" do 173 | it "contains the tag 'elapsed'" do 174 | insist { @match_event.get("tags").include?("elapsed") } == true 175 | end 176 | 177 | it "contains the tag tag 'elapsed_match'" do 178 | insist { @match_event.get("tags").include?("elapsed_match") } == true 179 | end 180 | 181 | it "contains an 'elapsed_time field' with the elapsed time" do 182 | insist { @match_event.get("elapsed_time") } == 10 183 | end 184 | 185 | it "contains an 'elapsed_timestamp_start field' with the timestamp of the 'start event'" do 186 | insist { @match_event.get("elapsed_timestamp_start") } == @start_event.get("@timestamp") 187 | end 188 | 189 | it "contains an 'id field'" do 190 | insist { @match_event.get(ID_FIELD) } == @id_value 191 | end 192 | end 193 | 194 | context "if 'new_event_on_match' is set to 'true'" do 195 | before(:each) do 196 | # I need to create a new filter because I need to set 197 | # the config property 'new_event_on_match" to 'true'. 198 | setup_filter("new_event_on_match" => true) 199 | @start_event = start_event(ID_FIELD => @id_value) 200 | @filter.filter(@start_event) 201 | 202 | end_timestamp = @start_event.get("@timestamp") + 10 203 | end_event = end_event(ID_FIELD => @id_value, "@timestamp" => end_timestamp) 204 | @filter.filter(end_event) do |new_event| 205 | @match_event = new_event 206 | end 207 | end 208 | 209 | context "creates a new event that" do 210 | it_behaves_like "match event" 211 | 212 | it "contains the 'host field'" do 213 | insist { @match_event.get("host") } == Socket.gethostname 214 | end 215 | end 216 | end 217 | 218 | context "if 'new_event_on_match' is set to 'false'" do 219 | before(:each) do 220 | end_timestamp = @start_event.get("@timestamp") + 10 221 | end_event = end_event(ID_FIELD => @id_value, "@timestamp" => end_timestamp) 222 | @filter.filter(end_event) 223 | 224 | @match_event = end_event 225 | end 226 | 227 | context "modifies the 'end event' that" do 228 | it_behaves_like "match event" 229 | end 230 | end 231 | 232 | end 233 | end 234 | end 235 | end 236 | 237 | describe "#flush" do 238 | def setup(timeout = 1000) 239 | @config["timeout"] = timeout 240 | @filter = LogStash::Filters::Elapsed.new(@config) 241 | @filter.register 242 | 243 | @start_event_1 = start_event(ID_FIELD => "1") 244 | @start_event_2 = start_event(ID_FIELD => "2") 245 | @start_event_3 = start_event(ID_FIELD => "3") 246 | 247 | @filter.filter(@start_event_1) 248 | @filter.filter(@start_event_2) 249 | @filter.filter(@start_event_3) 250 | 251 | # Force recorded events to different ages 252 | @filter.start_events["2"].age = 25 253 | @filter.start_events["3"].age = 26 254 | end 255 | 256 | it "increments the 'age' of all the recorded 'start events' by 5 seconds" do 257 | setup() 258 | old_age = ages() 259 | 260 | @filter.flush() 261 | 262 | ages().each_with_index do |new_age, i| 263 | insist { new_age } == (old_age[i] + 5) 264 | end 265 | end 266 | 267 | def ages() 268 | @filter.start_events.each_value.map{|element| element.age } 269 | end 270 | 271 | context "if the 'timeout interval' is set to 30 seconds" do 272 | before(:each) do 273 | setup(30) 274 | 275 | @expired_events = @filter.flush() 276 | 277 | insist { @filter.start_events.size } == 1 278 | insist { @expired_events.size } == 2 279 | end 280 | 281 | it "deletes the recorded 'start events' with 'age' greater, or equal to, the timeout" do 282 | insist { @filter.start_events.key?("1") } == true 283 | insist { @filter.start_events.key?("2") } == false 284 | insist { @filter.start_events.key?("3") } == false 285 | end 286 | 287 | it "creates a new event with tag 'elapsed_expired_error' for each expired 'start event'" do 288 | insist { @expired_events[0].get("tags").include?("elapsed_expired_error") } == true 289 | insist { @expired_events[1].get("tags").include?("elapsed_expired_error") } == true 290 | end 291 | 292 | it "creates a new event with tag 'elapsed' for each expired 'start event'" do 293 | insist { @expired_events[0].get("tags").include?("elapsed") } == true 294 | insist { @expired_events[1].get("tags").include?("elapsed") } == true 295 | end 296 | 297 | it "creates a new event containing the 'id field' of the expired 'start event'" do 298 | insist { @expired_events[0].get(ID_FIELD) } == "2" 299 | insist { @expired_events[1].get(ID_FIELD) } == "3" 300 | end 301 | 302 | it "creates a new event containing an 'elapsed_time field' with the age of the expired 'start event'" do 303 | insist { @expired_events[0].get("elapsed_time") } == 30 304 | insist { @expired_events[1].get("elapsed_time") } == 31 305 | end 306 | 307 | it "creates a new event containing an 'elapsed_timestamp_start field' with the timestamp of the expired 'start event'" do 308 | insist { @expired_events[0].get("elapsed_timestamp_start") } == @start_event_2.get("@timestamp") 309 | insist { @expired_events[1].get("elapsed_timestamp_start") } == @start_event_3.get("@timestamp") 310 | end 311 | 312 | it "creates a new event containing a 'host field' for each expired 'start event'" do 313 | insist { @expired_events[0].get("host") } == Socket.gethostname 314 | insist { @expired_events[1].get("host") } == Socket.gethostname 315 | end 316 | end 317 | end 318 | end 319 | --------------------------------------------------------------------------------