-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
688 additions
and
477 deletions.
There are no files selected for viewing
This file contains 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 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,6 +1,6 @@ | ||
dependencies: | ||
- name: common | ||
repository: oci://registry-1.docker.io/bitnamicharts | ||
version: 2.4.0 | ||
digest: sha256:b371e6f7f1449fa3abdcb97a04b0bbb2b5d36a4facb8e79041ac36a455b02bb0 | ||
generated: "2023-06-19T12:39:44.271254606+02:00" | ||
version: 2.19.3 | ||
digest: sha256:de997835d9ce9a9deefc2d70d8c62b11aa1d1a76ece9e86a83736ab9f930bf4d | ||
generated: "2024-06-03T18:43:30.71045378+02:00" |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{{- /* | ||
Copyright Broadcom, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: APACHE-2.0 | ||
*/}} | ||
|
||
{{- if .Values.autoscaling.enabled }} | ||
apiVersion: autoscaling/v2 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: {{ include "common.names.fullname" . }} | ||
namespace: {{ include "common.names.namespace" . | quote }} | ||
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }} | ||
{{- if .Values.commonAnnotations }} | ||
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} | ||
{{- end }} | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }} | ||
kind: Deployment | ||
name: {{ include "common.names.fullname" . }} | ||
minReplicas: {{ .Values.autoscaling.minReplicas }} | ||
maxReplicas: {{ .Values.autoscaling.maxReplicas }} | ||
metrics: | ||
{{- if .Values.autoscaling.targetMemory }} | ||
- type: Resource | ||
resource: | ||
name: memory | ||
{{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .) }} | ||
targetAverageUtilization: {{ .Values.autoscaling.targetMemory }} | ||
{{- else }} | ||
target: | ||
type: Utilization | ||
averageUtilization: {{ .Values.autoscaling.targetMemory }} | ||
{{- end }} | ||
{{- end }} | ||
{{- if .Values.autoscaling.targetCPU }} | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
{{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" .) }} | ||
targetAverageUtilization: {{ .Values.autoscaling.targetCPU }} | ||
{{- else }} | ||
target: | ||
type: Utilization | ||
averageUtilization: {{ .Values.autoscaling.targetCPU }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2024, CS GROUP - France, https://www.csgroup.eu/ | ||
# | ||
# This file is part of EODAG project | ||
# https://www.github.com/CS-SI/EODAG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import logging | ||
from typing import Any, Callable, Coroutine, Dict, TypeVar, cast | ||
|
||
import orjson | ||
from cachetools import LRUCache | ||
from fastapi import FastAPI, Request | ||
|
||
from eodag.rest.config import Settings | ||
from eodag.utils import urlsplit | ||
|
||
logger = logging.getLogger("eodag.rest.utils") | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def init_cache(app: FastAPI) -> None: | ||
"""Connect to local cache""" | ||
settings = Settings.from_environment() | ||
|
||
app.state.cache = LRUCache(maxsize=settings.cache_maxsize) | ||
|
||
|
||
async def cached( | ||
fn: Callable[[], Coroutine[Any, Any, T]], cache_key: str, request: Request | ||
) -> T: | ||
"""Either get the result from local cache or run the function and cache the result.""" | ||
settings = Settings.from_environment() | ||
|
||
host = urlsplit(cast(str, request.state.url_root)).netloc | ||
|
||
host_cache_key = f"{cache_key}:{host}" | ||
|
||
try: | ||
c: Dict[str, Any] = request.app.state.cache | ||
|
||
if cached := c.get(host_cache_key): | ||
logger.debug("Cache result hit") | ||
return orjson.loads(cached) # type: ignore | ||
except Exception as e: | ||
logger.error(f"Error in cache: {e}") | ||
if settings.debug: | ||
raise | ||
|
||
result = await fn() | ||
|
||
try: | ||
c[host_cache_key] = orjson.dumps(result) # type: ignore | ||
except Exception as e: | ||
logger.error(f"Error in cache: {e}") | ||
if settings.debug: | ||
raise | ||
|
||
return result |
This file contains 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2024, CS GROUP - France, https://www.csgroup.eu/ | ||
# | ||
# This file is part of EODAG project | ||
# https://www.github.com/CS-SI/EODAG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from __future__ import annotations | ||
|
||
from functools import lru_cache | ||
|
||
from pydantic import Field | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
|
||
from eodag.rest.constants import DEFAULT_MAXSIZE, DEFAULT_TTL | ||
|
||
|
||
class Settings(BaseSettings): | ||
"""EODAG Server config""" | ||
|
||
# local cache config | ||
cache_ttl: int = Field(default=DEFAULT_TTL) | ||
cache_maxsize: int = Field(default=DEFAULT_MAXSIZE) | ||
|
||
debug: bool = False | ||
|
||
model_config = SettingsConfigDict( | ||
env_prefix="EODAG_", extra="ignore", env_nested_delimiter="__" | ||
) | ||
|
||
@classmethod | ||
@lru_cache(maxsize=1) | ||
def from_environment(cls) -> Settings: | ||
"""Get settings""" | ||
return Settings() |
This file contains 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2024, CS GROUP - France, https://www.csgroup.eu/ | ||
# | ||
# This file is part of EODAG project | ||
# https://www.github.com/CS-SI/EODAG | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# default cache ttl | ||
DEFAULT_TTL = 600 # 10 min | ||
|
||
DEFAULT_MAXSIZE = 2048 # local cache maxsize | ||
|
||
CACHE_KEY_COLLECTIONS = "collections" | ||
CACHE_KEY_COLLECTION = "collection" | ||
CACHE_KEY_SEARCH = "search" | ||
CACHE_KEY_QUERYABLES = "queryables" | ||
CACHE_KEY_CATALOGS = "catalogs" |
Oops, something went wrong.