-
Notifications
You must be signed in to change notification settings - Fork 0
fix: frontend tests added #121
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db014e7
feat/fix: more tests, also simplified sse block: now using Notificati…
HardMax71 f4ad102
fix: env var turning off otel stuff for backend/unit tests
HardMax71 361b926
fix: single init point for metrics, fixed part of tests
HardMax71 82a9b6c
fix: locale in formatters.test.ts
HardMax71 f23498b
more tests + added svelte config file
HardMax71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,76 +1,27 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter | ||
| from opentelemetry.metrics import Meter, NoOpMeterProvider | ||
| from opentelemetry.sdk.metrics import MeterProvider as SdkMeterProvider | ||
| from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader | ||
| from opentelemetry.sdk.resources import Resource | ||
| from opentelemetry import metrics | ||
|
|
||
| from app.settings import Settings | ||
|
|
||
|
|
||
| @dataclass | ||
| class MetricsConfig: | ||
| service_name: str = "integr8scode-backend" | ||
| service_version: str = "1.0.0" | ||
| otlp_endpoint: str | None = None | ||
| export_interval_millis: int = 10000 | ||
| console_export_interval_millis: int = 60000 | ||
|
|
||
|
|
||
| class BaseMetrics: | ||
| def __init__(self, settings: Settings, meter_name: str | None = None): | ||
| """Initialize base metrics with its own meter. | ||
| """Initialize base metrics with a meter from the global MeterProvider. | ||
|
|
||
| The global MeterProvider is configured once by ``setup_metrics``. | ||
| If it hasn't been called (e.g. in tests), the default no-op provider is used. | ||
|
|
||
| Args: | ||
| settings: Application settings. | ||
| settings: Application settings (kept for DI compatibility). | ||
| meter_name: Optional name for the meter. Defaults to class name. | ||
| """ | ||
| config = MetricsConfig( | ||
| service_name=settings.TRACING_SERVICE_NAME or "integr8scode-backend", | ||
| service_version="1.0.0", | ||
| otlp_endpoint=settings.OTEL_EXPORTER_OTLP_ENDPOINT, | ||
| ) | ||
|
|
||
| meter_name = meter_name or self.__class__.__name__ | ||
| self._meter = self._create_meter(settings, config, meter_name) | ||
| self._meter = metrics.get_meter(meter_name) | ||
| self._create_instruments() | ||
|
|
||
| def _create_meter(self, settings: Settings, config: MetricsConfig, meter_name: str) -> Meter: | ||
| """Create a new meter instance for this collector. | ||
|
|
||
| Args: | ||
| settings: Application settings | ||
| config: Metrics configuration | ||
| meter_name: Name for this meter | ||
|
|
||
| Returns: | ||
| A new meter instance | ||
| """ | ||
| # If tracing/metrics disabled or no OTLP endpoint configured, use NoOp meter | ||
| if not config.otlp_endpoint: | ||
| return NoOpMeterProvider().get_meter(meter_name) | ||
|
|
||
| resource = Resource.create( | ||
| {"service.name": config.service_name, "service.version": config.service_version, "meter.name": meter_name} | ||
| ) | ||
|
|
||
| reader = PeriodicExportingMetricReader( | ||
| exporter=OTLPMetricExporter(endpoint=config.otlp_endpoint), | ||
| export_interval_millis=config.export_interval_millis, | ||
| ) | ||
|
|
||
| # Each collector gets its own MeterProvider | ||
| meter_provider = SdkMeterProvider(resource=resource, metric_readers=[reader]) | ||
|
|
||
| # Return a meter from this provider | ||
| return meter_provider.get_meter(meter_name) | ||
|
|
||
| def _create_instruments(self) -> None: | ||
| """Create metric instruments. Override in subclasses.""" | ||
| pass | ||
|
|
||
| def close(self) -> None: | ||
| """Close the metrics collector and clean up resources.""" | ||
| # Subclasses can override if they need cleanup | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.