File: test_xray.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (144 lines) | stat: -rw-r--r-- 4,076 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import datetime
import json

import boto3

from moto import mock_aws


@mock_aws
def test_put_telemetry():
    client = boto3.client("xray", region_name="us-east-1")

    client.put_telemetry_records(
        TelemetryRecords=[
            {
                "Timestamp": datetime.datetime(2015, 1, 1),
                "SegmentsReceivedCount": 123,
                "SegmentsSentCount": 123,
                "SegmentsSpilloverCount": 123,
                "SegmentsRejectedCount": 123,
                "BackendConnectionErrors": {
                    "TimeoutCount": 123,
                    "ConnectionRefusedCount": 123,
                    "HTTPCode4XXCount": 123,
                    "HTTPCode5XXCount": 123,
                    "UnknownHostCount": 123,
                    "OtherCount": 123,
                },
            }
        ],
        EC2InstanceId="string",
        Hostname="string",
        ResourceARN="string",
    )


@mock_aws
def test_put_trace_segments():
    client = boto3.client("xray", region_name="us-east-1")

    client.put_trace_segments(
        TraceSegmentDocuments=[
            json.dumps(
                {
                    "name": "example.com",
                    "id": "70de5b6f19ff9a0a",
                    "start_time": 1.478293361271e9,
                    "trace_id": "1-581cf771-a006649127e371903a2de979",
                    "end_time": 1.478293361449e9,
                }
            )
        ]
    )


@mock_aws
def test_trace_summary():
    client = boto3.client("xray", region_name="us-east-1")

    client.put_trace_segments(
        TraceSegmentDocuments=[
            json.dumps(
                {
                    "name": "example.com",
                    "id": "70de5b6f19ff9a0a",
                    "start_time": 1.478293361271e9,
                    "trace_id": "1-581cf771-a006649127e371903a2de979",
                    "in_progress": True,
                }
            ),
            json.dumps(
                {
                    "name": "example.com",
                    "id": "70de5b6f19ff9a0b",
                    "start_time": 1478293365,
                    "trace_id": "1-581cf771-a006649127e371903a2de979",
                    "end_time": 1478293385,
                }
            ),
        ]
    )

    client.get_trace_summaries(
        StartTime=datetime.datetime(2014, 1, 1), EndTime=datetime.datetime(2017, 1, 1)
    )


@mock_aws
def test_batch_get_trace():
    client = boto3.client("xray", region_name="us-east-1")

    client.put_trace_segments(
        TraceSegmentDocuments=[
            json.dumps(
                {
                    "name": "example.com",
                    "id": "70de5b6f19ff9a0a",
                    "start_time": 1.478293361271e9,
                    "trace_id": "1-581cf771-a006649127e371903a2de979",
                    "in_progress": True,
                }
            ),
            json.dumps(
                {
                    "name": "example.com",
                    "id": "70de5b6f19ff9a0b",
                    "start_time": 1478293365,
                    "trace_id": "1-581cf771-a006649127e371903a2de979",
                    "end_time": 1478293385,
                }
            ),
        ]
    )

    resp = client.batch_get_traces(
        TraceIds=[
            "1-581cf771-a006649127e371903a2de979",
            "1-581cf772-b006649127e371903a2de979",
        ]
    )
    assert len(resp["UnprocessedTraceIds"]) == 1
    assert len(resp["Traces"]) == 1


# Following are not implemented, just testing it returns what boto expects
@mock_aws
def test_batch_get_service_graph():
    client = boto3.client("xray", region_name="us-east-1")

    client.get_service_graph(
        StartTime=datetime.datetime(2014, 1, 1), EndTime=datetime.datetime(2017, 1, 1)
    )


@mock_aws
def test_batch_get_trace_graph():
    client = boto3.client("xray", region_name="us-east-1")

    client.batch_get_traces(
        TraceIds=[
            "1-581cf771-a006649127e371903a2de979",
            "1-581cf772-b006649127e371903a2de979",
        ]
    )