Add request_user_id metric

        Metrics:
             request_user_id
337858
def _set_request_user_id_metric(self, request):
        
        if hasattr(request, 'user') and hasattr(request.user, 'id') and request.user.id:
            monitoring.set_custom_metric('request_user_id', request.user.id)
954205
def add_metric(self, labels, count_value, sum_value, timestamp=None):
        
        self.samples.append(Sample(self.name + '_count', dict(zip(self._labelnames, labels)), count_value, timestamp))
        self.samples.append(Sample(self.name + '_sum', dict(zip(self._labelnames, labels)), sum_value, timestamp))
1230826
def set_metric(slug, value, category=None, expire=None, date=None):
    """"""
    get_r().set_metric(slug, value, category=category, expire=expire, date=date)
914475
def ticket_metrics(self, ticket_id, **kwargs):
        ""
        api_path = "/api/v2/tickets/{ticket_id}/metrics.json"
        api_path = api_path.format(ticket_id=ticket_id)
        return self.call(api_path, **kwargs)
1303576
def set_metric_ids(self, key, metric_ids):
        
        with self._lock:
            self._metric_ids[key] = metric_ids
431464
def _yarn_node_metrics(self, rm_address, instance, addl_tags):
        
        metrics_json = self._rest_request_to_json(rm_address, instance, YARN_NODES_PATH, addl_tags)

        if metrics_json and metrics_json['nodes'] is not None and metrics_json['nodes']['node'] is not None:

            for node_json in metrics_json['nodes']['node']:
                node_id = node_json['id']

                tags = ['node_id:{}'.format(str(node_id))]
                tags.extend(addl_tags)

                self._set_yarn_metrics_from_json(tags, node_json, YARN_NODE_METRICS)
626559
def _yarn_app_metrics(self, rm_address, instance, app_tags, addl_tags):
        
        metrics_json = self._rest_request_to_json(
            rm_address, instance, YARN_APPS_PATH, addl_tags, states=YARN_APPLICATION_STATES
        )

        if metrics_json and metrics_json['apps'] is not None and metrics_json['apps']['app'] is not None:

            for app_json in metrics_json['apps']['app']:

                tags = []
                for dd_tag, yarn_key in iteritems(app_tags):
                    try:
                        val = app_json[yarn_key]
                        if val:
                            tags.append('{tag}:{value}'.format(tag=dd_tag, value=val))
                    except KeyError:
                        self.log.error("Invalid value {} for application_tag".format(yarn_key))

                tags.extend(addl_tags)

                self._set_yarn_metrics_from_json(tags, app_json, YARN_APP_METRICS)
968231
def user_show(self, id, **kwargs):
        ""
        api_path = "/api/v2/users/{id}.json"
        api_path = api_path.format(id=id)
        return self.call(api_path, **kwargs)
171907
def query_metric_tags(self, metric_type, metric_id):
        
        definition = self._get(self._get_metrics_tags_url(self._get_metrics_single_url(metric_type, metric_id)))
        return definition
1174873
protected void registerMetrics() {
    if (metricType.equals(MetricType.DEBUG)
      || metricType.equals(MetricType.PERFORMANCE)) {
      metrics.addHistogram(OVERALL_AVG_BYTES_READ_METRIC);
      metrics.addHistogram(OVERALL_AVG_BYTES_WRITE_METRIC);
      metrics.addHistogram(OVERALL_AVG_TIME_ON_WIRE_METRIC);
      metrics.addMeter(OVERALL_RESPONSE_METRIC);
      metrics.addMeter(OVERALL_REQUEST_METRIC);

      if (metricType.equals(MetricType.DEBUG)) {
        metrics.addCounter(RECON_QUEUE_METRIC);
        metrics.addCounter(SHUTD_QUEUE_METRIC);
        metrics.addMeter(OVERALL_RESPONSE_RETRY_METRIC);
        metrics.addMeter(OVERALL_RESPONSE_SUCC_METRIC);
        metrics.addMeter(OVERALL_RESPONSE_FAIL_METRIC);
      }
    }
  }
737947
def post(method, hmc, uri, uri_parms, body, logon_required,
             wait_for_completion):
        """"""
        assert wait_for_completion is True  # always synchronous
        check_required_fields(method, uri, body,
                              ['anticipated-frequency-seconds'])
        new_metrics_context = hmc.metrics_contexts.add(body)
        result = {
            'metrics-context-uri': new_metrics_context.uri,
            'metric-group-infos': new_metrics_context.get_metric_group_infos()
        }
        return result
891256
def CollectMetrics(self, request, context):
        """"""
        LOG.debug("CollectMetrics called")
        try:
            metrics_to_collect = []
            for metric in request.metrics:
                metrics_to_collect.append(Metric(pb=metric))
            metrics_collected = self.plugin.collect(metrics_to_collect)
            return MetricsReply(metrics=[m.pb for m in metrics_collected])
        except Exception as err:
            msg = "message: {}\n\nstack trace: {}".format(
                err, traceback.format_exc())
            return MetricsReply(metrics=[], error=msg)
1320311
def refresh_metrics(self):
        """"""
        metrics = self.get_metrics()
        dbmetrics = (
            db.session.query(DruidMetric)
            .filter(DruidMetric.datasource_id == self.datasource_id)
            .filter(DruidMetric.metric_name.in_(metrics.keys()))
        )
        dbmetrics = {metric.metric_name: metric for metric in dbmetrics}
        for metric in metrics.values():
            dbmetric = dbmetrics.get(metric.metric_name)
            if dbmetric:
                for attr in ['json', 'metric_type']:
                    setattr(dbmetric, attr, getattr(metric, attr))
            else:
                with db.session.no_autoflush:
                    metric.datasource_id = self.datasource_id
                    db.session.add(metric)
616694
def extract_user_id(self, request):
        
        payload = self.extract_payload(request)
        user_id_attribute = self.config.user_id()
        return payload.get(user_id_attribute, None)
29387
public static String getMetricNameWithUserTag(String metricName, String userName) {
    UserMetricKey k = new UserMetricKey(metricName, userName);
    String result = CACHED_METRICS.get(k);
    if (result != null) {
      return result;
    }
    return CACHED_METRICS.computeIfAbsent(k, key -> metricName + "." + CommonMetrics.TAG_USER
        + TAG_SEPARATOR + userName);
  }
452917
def load_user(self, uid):
    
        '''
            
        '''
    
        title = '%s.load_user' % self.__class__.__name__
        
    # validate inputs
        input_fields = {
            'uid': uid
        }
        for key, value in input_fields.items():
            if value:
                object_title = '%s(%s=%s)' % (title, key, str(value))
                self.fields.validate(value, '.%s' % key, object_title)
    
    # construct url
        url = self.bucket_url + '/_user/%s' % uid
        
    # send request and unwrap response
        response = requests.get(url)
        response = response.json()
    
        return response
658917
def authenticated_userid(request):
    
    user = getattr(request, 'user', None)
    key = user.pk_field()
    return getattr(user, key)