Return a new metric where the name and all tags are using the valid character
set.
964214
public static Metric toValidValue(Metric metric) {
    MonitorConfig cfg = metric.getConfig();
    MonitorConfig.Builder cfgBuilder = MonitorConfig.builder(toValidCharset(cfg.getName()));
    for (Tag orig : cfg.getTags()) {
      final String key = orig.getKey();
      if (RELAXED_GROUP_KEYS.contains(key)) {
        cfgBuilder.withTag(key, toValidCharsetTable(CHARS_ALLOWED_GROUPS, orig.getValue()));
      } else {
        cfgBuilder.withTag(toValidCharset(key), toValidCharset(orig.getValue()));
      }
    }
    cfgBuilder.withPublishingPolicy(cfg.getPublishingPolicy());
    return new Metric(cfgBuilder.build(), metric.getTimestamp(), metric.getValue());
  }
813752
private void addMetric(
      List<Metric> metrics,
      String name,
      TagList tags,
      Object value) {
    long now = System.currentTimeMillis();
    if (onlyNumericMetrics) {
      value = asNumber(value);
    }
    if (value != null) {

      TagList newTags = counters.matches(MonitorConfig.builder(name).withTags(tags).build())
          ? getTagListWithAdditionalTag(tags, DataSourceType.COUNTER)
          : getTagListWithAdditionalTag(tags, DataSourceType.GAUGE);
      Metric m = new Metric(name, newTags, now, value);
      metrics.add(m);
    }
  }
1016025
def match_metric(regex):
    '''
    
    '''
    if _TRAFFICCTL:
        cmd = _traffic_ctl('metric', 'match', regex)
    else:
        cmd = _traffic_ctl('-m', regex)

    return _subprocess(cmd)
1305098
@Nonnull
    public static String escapeMetricNamePart(@Nonnull String namePart) {
        int i = 0;
        int l = namePart.length();
        while (i < l) {
            char ch = namePart.charAt(i);
            if (ch == ',' || ch == '=' || ch == '\\') {
                break;
            }
            i++;
        }
        if (i == l) {
            return namePart;
        }
        StringBuilder sb = new StringBuilder(namePart.length() + 3);
        sb.append(namePart, 0, i);
        while (i < l) {
            char ch = namePart.charAt(i++);
            if (ch == ',' || ch == '=' || ch == '\\') {
                sb.append('\\');
            }
            sb.append(ch);
        }
        return sb.toString();
    }
862369
def tag_info(self):
        """"""
        return self.__class__.__name__ + (
            '(%r)' % self.name if self.name
            else "") + ": " + self.valuestr()
74344
private String constructMetricQueryKey(Long startTimeStampBoundary, MetricQuery query) {
        StringBuilder sb = new StringBuilder();

        sb.append(startTimeStampBoundary).append(":");
        sb.append(query.getNamespace()).append(":");
        sb.append(query.getScope()).append(":");
        sb.append(query.getMetric()).append(":");

        // sort the tag key and values within each tag key alphabetically
        Map<String, String> treeMap = new TreeMap<String, String>();

        for (Map.Entry<String, String> tag : query.getTags().entrySet()) {
            String[] tagValues = tag.getValue().split("\\|");

            Arrays.sort(tagValues);

            StringBuilder sbTag = new StringBuilder();
            String separator = "";

            for (String tagValue : tagValues) {
                sbTag.append(separator);
                separator = "|";
                sbTag.append(tagValue);
            }
            treeMap.put(tag.getKey(), sbTag.toString());
        }
        sb.append(treeMap).append(":");
        sb.append(query.getAggregator()).append(":");
        sb.append(query.getDownsampler()).append(":");
        sb.append(query.getDownsamplingPeriod());
        return sb.toString();
    }
348329
public static MetricName build(String... parts) {
        if (parts == null || parts.length == 0)
            return MetricName.EMPTY;

        if (parts.length == 1)
            return new MetricName(parts[0], EMPTY_TAGS);

        return new MetricName(buildName(parts), EMPTY_TAGS);
    }
1128999
def _make_unique(name, idx):
    """"""
    p = re.compile(".[aA-zZ]+_x[0-9]+")
    if p.match(name):
        tags = name[1:].split("_x")
        return ">%s_%s_x%s" % (tags[0], idx, tags[1])
    return name.replace("@", ">")
957153
def _create_eval_metric(metric_name: str) -> mx.metric.EvalMetric:
        
        # output_names refers to the list of outputs this metric should use to update itself, e.g. the softmax output
        if metric_name == C.ACCURACY:
            return utils.Accuracy(ignore_label=C.PAD_ID, output_names=[C.SOFTMAX_OUTPUT_NAME], label_names=[C.TARGET_LABEL_NAME])
        elif metric_name == C.PERPLEXITY:
            return mx.metric.Perplexity(ignore_label=C.PAD_ID, output_names=[C.SOFTMAX_OUTPUT_NAME], label_names=[C.TARGET_LABEL_NAME], name=C.PERPLEXITY)
        elif metric_name == C.LENRATIO_MSE:
            return loss.LengthRatioMSEMetric(name=C.LENRATIO_MSE,
                                  output_names=[C.LENRATIO_OUTPUT_NAME], label_names=[C.LENRATIO_LABEL_OUTPUT_NAME])
        else:
            raise ValueError("unknown metric name")
124450
def _metric_value(value_str, metric_type):
    
    if metric_type in (int, float):
        try:
            return metric_type(value_str)
        except ValueError:
            raise ValueError("Invalid {} metric value: {!r}".
                             format(metric_type.__class__.__name__, value_str))
    elif metric_type is six.text_type:
        # In Python 3, decode('unicode_escape) requires bytes, so we need
        # to encode to bytes. This also works in Python 2.
        return value_str.strip('"').encode('utf-8').decode('unicode_escape')
    else:
        assert metric_type is bool
        lower_str = value_str.lower()
        if lower_str == 'true':
            return True
        elif lower_str == 'false':
            return False
        else:
            raise ValueError("Invalid boolean metric value: {!r}".
                             format(value_str))
1321852
def get_namespace_and_tag(name):
        

        if isinstance(name, str):
            if name[0] == "{":
                uri, ignore, tag = name[1:].partition("}")
            else:
                uri = None
                tag = name
        else:
            uri = None
            tag = None
        return uri, tag
1122192
public static String sanitizeMetricName(String metricName) {
    return SANITIZE_BODY_PATTERN.matcher(
            SANITIZE_PREFIX_PATTERN.matcher(metricName).replaceFirst("_")
    ).replaceAll("_");
  }
701185
def tag(name, tag_name):
    

    with LOCK:
        # just to check if <name> exists
        metric(name)

        TAGS.setdefault(tag_name, set()).add(name)
439282
def key_to_metric(self, key):
        """"""
        return ''.join(l if l in string.letters else '_' for l in key)
397868
def metric_parts(metric):
    """"""
    operator, met = resolve_metric_as_tuple(metric)
    return operator.name, met.name
133548
private String getQualifiedMetricName(String metricName) {
    try {
      if (SecurityUtils.isAuthenticationEnabled(mContext.getConf())
          && LoginUser.get(mContext.getConf()) != null) {
        return Metric.getMetricNameWithTags(metricName, CommonMetrics.TAG_USER,
            LoginUser.get(mContext.getConf()).getName());
      } else {
        return metricName;
      }
    } catch (IOException e) {
      return metricName;
    }
  }
857768
def valid(cls, data, context=None):
        """"""
        return cls(cls.TagType.VALID, data, context)