46 Commits

Author SHA1 Message Date
Amir Mofakhar
4250756a1f Implemented a policy enforcement engine
Under monasca_common/policy an enforcement engine is added for using
oslo.policy in the other monasca projects.
There are same methods as in enforcement engings currently used in
nova and keystone projects.
Also added unit tests under tests/policy for testing implemented
methods.

Task: 6105
Story: 2001233

Change-Id: Ic5402ba0986416c9386c1dc3fc1559f148ea9625
Signed-off-by: Amir Mofakhar <amofakhar@op5.com>
2017-12-19 15:16:09 +01:00
Craig Bryant
998f6afa53 Retry publish once on failures
On failure to publish, clear the topic metadata then retry, in
case the IP Addresses have changed.  This can occur when
Monasca is run in Kubernetes and the Kafka pod is restarted.
Restarting the Kafka pod can happen often enough the
API should be able handle it without losing a message.

Change-Id: If48971c40883b5be10adec947562cdda7e82d77c
Story: 2001386
Task: 5963
2017-12-12 12:47:27 +00:00
Ryan Brandt
7f91a53128 Allow () in dimensions
Change-Id: Ic61a325162873572cad387593c7107cba1a41e15
2017-11-30 15:24:46 -07:00
Habeeb Mohammed
94e0a059b5 Fixed inconfigurable kafka consumer offset location
PROBLEM: Consumer offset was resetting to the latest index rather than the earliest
SOLUTION: Modified consumer creation to include `auto_offset_reset="smallest"` which
	allows the offset to reset to the earliest known index.

NOTE: This does exactly what the whence parameter in SimpleConsumer.seek()
	is expected to do, however in order to achieve this functionality,
	the parameter `auto_offset_reset` MUST be set to either "largest"
	or "smallest".

Change-Id: I887892d80f2da9619c7f11737b3ab2e1d1dacf1e
2017-09-27 14:35:00 -06:00
Jenkins
9188cfcb34 Merge "Add a query language for group, inhibit, and silence rules" 2017-06-19 17:19:03 +00:00
Andrea Adams
41800dd195 Add a query language for group, inhibit, and silence rules
The new alarm rules will each have an expression in their
definition which will need to be parsed by both the Monasca-
API and the Monasca-Notification-Engine. Documentation for
this will be included in the API along with descriptions of the
new rules.

Story: 2000939
Task: 4692

Change-Id: I1a98fafae8dfdfa6fdb2eb66f4a4a4f40e518e46
2017-06-16 22:42:20 +00:00
Emma Foley
a6648264cc [doc] Fix sublist formatting in monasca_common/kafka_lib/NOTES.md
Change-Id: I465e3fd86b7875e51f5d9b0a82e106ede6787390
Closes-Bug: #1696786
2017-06-08 15:25:50 +00:00
M V P Nitesh
03fd5ca884 Replace assertRaisesRegexp with assertRaisesRegex
This replaces the deprecated (in python 3.2) unittest.TestCase
method assertRaisesRegexp() with assertRaisesRegex()

Change-Id: I0bed1f2a0bb8ef57a48e3b778795e8ac75f3a2eb
2017-05-22 14:42:11 +05:30
Tomasz Trębski
cabc2ddd5f Migrate to ostestr framework and PY3
Following commits does several things:

* migrates CI of monasca-common to ostestr
* enables PY35 compatybility

Also:

* marked one tests as excluded under PY35 because changing
it would require affecting embedded kafka library which
will be eventually removed in future

Change-Id: I432a466e2620bc8d305ef2630307b636461c8e81
2017-03-02 19:51:04 +01:00
Tomasz Trębski
dc7c14d2d0 Removed unused logging module
monasca_common.logging seems to be unused
in other monasca projects therefore should
be removed.

Also removed one dependency that was used only
by that module

Change-Id: Ib875d9bae86c9b2b715edbe0226347b3fc9ec8ed
2017-02-17 05:50:51 +00:00
Tomasz Trębski
9cbcfed83f Use long as possible timestamp value
long, as type, is also possible to be a timestamp
format

Needed-By: I2f9d22a2c5e18826c8f9bb1e817ad963731b390f
Change-Id: I186abe4cdafd58d998f8aaf36d866795771a9e0a
2017-02-15 06:58:03 +01:00
Jenkins
e9954014da Merge "Fork 0.9.5 kafka-python and require pykafka" 2017-01-23 00:12:03 +00:00
Joe Keen
cb2ec23cee Fork 0.9.5 kafka-python and require pykafka
To let other OpenStack projects move forward with new versions of kafka-python
we're forking kafka-python and embedding it in monasca-common.  This allows us
to migrate to the new async interfaces provided by more recent kafka clients
over time and not block other projects.

Requiring pykafka to allow us to have ~4x more throughput once we write to
their async interfaces.

