| 1 |
.. |
| 2 |
Copyright 2013 Rackspace Hosting. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
not use this file except in compliance with the License. You may obtain |
| 6 |
a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
License for the specific language governing permissions and limitations |
| 14 |
under the License. |
| 15 |
|
| 16 |
.. _events: |
| 17 |
|
| 18 |
=========================== |
| 19 |
Events and Event Processing |
| 20 |
=========================== |
| 21 |
|
| 22 |
Events vs. Samples |
| 23 |
~~~~~~~~~~~~~~~~~~ |
| 24 |
|
| 25 |
In addition to Meters, and related Sample data, Ceilometer can also process |
| 26 |
Events. |
| 27 |
|
| 28 |
While a Sample represents a single numeric datapoint, driving a Meter that |
| 29 |
represents the changes in that value over time, an Event represents the state |
| 30 |
of an object in an OpenStack service (such as an Instance in Nova, or an Image |
| 31 |
in Glance) at a point in time when something of interest has occurred. This can |
| 32 |
include non-numeric data, such as an instance's flavor, or network address. |
| 33 |
|
| 34 |
In general, Events let you know when something has changed about an |
| 35 |
object in an OpenStack system, such as the resize of an instance, or creation |
| 36 |
of an image. |
| 37 |
|
| 38 |
While Samples can be relatively cheap (small), disposable (losing an individual |
| 39 |
sample datapoint won't matter much), and fast, Events are larger, more |
| 40 |
informative, and should be handled more consistently (you do not want to lose |
| 41 |
one). |
| 42 |
|
| 43 |
Event Structure |
| 44 |
~~~~~~~~~~~~~~~ |
| 45 |
|
| 46 |
To facilitate downstream processing (billing and/or aggregation), a |
| 47 |
`minimum required data set and format <format>` has been defined for |
| 48 |
services, however events generally contain the following information: |
| 49 |
|
| 50 |
event_type |
| 51 |
A dotted string defining what event occurred, such as |
| 52 |
``compute.instance.resize.start`` |
| 53 |
|
| 54 |
message_id |
| 55 |
A UUID for this event. |
| 56 |
|
| 57 |
generated |
| 58 |
A timestamp of when the event occurred on the source system. |
| 59 |
|
| 60 |
traits |
| 61 |
A flat mapping of key-value pairs. |
| 62 |
The event's Traits contain most of the details of the event. Traits are |
| 63 |
typed, and can be strings, ints, floats, or datetimes. |
| 64 |
|
| 65 |
raw |
| 66 |
(Optional) Mainly for auditing purpose, the full notification message |
| 67 |
can be stored (unindexed) for future evaluation. |
| 68 |
|
| 69 |
Events from Notifications |
| 70 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 71 |
|
| 72 |
Events are primarily created via the notifications system in OpenStack. |
| 73 |
OpenStack systems, such as Nova, Glance, Neutron, etc. will emit |
| 74 |
notifications in a JSON format to the message queue when some notable action is |
| 75 |
taken by that system. Ceilometer will consume such notifications from the |
| 76 |
message queue, and process them. |
| 77 |
|
| 78 |
The general philosophy of notifications in OpenStack is to emit any and all |
| 79 |
data someone might need, and let the consumer filter out what they are not |
| 80 |
interested in. In order to make processing simpler and more efficient, |
| 81 |
the notifications are stored and processed within Ceilometer as Events. |
| 82 |
The notification payload, which can be an arbitrarily complex JSON data |
| 83 |
structure, is converted to a flat set of key-value pairs known as Traits. |
| 84 |
This conversion is specified by a config file, so that only the specific |
| 85 |
fields within the notification that are actually needed for processing the |
| 86 |
event will have to be stored as Traits. |
| 87 |
|
| 88 |
Note that the Event format is meant for efficient processing and querying, |
| 89 |
there are other means available for archiving notifications (i.e. for audit |
| 90 |
purposes, etc), possibly to different datastores. |
| 91 |
|
| 92 |
Converting Notifications to Events |
| 93 |
---------------------------------- |
| 94 |
|
| 95 |
In order to make it easier to allow users to extract what they need, |
| 96 |
the conversion from Notifications to Events is driven by a |
| 97 |
configuration file (specified by the flag definitions_cfg_file_ in |
| 98 |
:file:`ceilometer.conf`). |
| 99 |
|
| 100 |
This includes descriptions of how to map fields in the notification body |
| 101 |
to Traits, and optional plugins for doing any programmatic translations |
| 102 |
(splitting a string, forcing case, etc.) |
| 103 |
|
| 104 |
The mapping of notifications to events is defined per event_type, which |
| 105 |
can be wildcarded. Traits are added to events if the corresponding fields |
| 106 |
in the notification exist and are non-null. (As a special case, an empty |
| 107 |
string is considered null for non-text traits. This is due to some openstack |
| 108 |
projects (mostly Nova) using empty string for null dates.) |
| 109 |
|
| 110 |
If the definitions file is not present, a warning will be logged, but an empty |
| 111 |
set of definitions will be assumed. By default, any notifications that |
| 112 |
do not have a corresponding event definition in the definitions file will be |
| 113 |
converted to events with a set of minimal, default traits. This can be |
| 114 |
changed by setting the flag drop_unmatched_notifications_ in the |
| 115 |
:file:`ceilometer.conf` file. If this is set to True, then any notifications |
| 116 |
that don't have events defined for them in the file will be dropped. |
| 117 |
This can be what you want, the notification system is quite chatty by design |
| 118 |
(notifications philosophy is "tell us everything, we'll ignore what we don't |
| 119 |
need"), so you may want to ignore the noisier ones if you don't use them. |
| 120 |
|
| 121 |
.. _definitions_cfg_file: http://docs.openstack.org/trunk/config-reference/content/ch_configuring-openstack-telemetry.html |
| 122 |
.. _drop_unmatched_notifications: http://docs.openstack.org/trunk/config-reference/content/ch_configuring-openstack-telemetry.html |
| 123 |
|
| 124 |
There is a set of default traits (all are TEXT type) that will be added to |
| 125 |
all events if the notification has the relevant data: |
| 126 |
|
| 127 |
* service: (All notifications should have this) notification's publisher |
| 128 |
* tenant_id |
| 129 |
* request_id |
| 130 |
* project_id |
| 131 |
* user_id |
| 132 |
|
| 133 |
These do not have to be specified in the event definition, they are |
| 134 |
automatically added, but their definitions can be overridden for a given |
| 135 |
``event_type``. |
| 136 |
|
| 137 |
Definitions file format |
| 138 |
----------------------- |
| 139 |
|
| 140 |
The event definitions file is in YAML format. It consists of a list of event |
| 141 |
definitions, which are mappings. Order is significant, the list of definitions |
| 142 |
is scanned in *reverse* order (last definition in the file to the first), |
| 143 |
to find a definition which matches the notification's event_type. That |
| 144 |
definition will be used to generate the Event. The reverse ordering is done |
| 145 |
because it is common to want to have a more general wildcarded definition |
| 146 |
(such as ``compute.instance.*``) with a set of traits common to all of those |
| 147 |
events, with a few more specific event definitions (like |
| 148 |
``compute.instance.exists``) afterward that have all of the above traits, plus |
| 149 |
a few more. This lets you put the general definition first, followed by the |
| 150 |
specific ones, and use YAML mapping include syntax to avoid copying all of the |
| 151 |
trait definitions. |
| 152 |
|
| 153 |
Event Definitions |
| 154 |
----------------- |
| 155 |
|
| 156 |
Each event definition is a mapping with two keys (both required): |
| 157 |
|
| 158 |
event_type |
| 159 |
This is a list (or a string, which will be taken as a 1 element |
| 160 |
list) of event_types this definition will handle. These can be |
| 161 |
wildcarded with unix shell glob syntax. An exclusion listing |
| 162 |
(starting with a '!') will exclude any types listed from matching. |
| 163 |
If ONLY exclusions are listed, the definition will match anything |
| 164 |
not matching the exclusions. |
| 165 |
traits |
| 166 |
This is a mapping, the keys are the trait names, and the values are |
| 167 |
trait definitions. |
| 168 |
|
| 169 |
Trait Definitions |
| 170 |
----------------- |
| 171 |
|
| 172 |
Each trait definition is a mapping with the following keys: |
| 173 |
|
| 174 |
type |
| 175 |
(optional) The data type for this trait. (as a string). Valid |
| 176 |
options are: *text*, *int*, *float*, and *datetime*. |
| 177 |
defaults to *text* if not specified. |
| 178 |
fields |
| 179 |
A path specification for the field(s) in the notification you wish |
| 180 |
to extract for this trait. Specifications can be written to match |
| 181 |
multiple possible fields, the value for the trait will be derived |
| 182 |
from the matching fields that exist and have a non-null values in |
| 183 |
the notification. By default the value will be the first such field. |
| 184 |
(plugins can alter that, if they wish). This is normally a string, |
| 185 |
but, for convenience, it can be specified as a list of |
| 186 |
specifications, which will match the fields for all of them. |
| 187 |
(See `Field Path Specifications`_ for more info on this syntax.) |
| 188 |
plugin |
| 189 |
(optional) This is a mapping (For convenience, this value can also |
| 190 |
be specified as a string, which is interpreted as the name of a |
| 191 |
plugin to be loaded with no parameters) with the following keys: |
| 192 |
|
| 193 |
name |
| 194 |
(string) name of a plugin to load |
| 195 |
|
| 196 |
parameters |
| 197 |
(optional) Mapping of keyword arguments to pass to the plugin on |
| 198 |
initialization. (See documentation on each plugin to see what |
| 199 |
arguments it accepts.) |
| 200 |
|
| 201 |
Field Path Specifications |
| 202 |
------------------------- |
| 203 |
|
| 204 |
The path specifications define which fields in the JSON notification |
| 205 |
body are extracted to provide the value for a given trait. The paths |
| 206 |
can be specified with a dot syntax (e.g. ``payload.host``). Square |
| 207 |
bracket syntax (e.g. ``payload[host]``) is also supported. In either |
| 208 |
case, if the key for the field you are looking for contains special |
| 209 |
characters, like '.', it will need to be quoted (with double or single |
| 210 |
quotes) like so: |
| 211 |
|
| 212 |
:: |
| 213 |
|
| 214 |
payload.image_meta.'org.openstack__1__architecture' |
| 215 |
|
| 216 |
The syntax used for the field specification is a variant of JSONPath, |
| 217 |
and is fairly flexible. |
| 218 |
(see: https://github.com/kennknowles/python-jsonpath-rw for more info) |
| 219 |
|
| 220 |
Example Definitions file |
| 221 |
------------------------ |
| 222 |
|
| 223 |
:: |
| 224 |
|
| 225 |
--- |
| 226 |
- event_type: compute.instance.* |
| 227 |
traits: &instance_traits |
| 228 |
user_id: |
| 229 |
fields: payload.user_id |
| 230 |
instance_id: |
| 231 |
fields: payload.instance_id |
| 232 |
host: |
| 233 |
fields: publisher_id |
| 234 |
plugin: |
| 235 |
name: split |
| 236 |
parameters: |
| 237 |
segment: 1 |
| 238 |
max_split: 1 |
| 239 |
service_name: |
| 240 |
fields: publisher_id |
| 241 |
plugin: split |
| 242 |
instance_type_id: |
| 243 |
type: int |
| 244 |
fields: payload.instance_type_id |
| 245 |
os_architecture: |
| 246 |
fields: payload.image_meta.'org.openstack__1__architecture' |
| 247 |
launched_at: |
| 248 |
type: datetime |
| 249 |
fields: payload.launched_at |
| 250 |
deleted_at: |
| 251 |
type: datetime |
| 252 |
fields: payload.deleted_at |
| 253 |
- event_type: |
| 254 |
- compute.instance.exists |
| 255 |
- compute.instance.update |
| 256 |
traits: |
| 257 |
<<: *instance_traits |
| 258 |
audit_period_beginning: |
| 259 |
type: datetime |
| 260 |
fields: payload.audit_period_beginning |
| 261 |
audit_period_ending: |
| 262 |
type: datetime |
| 263 |
fields: payload.audit_period_ending |
| 264 |
|
| 265 |
Trait plugins |
| 266 |
------------- |
| 267 |
|
| 268 |
Trait plugins can be used to do simple programmatic conversions on the value in |
| 269 |
a notification field, like splitting a string, lowercasing a value, converting |
| 270 |
a screwball date into ISO format, or the like. They are initialized with the |
| 271 |
parameters from the trait definition, if any, which can customize their |
| 272 |
behavior for a given trait. They are called with a list of all matching fields |
| 273 |
from the notification, so they can derive a value from multiple fields. The |
| 274 |
plugin will be called even if there are no fields found matching the field |
| 275 |
path(s), this lets a plugin set a default value, if needed. A plugin can also |
| 276 |
reject a value by returning *None*, which will cause the trait not to be |
| 277 |
added. If the plugin returns anything other than *None*, the trait's value |
| 278 |
will be set to whatever the plugin returned (coerced to the appropriate type |
| 279 |
for the trait). |
| 280 |
|
| 281 |
Building Notifications |
| 282 |
~~~~~~~~~~~~~~~~~~~~~~ |
| 283 |
|
| 284 |
In general, the payload format OpenStack services emit could be described as |
| 285 |
the Wild West. The payloads are often arbitrary data dumps at the time of |
| 286 |
the event which is often susceptible to change. To make consumption easier, |
| 287 |
the Ceilometer team offers: CADF_, an open, cloud standard which helps model |
| 288 |
cloud events. |
| 289 |
|
| 290 |
.. _CADF: https://docs.openstack.org/pycadf/latest/ |