Skip to content

Commit

Permalink
Handle all exceptions while publishing in discovery client
Browse files Browse the repository at this point in the history
Add stats to discovery client and make them avaiable via
API server introspect.

Change-Id: I2941b9bf4d8bdf89286eb166091a04058edcf884
Partial-Bug: #1534342
  • Loading branch information
Deepinder Setia committed Feb 4, 2016
1 parent 731710e commit 81c0909
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 106 deletions.
3 changes: 3 additions & 0 deletions src/config/api-server/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ cfixture_rule = env.Install("vnc_cfg_api_server/gen", "../common/cfixture.py")

doc_sources_rules = SConscript(dirs=['doc'], exports = 'CfgmEnv')

discovery_client_stats_pkg = env.SandeshGenPy('discovery_client_stats.sandesh', 'vnc_cfg_api_server/sandesh/', False)
sandesh_trace_pkg = env.SandeshGenPy('traces.sandesh', 'vnc_cfg_api_server/sandesh/', False)

sdist_depends = [generated_rule, generateds_rule, cfixture_rule]
sdist_depends.extend(setup_sources_rules)
sdist_depends.extend(local_sources_rules)
sdist_depends.extend(doc_sources_rules)
sdist_depends.extend(discovery_client_stats_pkg)
sdist_depends.extend(sandesh_trace_pkg)

cd_cmd = 'cd ' + Dir('.').path + ' && '
Expand All @@ -115,6 +117,7 @@ env.Depends(sdist_gen, sdist_depends)
# Documentation
doc_files = []
doc_files += env.SandeshGenDoc('traces.sandesh')
doc_files += env.SandeshGenDoc('discovery_client_stats.sandesh')
doc_files += env['CFGM_DOC_FILES']

if 'install' in BUILD_TARGETS:
Expand Down
61 changes: 61 additions & 0 deletions src/config/api-server/discovery_client_stats.sandesh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// Introspect structs for API server
//
// Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
//

struct SubscriberStats {
1: string service_type;
2: u32 Request;
3: u32 Response;
4: string HttpError;
5: u32 ConnError;
6: u32 Timeout;
7: u32 unknown_exceptions;
8: string exception_info;
}

struct PublisherStats {
1: string service_type;
2: u32 Request;
3: u32 Response;
4: string HttpError;
5: u32 ConnError;
6: u32 Timeout;
7: u32 unknown_exceptions;
8: string exception_info;
}

request sandesh DiscoveryClientStatsReq {
}

response sandesh DiscoveryClientStatsResp {
1: list<PublisherStats> Publish;
2: list<SubscriberStats> Subscribe;
}

struct SubscribeInfo {
1: string service_type;
2: u32 instances;
3: u32 ttl;
4: string blob;
}

request sandesh DiscoveryClientSubscribeInfoReq {
}

response sandesh DiscoveryClientSubscribeInfoResp {
1: list<SubscribeInfo> Subscribe;
}

struct PublishInfo {
1: string service_type;
2: string blob;
}

request sandesh DiscoveryClientPublishInfoReq {
}

response sandesh DiscoveryClientPublishInfoResp {
1: list<PublishInfo> Publish
}
66 changes: 65 additions & 1 deletion src/config/api-server/vnc_cfg_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
from cfgm_common.uve.cfgm_cpuinfo.ttypes import NodeStatusUVE, \
NodeStatus

from sandesh.discovery_client_stats import ttypes as sandesh
from sandesh.traces.ttypes import RestApiTrace
from vnc_bottle import get_bottle_server