Change-Id: Ifb6ab67ce1335a5ec4ed7dd8b0027dc9d46a6dda
Depends-On: I26f9c588f2818059ab6ba24f9fad8e213798a39c
2017-01-21 10:40:55 -07:00
Jenkins
32de2db4d4 Merge "Break up dimenion validation into key and value parts" 2017-01-20 19:12:59 +00:00
Ryan Brandt
2147d15faa Break up dimenion validation into key and value parts
Some components need to validate dimenion keys independently
from the values (i.e. the API).

Change-Id: I91536f28ca3d58f1002eed5a7631b6c4c377b6b0
2017-01-13 14:55:37 -07:00
Nguyen Hung Phuong
d8c0655b37 Clean imports in code
In some part in the code we import objects. In the Openstack style
guidelines they recommend to import only modules.

http://docs.openstack.org/developer/hacking/#imports

Change-Id: Icc97b8d76901b8807bf04737bc1f72b5393e2879
2017-01-12 21:54:28 +00:00
Ryan Brandt
0a261ef5a2 Allow value_meta to be None/Null
The API spec says value_meta is optional, so
allow none as a value. This change will also
match the java API.

Change-Id: Ibabff76b3f1592334c281f57a1a5b939bb11e1f8
2017-01-10 14:14:53 -07:00
Ryan Brandt
4679a9fd31 Add validation for 'nan' and infinity
Influx doesn't support these as metric values

Change-Id: Id6e9aaa3a21ac20d366e9a88d82ad153210d612b
2017-01-03 12:49:51 -07:00
Jenkins
2b0255043c Merge "Use six.moves.range for Python 3" 2016-11-25 04:36:14 +00:00
Luong Anh Tuan
5d5c6f4e4f Use six.moves.range for Python 3
The function xrange() was renamed to range() in Python 3.

Use "from six.moves import range" to get xrange() on Python 2 and range()
on Python 3 as the name "range", and replace "xrange()" with "range()".

The import is omitted for small ranges (1024 items or less).

This patch was generated by the following tool (revision 0c1d096b3903)
with the "xrange" operation:
https://bitbucket.org/haypo/misc/src/tip/python/sixer.py

Manual change:

* Replace range(n) with list(range(n)) in a loop of
  nova/virt/libvirt/driver.py which uses list.pop()

Blueprint nova-python3

Change-Id: Ifc264fe262982b62d9791cedef6040eecc8af04e
2016-11-21 09:19:34 +00:00
Cao Xuan Hoang
4e45bfc538 TrivialFix: Remove logging import unused
This patch removes logging import unused in
monasca_common/simport/simport.py

Change-Id: I61dc6a8b996e36b2be13b409e44bc7d8df356723
2016-09-23 17:07:11 +07:00
Kaiyan Sheng
a62f3cdd19 Move metric validation from agent to monasca common
This case other repos can use this code to validate metrics instead
of writing their own.

Change-Id: If402441cd1ec80c4b81c125eea678d01b4687d90
2016-09-01 13:38:39 -06:00
Laszlo Hegedus
6c78674266 Add unit tests for common repositories module
Add unit tests for repositories.mysql module.

Change-Id: Ia834b87cf5619bdb2bdf471352600e69e53a3eea
2016-07-20 13:31:50 +00:00
Jenkins
3e27d3fea4 Merge "Make monasca-common pep8 compatible" 2016-06-16 23:13:56 +00:00
Kaiyan Sheng
d000623ab4 Move simport into monasca common
Change-Id: I284bc33d8589114ca17b772955527ffd7a5a1554
2016-06-10 16:30:08 -06:00
Laszlo Hegedus
c98478df18 Make monasca-common pep8 compatible
Cleaned up test-requirements.txt in order to use the latest hacking
package.
Removed the ignored pep8 checks and made the code pass all of them.

Also removed the OpenStack Foundation copyright notice that was put
there accidentally before.

Change-Id: I3d287eb71fc2bf0e4d52856c11cbc8a347cac2ed
2016-06-04 09:22:43 +00:00
Jenkins
59d4eadf3f Merge "Remove unnecessary executable permissions" 2016-05-24 18:00:31 +00:00
Bertrand Lallau
932d25b3f5 Remove unnecessary executable permissions
Removes executable permissions on python modules not requiring it.

Change-Id: Ia1aee6fd3cee81340d6faaff1db43ba4b55997bb
2016-05-24 09:28:30 +02:00
Laszlo Hegedus
082787e5b2 Add unit tests for common rest.utils module
Add unit tests for common json conversions and exception handling.

Change-Id: I71ab992bb09114f4fd9c9752820ab57b4c51577a
2016-05-20 20:53:20 +02:00
Laszlo Hegedus
bfc88d4f05 Add unit tests for common Kafka module
Add tests for kafka producer and consumer modules. The test coverage
of monasca_common was was 9%. This is improved in this commit.

Show test coverage when running tox. Change the nosetests command to
show test coverage for the whole module.

Change-Id: I771a539aee5fa92c065ee16b5bb94c9ae7e7a09b
2016-05-17 10:50:12 +02:00
Koji Nakazono
5c73077520 FIX handling json data with multibyte characters
"json.dumps" function returns encoded value when specifying
"ensure_ascii=False", so it's not necessary to encode the returned
value.

