Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'releases/1.28.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcalvo committed May 9, 2024
2 parents a8de127 + 5989978 commit 63d4875
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 50 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ These are the section headers that we use:

## [Unreleased]()

## [1.28.0](https://github.com/argilla-io/argilla-server/compare/v1.27.0...v1.28.0)

### Added

- Added support to specify a list of score values for suggestions `score` attribute. ([#98](https://github.com/argilla-io/argilla-server/pull/98))
- Added `GET /api/v1/settings` new endpoint exposing Argilla and Hugging Face settings when available. ([#127](https://github.com/argilla-io/argilla-server/pull/127))
- Added `ARGILLA_SHOW_HUGGINGFACE_SPACE_PERSISTANT_STORAGE_WARNING` new environment variable to disable warning message when Hugging Face Spaces persistent storage is disabled. ([#124](https://github.com/argilla-io/argilla-server/pull/124))
- Added `ARGILLA_SHOW_HUGGINGFACE_SPACE_PERSISTENT_STORAGE_WARNING` new environment variable to disable warning message when Hugging Face Spaces persistent storage is disabled. ([#124](https://github.com/argilla-io/argilla-server/pull/124))
- Added `options_order` new settings attribute to support specify an order for options in multi label selection questions. ([#133](https://github.com/argilla-io/argilla-server/pull/133))
- Added `POST /api/v1/datasets/:dataset_id/records/bulk` endpoint. ([#106](https://github.com/argilla-io/argilla-server/pull/106))
- Added `PUT /api/v1/datasets/:dataset_id/records/bulk` endpoint. ([#106](https://github.com/argilla-io/argilla-server/pull/106))
Expand Down
4 changes: 2 additions & 2 deletions src/argilla_server/contexts/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def _get_argilla_settings() -> ArgillaSettings:
argilla_settings = ArgillaSettings()

if _get_huggingface_settings():
argilla_settings.show_huggingface_space_persistant_storage_warning = (
settings.show_huggingface_space_persistant_storage_warning
argilla_settings.show_huggingface_space_persistent_storage_warning = (
settings.show_huggingface_space_persistent_storage_warning
)

return argilla_settings
Expand Down
6 changes: 4 additions & 2 deletions src/argilla_server/schemas/v1/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class ArgillaSettings(BaseModel):
show_huggingface_space_persistant_storage_warning: Optional[bool]
show_huggingface_space_persistent_storage_warning: Optional[bool]


class HuggingfaceSettings(BaseSettings):
Expand All @@ -28,7 +28,9 @@ class HuggingfaceSettings(BaseSettings):
space_host: str = Field(None, env="SPACE_HOST")
space_repo_name: str = Field(None, env="SPACE_REPO_NAME")
space_author_name: str = Field(None, env="SPACE_AUTHOR_NAME")
space_persistant_storage_enabled: bool = Field(False, env="PERSISTANT_STORAGE_ENABLED")
# NOTE: Hugging Face has a typo in their environment variable name,
# using PERSISTANT instead of PERSISTENT. We will use the correct spelling in our code.
space_persistent_storage_enabled: bool = Field(False, env="PERSISTANT_STORAGE_ENABLED")

@property
def is_running_on_huggingface(self) -> bool:
Expand Down
4 changes: 2 additions & 2 deletions src/argilla_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ class Settings(BaseSettings):
)

# Hugging Face settings
show_huggingface_space_persistant_storage_warning: bool = Field(
show_huggingface_space_persistent_storage_warning: bool = Field(
default=True,
description="If True, show a warning when Hugging Face space persistant storage is disabled",
description="If True, show a warning when Hugging Face space persistent storage is disabled",
)

# See also the telemetry.py module
Expand Down
38 changes: 23 additions & 15 deletions src/argilla_server/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
from argilla_server.constants import DEFAULT_USERNAME
from argilla_server.models import User
from argilla_server.settings import settings
from argilla_server.utils._telemetry import is_running_on_docker_container, server_deployment_type
from argilla_server.utils._telemetry import (
is_running_on_docker_container,
is_running_on_huggingface_space,
server_deployment_type,
)

try:
from analytics import Client # This import works only for version 2.2.0
Expand Down Expand Up @@ -54,13 +58,6 @@ def server_id(self) -> uuid.UUID:
def __post_init__(self, enable_telemetry: bool, disable_send: bool, api_key: str, host: str):
from argilla_server._version import __version__

self.client = None
if enable_telemetry:
try:
self.client = Client(write_key=api_key, gzip=True, host=host, send=not disable_send, max_retries=10)
except Exception as err:
_LOGGER.warning(f"Cannot initialize telemetry. Error: {err}. Disabling...")

self._server_id = uuid.UUID(int=uuid.getnode())
self._system_info = {
"system": platform.system(),
Expand All @@ -74,19 +71,30 @@ def __post_init__(self, enable_telemetry: bool, disable_send: bool, api_key: str
}

_LOGGER.info("System Info:")
_LOGGER.info(json.dumps(self._system_info, indent=2))
_LOGGER.info(f"Server id: {self.server_id}")
_LOGGER.info(f"Context: {json.dumps(self._system_info, indent=2)}")

self.client: Optional[Client] = None
if enable_telemetry:
try:
client = Client(write_key=api_key, gzip=True, host=host, send=not disable_send, max_retries=10)
client.identify(user_id=str(self._server_id), traits=self._system_info)

self.client = client
except Exception as err:
_LOGGER.warning(f"Cannot initialize telemetry. Error: {err}. Disabling...")

def track_data(self, action: str, data: Dict[str, Any], include_system_info: bool = True):
if not self.client:
return

event_data = data.copy()
self.client.track(
user_id=str(self._server_id),
event=action,
properties=event_data,
context=self._system_info if include_system_info else {},
)

context = {}
if include_system_info:
context = self._system_info.copy()

self.client.track(user_id=str(self._server_id), event=action, properties=event_data, context=context)


_CLIENT = TelemetryClient()
Expand Down
45 changes: 22 additions & 23 deletions src/argilla_server/utils/_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,51 @@
# 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
import os

import psutil
_LOGGER = logging.getLogger(__name__)


def server_deployment_type() -> str:
"""Returns the type of deployment of the server."""
global _server_deployment_type

if _server_deployment_type is None:
_server_deployment_type = "server"

if is_running_on_docker_container() and _is_quickstart_env():
if is_running_on_huggingface_space():
_server_deployment_type = "huggingface_space"
elif _is_quickstart_env():
_server_deployment_type = "quickstart"

else:
_server_deployment_type = "server"
return _server_deployment_type


def is_running_on_huggingface_space() -> bool:
"""Returns True if the current process is running inside a Huggingface Space, False otherwise."""
from argilla_server.schemas.v1.settings import HuggingfaceSettings

return HuggingfaceSettings().is_running_on_huggingface


def is_running_on_docker_container() -> bool:
"""Returns True if the current process is running inside a Docker container, False otherwise."""
global _in_docker_container

if _in_docker_container is None:
_in_docker_container = _has_docker_env() or _has_docker_cgroup()
if is_running_on_huggingface_space():
_in_docker_container = True
else:
_in_docker_container = _has_docker_env() or _has_docker_cgroup()

return _in_docker_container


def _has_docker_env() -> bool:
try:
return os.path.exists("/.dockerenv")
except:
except Exception as e:
_LOGGER.warning(f"Error while checking if running in Docker: {e}")
return False


Expand All @@ -55,23 +67,11 @@ def _has_docker_cgroup() -> bool:
and os.path.isfile(cgroup_path)
and any("docker" in line for line in open(cgroup_path))
)
except:
except Exception as e:
_LOGGER.warning(f"Error while checking if running in Docker: {e}")
return False


def _is_quickstart_script_running() -> bool:
# TODO: Any modification in the `quickstart.Dockerfile` file should be reflected here

try:
cmdline_key = "cmdline"
for process in psutil.process_iter([cmdline_key]):
if "start_quickstart_argilla.sh" in process.info[cmdline_key]:
return True
except:
pass
return False


def _is_quickstart_env():
# TODO: Any modification in the `quickstart.Dockerfile` file should be reflected here

Expand All @@ -84,7 +84,6 @@ def _is_quickstart_env():
"ADMIN_API_KEY",
"ANNOTATOR_USERNAME",
"ANNOTATOR_PASSWORD",
"LOAD_DATASETS",
]:
if env_var not in os.environ:
return False
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/api/v1/settings/test_get_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,26 @@ async def test_get_settings_for_argilla_settings_running_on_huggingface(self, as

assert response.status_code == 200
assert response.json()["argilla"] == {
"show_huggingface_space_persistant_storage_warning": True,
"show_huggingface_space_persistent_storage_warning": True,
}

async def test_get_settings_for_argilla_settings_running_on_huggingface_with_disabled_storage_warning(
self, async_client: AsyncClient
):
with mock.patch.object(HUGGINGFACE_SETTINGS, "space_id", "space-id"):
with mock.patch.object(argilla_server_settings, "show_huggingface_space_persistant_storage_warning", False):
with mock.patch.object(argilla_server_settings, "show_huggingface_space_persistent_storage_warning", False):
response = await async_client.get(self.url())

assert response.status_code == 200
assert response.json()["argilla"] == {
"show_huggingface_space_persistant_storage_warning": False,
"show_huggingface_space_persistent_storage_warning": False,
}

async def test_get_settings_for_argilla_settings_not_running_on_huggingface(self, async_client: AsyncClient):
response = await async_client.get(self.url())

assert response.status_code == 200
assert "show_huggingface_space_persistant_storage_warning" not in response.json()["argilla"]
assert "show_huggingface_space_persistent_storage_warning" not in response.json()["argilla"]

async def test_get_settings_for_huggingface_settings_running_on_huggingface(self, async_client: AsyncClient):
huggingface_os_environ = {
Expand All @@ -78,7 +78,7 @@ async def test_get_settings_for_huggingface_settings_running_on_huggingface(self
"space_host": "space-host",
"space_repo_name": "space-repo-name",
"space_author_name": "space-author-name",
"space_persistant_storage_enabled": True,
"space_persistent_storage_enabled": True,
}

async def test_get_settings_for_huggingface_settings_not_running_on_huggingface(self, async_client: AsyncClient):
Expand Down

0 comments on commit 63d4875

Please sign in to comment.