Exemplo n.º 1
0
def test_reserved_extra_keys():
    """
    Test that extra keys starting with 'glean.' are rejected for
    non-internal metrics.
    """
    with pytest.raises(ValueError):
        metrics.Event(
            type="event",
            category="category",
            name="metric",
            bugs=[42],
            notification_emails=["*****@*****.**"],
            description="description...",
            expires="never",
            extra_keys={"glean.internal": {"description": "foo"}},
        )

    metrics.Event(
        type="event",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
        extra_keys={"glean.internal": {"description": "foo"}},
        _config={"allow_reserved": True},
    )
Exemplo n.º 2
0
def test_metric_type_name():
    event = metrics.Event(
        type="event",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
        extra_keys={"my_extra": {
            "description": "an extra"
        }},
    )

    assert kotlin.type_name(event) == "EventMetricType<metricKeys>"

    event = metrics.Event(
        type="event",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
    )

    assert kotlin.type_name(event) == "EventMetricType<NoExtraKeys>"

    boolean = metrics.Boolean(
        type="boolean",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
    )
    assert kotlin.type_name(boolean) == "BooleanMetricType"

    ping = pings.Ping(
        name="custom",
        description="description...",
        include_client_id=True,
        bugs=[42],
        notification_emails=["*****@*****.**"],
    )
    assert kotlin.type_name(ping) == "PingType<NoReasonCodes>"

    ping = pings.Ping(
        name="custom",
        description="description...",
        include_client_id=True,
        bugs=[42],
        notification_emails=["*****@*****.**"],
        reasons={
            "foo": "foolicious",
            "bar": "barlicious"
        },
    )
    assert kotlin.type_name(ping) == "PingType<customReasonCodes>"
Exemplo n.º 3
0
def test_extra_info_generator():
    event = metrics.Event(
        type="event",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
        extra_keys={"my_extra": {
            "description": "an extra"
        }},
    )

    assert markdown.extra_info(event) == [("my_extra", "an extra")]

    # We don't currently support extra info for types other than events.
    other = metrics.Timespan(
        type="timespan",
        category="category",
        name="metric",
        bugs=[42],
        time_unit="day",
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
    )

    assert len(markdown.extra_info(other)) == 0
Exemplo n.º 4
0
def test_extra_info_generator():
    event = metrics.Event(
        type="event",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
        extra_keys={"my_extra": {
            "description": "an extra"
        }},
    )

    assert markdown.extra_info(event) == [("my_extra", "an extra")]

    labeled = metrics.LabeledCounter(
        type="labeled_counter",
        category="category",
        name="metric",
        bugs=[42],
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
        labels=["label"],
    )

    assert markdown.extra_info(labeled) == [("label", None)]

    # We currently support extra info only for events and labeled types.
    other = metrics.Timespan(
        type="timespan",
        category="category",
        name="metric",
        bugs=[42],
        time_unit="day",
        notification_emails=["*****@*****.**"],
        description="description...",
        expires="never",
    )

    assert len(markdown.extra_info(other)) == 0