Change-Id: Ic4834a27d36993cd9f4d2b6945cf108e7149d95b
Closes-Bug: 1569112
2016-04-12 10:27:31 +09:00
Tomasz Trębski
8f729c4c2b Invalid kafka check script name
Having 'kafka.py' as the script name
resulted in error when importing this script.

Change-Id: Icf6b6776e78bfcb4d6808556ffb37e14275d7240
2016-04-05 06:17:46 +02:00
Jenkins
f3cbb73f70 Merge "Kafka healthcheck" 2016-03-22 21:46:05 +00:00
Joe Keen
5aaf3df47a Partition rebalance broken in kafka-python 0.9.5
Our partiton rebalance mechanism broke on the upgrade from kafka-python 0.9.2
to 0.9.5.  Rather than fiddling with the internals of the kafka consumer object
we're now reconstructing the consumer object after each rebalance and handing
it the specific partitions it needs to worry about.

Closes-bug: #1560178
Change-Id: I469ceb28538db1f36918f211eaea4fcfdaa17649
2016-03-21 17:05:58 -06:00
Tomasz Trębski
b94bb88397 Kafka healthcheck
This commit provides healthcheck package for
monasca-common where so called checks can be defined
and used throughout monasca-* projects.

Summary:
- KafkaHealthCheck
- HealthCheckResult

Change-Id: Ib404ae128c8a3c93b24e4e237a3d77130fb18b53
2016-03-08 14:20:47 +01:00
Jenkins
a623b10429 Merge "Improving kafka performance" 2016-02-09 22:04:35 +00:00
Joe Keen
b6945fe27f Improving kafka performance
The kafka client library recieves batches of a certain size from kafka
regardless of the batch size I ask for.  Asking for a batch size that's larger
than the respose size results in multiple requests to kafka until the batch
size I asked for is recieved.

Asking for a single message still causes the kafka client to recieve a batch of
data from kafka but doing it this way, which is the same way that the kafka
library __iter__ function works, results in a ~5x improvement in throughput
over asking for larger batch sizes.

Increasing the requested batch size results in a dramatic increase in
performance.  For the Java consumer the default read size is 1MB compared to
the 4KB default read size in the Python consumer.  Increasing the Python
consumer to match the Java version results in a ~10x improvement.

Change-Id: I3380df56749a577ae7116e5da841dcb91c85312a
2016-02-09 12:19:05 -07:00
Joe Keen
633ab3ec6a Fix Kafka consumer commit
If we don't specify the current set of partitions to the commit call the Kafka
consumer object seems to issue a commit for all the partitions it has
information on and not just the ones it is actively reading.  This fix will
allow it to only commit to the partitions that it is consuming from.

Change-Id: Ifd5aa9c8fe4d83f804629f1a301a40556721d018
2016-02-04 13:18:49 -07:00
Jenkins
c7a064c899 Merge "Convert partition key to str" 2016-01-27 00:20:22 +00:00
Joe Keen
ca22e64edd Convert partition key to str
In kafka 0.9.5 the partition key needs to be a six.binary_type which is a str
in Python 2.6

Change-Id: I423694d635521d286bfdafc2172b31f3dca21860
2016-01-26 13:46:08 -07:00
Tomasz Trębski
e6143321a8 Common REST data handling
Adding common REST data handling
to monasca-common project

Change-Id: I982d0afbc51863905c56e1d4c24307fea261d944
2016-01-14 12:27:33 +00:00
Craig Bryant
fbf46dca69 Remove invalid ascii characters
Not sure how they got there but characters in columns 18 and 19 on
line 43 are not ascii. Remove them

Change-Id: Ibbf27c89b3ba6f110b47d042ea24cc1443ad055d
2016-01-11 20:13:28 -07:00
Michal Zielonka
7a6aa181b9 Change MySqlDB to pymysql
MySQL-python has GPL2 license. Apache license is not compatible with it. 
We propose to replace it with pymysql which has MIT license.

Change-Id: I8d758f5e4908c1047dc4167ebd28cad24fff3a28
2015-12-15 17:04:39 +00:00
Tomasz Trębski
c5161fd4ae Using own key in kafka producer
Added possibility to specify own key instead
of using calculated one. Feature is optional.

Change-Id: I6279ba8753f30f42526bb4de5db54d449a94f5b1
2015-11-10 12:01:32 +00:00
Joe Keen
7eec9f1ebc Added kafka interaction objects to monasca_common
New consumer object intended to be used by the pieces of Monasca that want to
consume data from kafka.

New producer object that will write to kafka in a performant manner.

Require kazoo
Removed PyYaml requirement

Change-Id: I2eb0c5cd1ed64b83a67912109c4c6de7a1d73722
2015-10-30 18:03:45 -06:00
cindy oneill
21d3947845 initial python monasca-common code in monasca_common
This is the start of a python monasca-common package.
Initially it has a common python logging config,
common oslo opts, and mysql common code.

Change-Id: I15c32b72fc42a8c5ce9eeedf20ca3a11907bf29f
2015-09-01 13:56:39 -06:00