Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace cache+property with cached_property #107

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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