Exemplo n.º 1
0
 def token_aware_policy_insights_serializer(policy):
     return {'type': policy.__class__.__name__,
             'namespace': namespace(policy.__class__),
             'options': {'child_policy': insights_registry.serialize(policy._child_policy,
                                                                     policy=True),
                         'shuffle_replicas': policy.shuffle_replicas}
             }
Exemplo n.º 2
0
 def execution_profile_insights_serializer(profile):
     return {
         'loadBalancing': insights_registry.serialize(profile.load_balancing_policy,
                                                      policy=True),
         'retry': insights_registry.serialize(profile.retry_policy,
                                              policy=True),
         'readTimeout': profile.request_timeout,
         'consistency': ConsistencyLevel.value_to_name.get(profile.consistency_level, None),
         'serialConsistency': ConsistencyLevel.value_to_name.get(profile.serial_consistency_level, None),
         'continuousPagingOptions': (insights_registry.serialize(profile.continuous_paging_options)
                                     if (profile.continuous_paging_options is not None and
                                        profile.continuous_paging_options is not _NOT_SET) else
                                     None),
         'speculativeExecution': insights_registry.serialize(profile.speculative_execution_policy),
         'graphOptions': None
     }
Exemplo n.º 3
0
 def wrapper_policy_insights_serializer(policy):
     return {'type': policy.__class__.__name__,
             'namespace': namespace(policy.__class__),
             'options': {
                 'child_policy': insights_registry.serialize(policy._child_policy,
                                                             policy=True)
             }}
Exemplo n.º 4
0
 def host_filter_policy_insights_serializer(policy):
     return {
         'type': policy.__class__.__name__,
         'namespace': namespace(policy.__class__),
         'options': {'child_policy': insights_registry.serialize(policy._child_policy,
                                                                 policy=True),
                     'predicate': policy.predicate.__name__}
     }
Exemplo n.º 5
0
    def profile_manager_insights_serializer(manager):
        defaults = {
            # Insights's expected default
            'default': insights_registry.serialize(manager.profiles[EXEC_PROFILE_DEFAULT]),
            # remaining named defaults for driver's defaults, including duplicated default
            'EXEC_PROFILE_DEFAULT': insights_registry.serialize(manager.profiles[EXEC_PROFILE_DEFAULT]),
            'EXEC_PROFILE_GRAPH_DEFAULT': insights_registry.serialize(manager.profiles[EXEC_PROFILE_GRAPH_DEFAULT]),
            'EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT': insights_registry.serialize(
                manager.profiles[EXEC_PROFILE_GRAPH_SYSTEM_DEFAULT]
            ),
            'EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT': insights_registry.serialize(
                manager.profiles[EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT]
            )
        }
        other = {
            key: insights_registry.serialize(value)
            for key, value in manager.profiles.items()
            if key not in _EXEC_PROFILE_DEFAULT_KEYS
        }
        overlapping_keys = set(defaults) & set(other)
        if overlapping_keys:
            log.debug('The following key names overlap default key sentinel keys '
                      'and these non-default EPs will not be displayed in Insights '
                      ': {}'.format(list(overlapping_keys)))

        other.update(defaults)
        return other
Exemplo n.º 6
0
    def _get_startup_data(self):
        cc = self._session.cluster.control_connection
        try:
            local_ipaddr = cc._connection._socket.getsockname()[0]
        except Exception as e:
            log.debug('Unable to get local socket addr from {}: {}'.format(cc._connection, e))
        hostname = socket.getfqdn()

        host_distances_counter = Counter(
            self._session.cluster.profile_manager.distance(host)
            for host in self._session.hosts
        )
        host_distances_dict = {
            'local': host_distances_counter[HostDistance.LOCAL],
            'remote': host_distances_counter[HostDistance.REMOTE],
            'ignored': host_distances_counter[HostDistance.IGNORED]
        }

        compression_type = cc._connection._compression_type if cc._connection else 'NONE'

        if self._session.cluster.ssl_context:
            cert_validation = self._session.cluster.ssl_context.verify_mode == ssl.CERT_REQUIRED
        elif self._session.cluster.ssl_options:
            cert_validation = self._session.cluster.ssl_options.get('cert_reqs') == ssl.CERT_REQUIRED
        else:
            cert_validation = None

        uname_info = platform.uname()

        return {
            'metadata': {
                'name': 'driver.startup',
                'insightMappingId': 'v1',
                'insightType': 'EVENT',
                'timestamp': ms_timestamp_from_datetime(datetime.datetime.utcnow()),
                'tags': {
                    'language': 'python'
                },
            },
            'data': {
                'driverName': 'DataStax Enterprise Python Driver',
                'driverVersion': sys.modules['dse'].__version__,
                'clientId': str(self._session.cluster.client_id),
                'sessionId': str(self._session.session_id),
                'applicationName': self._session.cluster.application_name or 'python',
                'applicationNameWasGenerated': not self._session.cluster.application_name,
                'applicationVersion': self._session.cluster.application_version,
                'contactPoints': self._session.cluster._endpoint_map_for_insights,
                'dataCenters': list(set(h.datacenter for h in self._session.cluster.metadata.all_hosts()
                                        if (h.datacenter and
                                            self._session.cluster.profile_manager.distance(h) == HostDistance.LOCAL))),
                'initialControlConnection': cc._connection.host if cc._connection else None,
                'protocolVersion': self._session.cluster.protocol_version,
                'localAddress': local_ipaddr,
                'hostName': hostname,
                'executionProfiles': insights_registry.serialize(self._session.cluster.profile_manager),
                'configuredConnectionLength': host_distances_dict,
                'heartbeatInterval': self._session.cluster.idle_heartbeat_interval,
                'compression': compression_type.upper() if compression_type else 'NONE',
                'reconnectionPolicy': insights_registry.serialize(self._session.cluster.reconnection_policy),
                'sslConfigured': {
                    'enabled': bool(self._session.cluster.ssl_options or self._session.cluster.ssl_context),
                    'certValidation': cert_validation
                },
                'authProvider': {
                    'type': (self._session.cluster.auth_provider.__class__.__name__
                             if self._session.cluster.auth_provider else
                             None)
                },
                'otherOptions': {
                },
                'platformInfo': {
                    'os': {
                        'name': uname_info.system if six.PY3 else uname_info[0],
                        'version': uname_info.release if six.PY3 else uname_info[2],
                        'arch': uname_info.machine if six.PY3 else uname_info[4]
                    },
                    'cpus': {
                        'length': multiprocessing.cpu_count(),
                        'model': platform.processor()
                    },
                    'runtime': {
                        'python': sys.version,
                        'event_loop': self._session.cluster.connection_class.__name__
                    }
                },
                'periodicStatusInterval': self._interval
            }
        }
Exemplo n.º 7
0
 def graph_execution_profile_insights_serializer(profile):
     rv = insights_registry.serialize(profile, cls=ExecutionProfile)
     rv['graphOptions'] = insights_registry.serialize(profile.graph_options)
     return rv