Skip to content

Commit

Permalink
Replace cache+property with cached_property (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wh1isper authored Dec 7, 2023
1 parent 3eb8745 commit c768ccd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
18 changes: 5 additions & 13 deletions duetector/analyzer/jaeger/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,17 @@
from google.protobuf.duration_pb2 import Duration
from google.protobuf.timestamp_pb2 import Timestamp

from duetector.analyzer.jaeger.proto import model_pb2
from duetector.exceptions import AnalysQueryError
from duetector.utils import get_grpc_cred_from_path

try:
from functools import cache
except ImportError:
from functools import lru_cache as cache

from duetector.analyzer.base import Analyzer
from duetector.analyzer.jaeger.proto import model_pb2
from duetector.analyzer.jaeger.proto.model_pb2 import Span
from duetector.analyzer.jaeger.proto.query_pb2 import *
from duetector.analyzer.jaeger.proto.query_pb2_grpc import *
from duetector.analyzer.models import AnalyzerBrief, Brief, Tracking
from duetector.exceptions import AnalysQueryError
from duetector.extension.analyzer import hookimpl
from duetector.log import logger
from duetector.otel import OTelInspector
from duetector.utils import get_grpc_cred_from_path

ChannelInitializer = Callable[[], grpc.aio.Channel]

Expand Down Expand Up @@ -217,8 +211,7 @@ class JaegerAnalyzer(Analyzer):
def __init__(self, config: dict[str, Any] | None = None, *args, **kwargs):
super().__init__(config, *args, **kwargs)

@property
@cache
@functools.cached_property
def channel_initializer(self) -> ChannelInitializer:
"""
Example:
Expand All @@ -242,8 +235,7 @@ def channel_initializer(self) -> ChannelInitializer:

return functools.partial(target_func, **kwargs)

@property
@cache
@functools.cached_property
def connector(self):
return JaegerConnector(self.channel_initializer)

Expand Down
10 changes: 4 additions & 6 deletions duetector/injectors/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import signal
from datetime import datetime, timedelta
from functools import cached_property
from pathlib import Path
from threading import Event, Thread
from typing import Any, Dict, List, Optional
Expand Down Expand Up @@ -218,8 +219,7 @@ class Inspector:
prefix = "inspector"
name = None

@property
@cache
@cached_property
def id(self) -> str:
return with_prefix(self.sep, self.prefix, self.name or self.__class__.__name__)

Expand Down Expand Up @@ -262,8 +262,7 @@ def stop(self):


class NamespaceInspector(Inspector):
@property
@cache
@cached_property
def name(self) -> str:
return self.sep.join(["proc", "namespace"])

Expand All @@ -290,8 +289,7 @@ def stop(self):


class CgroupInspector(Inspector):
@property
@cache
@cached_property
def name(self) -> str:
return self.sep.join(["proc", "cgroup"])

Expand Down

0 comments on commit c768ccd

Please sign in to comment.