Exemplo n.º 1
0
    def __post_init__(self):
        from kazoo.client import KazooClient

        if self.ssl:
            if isinstance(self.ssl.server_verify, str):
                self._client = KazooClient(
                    hosts=self.hosts,
                    timeout=self.timeout,
                    handler=SecureSequentialThreadingHandler(),
                    use_ssl=True,
                    verify_certs=True,
                    ca=self.ssl.server_verify,
                    certfile=self.ssl.client_cert_path,
                    keyfile=self.ssl.client_key_path,
                )
            elif isinstance(self.ssl.server_verify, bool):
                self._client = KazooClient(
                    hosts=self.hosts,
                    timeout=self.timeout,
                    handler=SecureSequentialThreadingHandler(),
                    use_ssl=True,
                    verify_certs=self.ssl.server_verify,
                    certfile=self.ssl.client_cert_path,
                    keyfile=self.ssl.client_key_path,
                )

            else:
                raise ValidationError(
                    'SSL server verify must be type of Path or boolean!')
        else:
            self._client = KazooClient(hosts=self.hosts, timeout=self.timeout)

        self._client.start()
Exemplo n.º 2
0
def check_kafka_dependency():
    if confluent_kafka is None:
        log.error(confluent_kafka_import_error)
        raise ValidationError(confluent_kafka_import_error)
Exemplo n.º 3
0
 def __post_init__(self):
     if self.client_key_path and not self.client_cert_path:
         # There is only client key path, that is wrong, throw error.
         raise ValidationError(
                 'Provided client key without certificate!')
Exemplo n.º 4
0
    def __init__(
            self,
            node: Node,
            metrics_storage: Storage = DEFAULT_STORAGE,
            interval: Numeric(0, 60) = 1.,
            rdt_enabled: Optional[bool] = None,
            gather_hw_mm_topology: Optional[bool] = None,
            extra_labels: Optional[Dict[Str, Str]] = None,
            event_names: List[str] = [],
            perf_aggregate_cpus: bool = True,
            enable_derived_metrics: bool = False,
            uncore_event_names: List[Union[List[str], str]] = [],
            task_label_generators: Optional[Dict[str, TaskLabelGenerator]] = None,
            allocation_configuration: Optional[AllocationConfiguration] = None,
            wss_reset_cycles: Optional[int] = None,
            wss_stable_cycles: int = 0,
            wss_membw_threshold: Optional[float] = None,
            include_optional_labels: bool = False,
            zoneinfo: Union[Str, bool] = True,
            vmstat: Union[Str, bool] = True,
            sched: Union[Str, bool] = False,
    ):

        self._node = node
        self._metrics_storage = metrics_storage
        self._interval = interval
        self._rdt_enabled = rdt_enabled
        self._gather_hw_mm_topology = gather_hw_mm_topology
        self._include_optional_labels = include_optional_labels

        self._extra_labels = {k: str(v) for k, v in
                              extra_labels.items()} if extra_labels else dict()
        log.debug('Extra labels: %r', self._extra_labels)
        self._finish = False  # Guard to stop iterations.
        self._last_iteration = time.time()  # Used internally by wait function.
        self._allocation_configuration = allocation_configuration
        self._event_names = event_names
        self._perf_aggregate_cpus = perf_aggregate_cpus

        # TODO: fix those workarounds for dynamic levels and dynamic perf event metrics.
        # First add dynamic metrics
        for event_name in event_names:
            # is dynamic raw event
            if '__r' in event_name:
                log.debug('Creating metadata for dynamic metric: %r', event_name)
                METRICS_METADATA[event_name] = MetricMetadata(
                    'Hardware PMU counter (raw event)',
                    MetricType.COUNTER,
                    MetricUnit.NUMERIC,
                    MetricSource.PERF_SUBSYSTEM_WITH_CGROUPS,
                    MetricGranularity.TASK,
                    [],
                    'no (event_names)',
                )
        # We had the modify levels for all metrics
        # The set proper levels based on perf_aggregate_cpus value
        if not perf_aggregate_cpus:
            log.debug('Enabling "cpu" level for PERF_SUBSYSTEM_WITH_CGROUPS and derived metrics.')
            for metric_metadata in METRICS_METADATA.values():
                if metric_metadata.source == MetricSource.PERF_SUBSYSTEM_WITH_CGROUPS:
                    metric_metadata.levels = ['cpu']
                if metric_metadata.source == MetricSource.DERIVED_PERF_WITH_CGROUPS:
                    metric_metadata.levels = ['cpu']

        self._enable_derived_metrics = enable_derived_metrics
        self._uncore_events = uncore_event_names

        self._task_label_generators = task_label_generators or {}

        self._wss_reset_cycles = wss_reset_cycles
        self._wss_stable_cycles = wss_stable_cycles
        self._wss_membw_threshold = wss_membw_threshold

        self._uncore_pmu = None

        self._initialize_rdt_callback = None
        self._iterate_body_callback = None
        self._cached_bandwidth = None

        if zoneinfo is True:
            self._zoneinfo = zoneinfo
            zoneinfo_regexp = zoneinfo_module.DEFAULT_REGEXP
            log.debug('Enabled zoneinfo collection')
        elif zoneinfo is False:
            self._zoneinfo = zoneinfo
            log.debug('Disabled zoneinfo collection')
            zoneinfo_regexp = None
        else:
            zoneinfo_regexp = zoneinfo
            self._zoneinfo = True

        # Validate zoneinfo regexp.
        log.debug('zoneinfo=%r regexp=%r', self._zoneinfo, zoneinfo_regexp)
        self._zoneinfo_regexp_compiled = None
        if self._zoneinfo:
            try:
                self._zoneinfo_regexp_compiled = re.compile(zoneinfo_regexp)
            except re.error as e:
                raise ValidationError('zoneinfo_regexp_compile improper regexp: %s' % e)

            if not self._zoneinfo_regexp_compiled.groups == 2:
                raise ValidationError(
                    'zoneinfo_regexp_compile improper number of groups: should be 2')

        # Validate config and vmstat regexp.
        if vmstat in (True, False):
            self._vmstat = vmstat
        else:
            # Got regexp - compile and check...
            try:
                self._vmstat = re.compile(vmstat)
            except re.error as e:
                raise ValidationError('vmstat_regexp_compile improper regexp: %s' % e)

        # Validate config and sched regexp.
        if sched in (True, False):
            self._sched = sched
        else:
            # Got regexp - compile and check...
            try:
                self._sched = re.compile(sched)
            except re.error as e:
                raise ValidationError('sched regex compile improper regexp: %s' % e)