-
Notifications
You must be signed in to change notification settings - Fork 934
expose stats_cb #55
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
expose stats_cb #55
Changes from 1 commit
201b6b3
8f88eb1
73b363f
d7ab475
eb31ace
90d11df
495a836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,7 +36,8 @@ | |
| bootstrap_servers = 'localhost' | ||
|
|
||
|
|
||
|
|
||
| # global variable to be set by stats_cb call back function | ||
| good_stats_cb_result = False | ||
|
|
||
| def error_cb (err): | ||
| print('Error: %s' % err) | ||
|
|
@@ -359,9 +360,13 @@ def verify_stats_cb(): | |
| """ Verify stats_cb """ | ||
|
|
||
| def stats_cb(stats_json_str): | ||
| global good_stats_cb_result | ||
| stats_json = json.loads(stats_json_str) | ||
| if 'test' in stats_json['topics']: | ||
| print("# app_offset stats for topic test partition 0: %d" % stats_json['topics']['test']['partitions']['0']['app_offset']) | ||
| app_offset = stats_json['topics']['test']['partitions']['0']['app_offset'] | ||
|
Contributor
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. probably want to wrap this in a try: if any of the sub-dict keys are missing and just print the json blob on failure. |
||
| if app_offset > 0: | ||
| print("# app_offset stats for topic test partition 0: %d" % app_offset) | ||
| good_stats_cb_result = True | ||
|
|
||
| conf = {'bootstrap.servers': bootstrap_servers, | ||
| 'group.id': uuid.uuid1(), | ||
|
|
@@ -388,7 +393,7 @@ def stats_cb(stats_json_str): | |
| else: | ||
| bar = None | ||
|
|
||
| while True: | ||
| while not good_stats_cb_result: | ||
| # Consume until EOF or error | ||
|
|
||
| msg = c.poll(timeout=20.0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,15 @@ def test_version(): | |
| assert len(sver) > 0 | ||
| assert iver > 0 | ||
|
|
||
| # global variable for error_cb call back function | ||
| seen_error_cb = False | ||
|
|
||
| def test_error_cb(): | ||
| """ Tests error_cb. """ | ||
|
|
||
| def error_cb(error_msg): | ||
| print('OK: error_cb() called') | ||
| global seen_error_cb | ||
| seen_error_cb = True | ||
| assert error_msg.code() in (confluent_kafka.KafkaError._TRANSPORT, confluent_kafka.KafkaError._ALL_BROKERS_DOWN) | ||
|
|
||
| conf = {'bootstrap.servers': 'localhost:9093', # Purposely cause connection refused error | ||
|
Contributor
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. This is actually probably the second most likely port to find a broker on localhost, so maybe you want to connect to localhost:22 or somesuch that will definately not a Kafka broker. |
||
|
|
@@ -31,26 +35,23 @@ def error_cb(error_msg): | |
| } | ||
|
|
||
| kc = confluent_kafka.Consumer(**conf) | ||
|
|
||
| kc.subscribe(["test"]) | ||
| kc.poll(timeout=0.001) | ||
| time.sleep(1) | ||
| kc.unsubscribe() | ||
| while not seen_error_cb: | ||
| kc.poll(timeout=1) | ||
|
|
||
| kc.close() | ||
|
|
||
| # global variable for stats_cb call back function | ||
| seen_stats_cb = False | ||
|
|
||
| def test_stats_cb(): | ||
| """ Tests stats_cb. """ | ||
|
|
||
| def stats_cb(stats_json_str): | ||
| # print(stats_json_str) | ||
| try: | ||
| stats_json = json.loads(stats_json_str) | ||
| if 'type' in stats_json: | ||
| print("stats_cb: type=%s" % stats_json['type']) | ||
| print('OK: stats_cb() called') | ||
| except Exception as e: | ||
| assert False | ||
| global seen_stats_cb | ||
| seen_stats_cb = True | ||
| stats_json = json.loads(stats_json_str) | ||
| assert len(stats_json['name']) > 0 | ||
|
|
||
| conf = {'group.id':'test', | ||
| 'socket.timeout.ms':'100', | ||
|
|
@@ -62,8 +63,7 @@ def stats_cb(stats_json_str): | |
| kc = confluent_kafka.Consumer(**conf) | ||
|
|
||
| kc.subscribe(["test"]) | ||
|
Contributor
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. Same thing as suggested for error_cb |
||
| kc.poll(timeout=0.001) | ||
| time.sleep(1) | ||
|
|
||
| while not seen_stats_cb: | ||
| kc.poll(timeout=1) | ||
| kc.close() | ||
|
|
||
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.
We might want to check here and for error_cb if the object is callable (
PyCallable_Check(vo)) (Py_None is okay too)