Expand Down Expand Up @@ -1371,6 +1372,9 @@ def __init__(self, args_str=None):
if self._args.sandesh_send_rate_limit is not None:
SandeshSystem.set_sandesh_send_rate_limit(
self._args.sandesh_send_rate_limit)
sandesh.DiscoveryClientStatsReq.handle_request = self.sandesh_disc_client_stats_handle_request
sandesh.DiscoveryClientSubscribeInfoReq.handle_request = self.sandesh_disc_client_subinfo_handle_request
sandesh.DiscoveryClientPublishInfoReq.handle_request = self.sandesh_disc_client_pubinfo_handle_request
module = Module.API_SERVER
module_name = ModuleNames[Module.API_SERVER]
node_type = Module2NodeType[module]
Expand All @@ -1385,7 +1389,7 @@ def __init__(self, args_str=None):
self._args.collectors,
'vnc_api_server_context',
int(self._args.http_server_port),
['cfgm_common'], self._disc,
['cfgm_common', 'vnc_cfg_api_server.sandesh'], self._disc,
logger_class=self._args.logger_class,
logger_config_file=self._args.logging_conf)
self._sandesh.trace_buffer_create(name="VncCfgTraceBuf", size=1000)
Expand Down Expand Up @@ -1457,6 +1461,66 @@ def __init__(self, args_str=None):

# end __init__

def sandesh_disc_client_subinfo_handle_request(self, req):
stats = self._disc.get_stats()
resp = sandesh.DiscoveryClientSubscribeInfoResp(Subscribe=[])

for sub in stats['subs']:
info = sandesh.SubscribeInfo(service_type=sub['service_type'])
info.instances = sub['instances']
info.ttl = sub['ttl']
info.blob = sub['blob']
resp.Subscribe.append(info)

resp.response(req.context())
# end

def sandesh_disc_client_pubinfo_handle_request(self, req):
stats = self._disc.get_stats()
resp = sandesh.DiscoveryClientPublishInfoResp(Publish=[])

for service_type, pub in stats['pubs'].items():
info = sandesh.PublishInfo(service_type=service_type)
info.blob = pub['blob']
resp.Publish.append(info)

resp.response(req.context())
# end

# Return discovery client stats
def sandesh_disc_client_stats_handle_request(self, req):
stats = self._disc.get_stats()
resp = sandesh.DiscoveryClientStatsResp(Subscribe=[], Publish=[])

# pub stats
for service_type, pub in stats['pubs'].items():
pub_stats = sandesh.PublisherStats(service_type=service_type)
pub_stats.Request = pub['request']
pub_stats.Response = pub['response']
pub_stats.ConnError = pub['conn_error']
pub_stats.Timeout = pub['timeout']
pub_stats.unknown_exceptions = pub['exc_unknown']
pub_stats.exception_info = pub['exc_info']
xxx = ['%s:%d' % (k[3:], v) for k, v in pub.items() if 'sc_' in k]
pub_stats.HttpError = ", ".join(xxx)
resp.Publish.append(pub_stats)

# sub stats
for sub in stats['subs']:
sub_stats = sandesh.SubscriberStats(service_type=sub['service_type'])
sub_stats.Request = sub['request']
sub_stats.Response = sub['response']
sub_stats.ConnError = sub['conn_error']
sub_stats.Timeout = sub['timeout']
sub_stats.unknown_exceptions = sub['exc_unknown']
sub_stats.exception_info = sub['exc_info']
xxx = ['%s:%d' % (k[3:], v) for k, v in sub.items() if 'sc_' in k]
sub_stats.HttpError = ", ".join(xxx)
resp.Subscribe.append(sub_stats)

resp.response(req.context())
# end sandesh_disc_client_stats_handle_request

def _extensions_transform_request(self, request):
extensions = self._extension_mgrs.get('resourceApi')
if not extensions or not extensions.names():
Expand Down
1 change: 0 additions & 1 deletion src/config/common/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ class TestCase(testtools.TestCase, fixtures.TestWithFixtures):
(disc_client.DiscoveryClient, 'publish',stub),
(disc_client.DiscoveryClient, 'subscribe',stub),
(disc_client.DiscoveryClient, 'syslog',stub),
(disc_client.DiscoveryClient, 'def_pub',stub),

(kazoo.client.KazooClient, '__new__',FakeKazooClient),
(kazoo.handlers.gevent.SequentialGeventHandler, '__init__',stub),
Expand Down

0 comments on commit 81c0909

Please sign in to comment.