1
1
import logging
2
2
3
3
from localstack .http import Response
4
- from localstack .utils .analytics .usage import UsageSetCounter
4
+ from localstack .utils .analytics .metrics import Counter , LabeledCounterMetric
5
5
6
6
from ..api import RestApiGatewayHandler , RestApiGatewayHandlerChain
7
7
from ..context import RestApiInvocationContext
10
10
11
11
12
12
class IntegrationUsageCounter (RestApiGatewayHandler ):
13
- counter : UsageSetCounter
13
+ counter : LabeledCounterMetric
14
14
15
- def __init__ (self , counter : UsageSetCounter = None ):
16
- self .counter = counter or UsageSetCounter (namespace = "apigateway:invokedrest" )
15
+ def __init__ (self , counter : LabeledCounterMetric = None ):
16
+ self .counter = counter or Counter (
17
+ namespace = "apigateway" , name = "rest_api_execute" , labels = ["invocation_type" ]
18
+ )
17
19
18
20
def __call__ (
19
21
self ,
@@ -31,7 +33,7 @@ def __call__(
31
33
# hence we should count it as a NOT_FOUND invocation
32
34
invocation_type = "NOT_FOUND"
33
35
34
- self .counter .record (invocation_type )
36
+ self .counter .labels (invocation_type = invocation_type ). increment ( )
35
37
36
38
@staticmethod
37
39
def _get_aws_integration_service (integration_uri : str ) -> str :
@@ -41,4 +43,8 @@ def _get_aws_integration_service(integration_uri: str) -> str:
41
43
if len (split_arn := integration_uri .split (":" , maxsplit = 5 )) < 4 :
42
44
return "null"
43
45
44
- return split_arn [4 ]
46
+ service = split_arn [4 ]
47
+ # the URI can also contain some <api-id>.<service>-api kind of route like `execute-api` or `appsync-api`
48
+ # we need to make sure we do not pass the full value back
49
+ service = service .split ("." )[- 1 ]
50
+ return service
0 commit comments