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

Remove channel concept (python side) #2454

Merged
merged 6 commits into from
Sep 13, 2024
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
6 changes: 2 additions & 4 deletions nucliadb/src/nucliadb/common/cluster/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,11 @@ async def get_shard(self, shard_id: str) -> noderesources_pb2.Shard:
async def new_shard(
self,
kbid: str,
release_channel: utils_pb2.ReleaseChannel.ValueType,
vector_index_config: VectorIndexConfig,
) -> noderesources_pb2.ShardCreated:
req = NewShardRequest(
kbid=kbid,
release_channel=release_channel,
release_channel=utils_pb2.ReleaseChannel.STABLE,
config=vector_index_config,
# Deprecated fields, only for backwards compatibility with older nodes
similarity=vector_index_config.similarity,
Expand All @@ -111,12 +110,11 @@ async def new_shard(
async def new_shard_with_vectorsets(
self,
kbid: str,
release_channel: utils_pb2.ReleaseChannel.ValueType,
vectorsets_configs: dict[str, VectorIndexConfig],
) -> noderesources_pb2.ShardCreated:
req = NewShardRequest(
kbid=kbid,
release_channel=release_channel,
release_channel=utils_pb2.ReleaseChannel.STABLE,
vectorsets_configs=vectorsets_configs,
)

Expand Down
2 changes: 0 additions & 2 deletions nucliadb/src/nucliadb/common/cluster/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,12 @@ async def create_shard_by_kbid(

shard_created = await node.new_shard(
kbid,
release_channel=kb_shards.release_channel,
vector_index_config=vector_index_config,
)

else:
shard_created = await node.new_shard_with_vectorsets(
kbid,
release_channel=kb_shards.release_channel,
vectorsets_configs=vectorsets,
)

Expand Down
2 changes: 0 additions & 2 deletions nucliadb/src/nucliadb/common/cluster/rollover.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,11 @@ async def create_rollover_shards(
)
shard_created = await node.new_shard(
kbid,
release_channel=kb_shards.release_channel,
vector_index_config=vector_index_config,
)
else:
shard_created = await node.new_shard_with_vectorsets(
kbid,
release_channel=kb_shards.release_channel,
vectorsets_configs=vectorsets,
)
except Exception as e:
Expand Down
26 changes: 2 additions & 24 deletions nucliadb/src/nucliadb/ingest/orm/knowledgebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#
from datetime import datetime
from functools import partial
from typing import Any, AsyncGenerator, Callable, Coroutine, Optional, Sequence, cast
from typing import Any, AsyncGenerator, Callable, Coroutine, Optional, Sequence
from uuid import uuid4

from grpc import StatusCode
Expand Down Expand Up @@ -48,7 +48,7 @@
from nucliadb.ingest.orm.resource import Resource
from nucliadb.ingest.orm.utils import choose_matryoshka_dimension, compute_paragraph_key
from nucliadb.migrator.utils import get_latest_version
from nucliadb_protos import knowledgebox_pb2, nodewriter_pb2, utils_pb2, writer_pb2
from nucliadb_protos import knowledgebox_pb2, nodewriter_pb2, writer_pb2
from nucliadb_protos.knowledgebox_pb2 import (
CreateExternalIndexProviderMetadata,
ExternalIndexProviderType,
Expand All @@ -57,14 +57,10 @@
StoredExternalIndexProviderMetadata,
)
from nucliadb_protos.resources_pb2 import Basic
from nucliadb_protos.utils_pb2 import ReleaseChannel
from nucliadb_utils import const
from nucliadb_utils.settings import running_settings
from nucliadb_utils.storages.storage import Storage
from nucliadb_utils.utilities import (
get_audit,
get_storage,
has_feature,
)

# XXX Eventually all these keys should be moved to datamanagers.kb
Expand Down Expand Up @@ -104,7 +100,6 @@ async def create(
title: str = "",
description: str = "",
semantic_models: Optional[dict[str, SemanticModelMetadata]] = None,
release_channel: Optional[ReleaseChannel.ValueType] = ReleaseChannel.STABLE,
external_index_provider: CreateExternalIndexProviderMetadata = CreateExternalIndexProviderMetadata(),
) -> tuple[str, str]:
"""Creates a new knowledge box and return its id and slug."""
Expand All @@ -116,8 +111,6 @@ async def create(
if semantic_models is None or len(semantic_models) == 0:
raise KnowledgeBoxCreationError("KB must define at least one semantic model")

release_channel = cast(ReleaseChannel.ValueType, release_channel_for_kb(slug, release_channel))

rollback_ops: list[Callable[[], Coroutine[Any, Any, Any]]] = []

try:
Expand All @@ -139,7 +132,6 @@ async def create(
kb_shards.kbid = kbid
# B/c with Shards.actual
kb_shards.actual = -1
kb_shards.release_channel = release_channel

vs_external_indexes = []
for vectorset_id, semantic_model in semantic_models.items(): # type: ignore
Expand Down Expand Up @@ -498,20 +490,6 @@ async def _maybe_delete_external_indexes(
await PineconeIndexManager.delete_indexes(kbid, stored)


def release_channel_for_kb(
slug: str, release_channel: Optional[ReleaseChannel.ValueType]
) -> ReleaseChannel.ValueType:
if running_settings.running_environment == "stage" and has_feature(
const.Features.EXPERIMENTAL_KB, context={"slug": slug}
):
release_channel = utils_pb2.ReleaseChannel.EXPERIMENTAL

if release_channel is None:
return utils_pb2.ReleaseChannel.STABLE

return release_channel


def chunker(seq: Sequence, size: int):
return (seq[pos : pos + size] for pos in range(0, len(seq), size))

Expand Down
2 changes: 0 additions & 2 deletions nucliadb/src/nucliadb/writer/api/v1/knowledgebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ async def _rollback_learning_config(kbid: str):

rollback_learning_config = partial(_rollback_learning_config, kbid)
semantic_models = learning_config.into_semantic_models_metadata()
release_channel = item.release_channel.to_pb() if item.release_channel is not None else None

external_index_provider = knowledgebox_pb2.CreateExternalIndexProviderMetadata(
type=knowledgebox_pb2.ExternalIndexProviderType.UNSET,
Expand All @@ -152,7 +151,6 @@ async def _rollback_learning_config(kbid: str):
title=item.title or "",
description=item.description or "",
semantic_models=semantic_models,
release_channel=release_channel,
external_index_provider=external_index_provider,
)

Expand Down
6 changes: 2 additions & 4 deletions nucliadb/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,8 @@ async def nucliadb_manager(nucliadb: Settings):


@pytest.fixture(scope="function")
async def knowledgebox(nucliadb_manager: AsyncClient, request):
resp = await nucliadb_manager.post(
"/kbs", json={"slug": "knowledgebox", "release_channel": request.param}
)
async def knowledgebox(nucliadb_manager: AsyncClient):
resp = await nucliadb_manager.post("/kbs", json={"slug": "knowledgebox"})
assert resp.status_code == 201
uuid = resp.json().get("uuid")

Expand Down
32 changes: 1 addition & 31 deletions nucliadb/tests/ingest/integration/orm/test_orm_knowledgebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import uuid
from unittest.mock import AsyncMock, patch
from unittest.mock import AsyncMock

import pytest

Expand Down Expand Up @@ -143,36 +143,6 @@ async def test_create_knowledgebox_without_vectorsets_is_not_allowed(
await KnowledgeBox.create(maindb_driver, kbid="kbid", slug="slug", semantic_models={})


@pytest.mark.parametrize(
"release_channel",
[
utils_pb2.ReleaseChannel.STABLE,
utils_pb2.ReleaseChannel.EXPERIMENTAL,
],
)
@pytest.mark.asyncio
async def test_create_knowledgebox_with_release_channel(
storage: Storage,
maindb_driver: Driver,
shard_manager: cluster_manager.KBShardManager,
release_channel: utils_pb2.ReleaseChannel.ValueType,
):
with patch("nucliadb.ingest.orm.knowledgebox.release_channel_for_kb") as mock:
mock.return_value = release_channel

kbid, _ = await KnowledgeBox.create(
maindb_driver,
kbid=KnowledgeBox.new_unique_kbid(),
slug="mykbslug",
semantic_models={"my-semantic-model": SemanticModelMetadata()},
)

async with maindb_driver.transaction(read_only=True) as txn:
shards = await datamanagers.cluster.get_kb_shards(txn, kbid=kbid)
assert shards is not None
assert shards.release_channel == release_channel


@pytest.mark.asyncio
async def test_create_knowledgebox_with_same_kbid(
storage: Storage,
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion nucliadb/tests/ingest/unit/service/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ async def test_NewKnowledgeBoxV2(self, writer: WriterServicer, hosted_nucliadb,
)
for vs in request.vectorsets
}
assert "release_channel" not in knowledgebox_class.create.call_args.kwargs

async def test_NewKnowledgeBoxV2_with_matryoshka_dimensions(
self, writer: WriterServicer, hosted_nucliadb, knowledgebox_class
Expand Down
2 changes: 0 additions & 2 deletions nucliadb/tests/nucliadb/benchmarks/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
warmup=False,
)
@pytest.mark.asyncio
@pytest.mark.parametrize("knowledgebox", ["STABLE", "EXPERIMENTAL"], indirect=True)
async def test_search_returns_labels(
nucliadb_reader: AsyncClient,
nucliadb_writer: AsyncClient,
Expand Down Expand Up @@ -70,7 +69,6 @@ async def test_search_returns_labels(
warmup=False,
)
@pytest.mark.asyncio
@pytest.mark.parametrize("knowledgebox", ["STABLE", "EXPERIMENTAL"], indirect=True)
async def test_search_relations(
nucliadb_reader: AsyncClient,
nucliadb_writer: AsyncClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ async def app_context(natsd, storage, nucliadb):
await ctx.finalize()


@pytest.mark.parametrize("knowledgebox", ("EXPERIMENTAL", "STABLE"), indirect=True)
async def test_rebalance_kb_shards(
app_context,
knowledgebox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ async def app_context(natsd, storage, nucliadb):
await ctx.finalize()


@pytest.mark.parametrize("knowledgebox", ("EXPERIMENTAL", "STABLE"), indirect=True)
async def test_rollover_kb_index(
app_context: ApplicationContext,
knowledgebox,
Expand Down Expand Up @@ -113,7 +112,6 @@ async def _test_rollover_kb_index(
assert len(body["resources"]) == count


@pytest.mark.parametrize("knowledgebox", ("EXPERIMENTAL", "STABLE"), indirect=True)
async def test_rollover_kb_index_does_a_clean_cutover(
app_context,
knowledgebox,
Expand All @@ -131,7 +129,6 @@ async def get_kb_shards(kbid: str):
assert shards2.extra == {}


@pytest.mark.parametrize("knowledgebox", ("EXPERIMENTAL", "STABLE"), indirect=True)
async def test_rollover_kb_index_handles_changes_in_between(
app_context,
knowledgebox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ async def execution_context(natsd, storage, nucliadb):
await context.finalize()


@pytest.mark.parametrize("knowledgebox", ("EXPERIMENTAL", "STABLE"), indirect=True)
async def test_migrate_kb(execution_context: ExecutionContext, knowledgebox):
# this will test run all available migrations
await execution_context.data_manager.update_kb_info(kbid=knowledgebox, current_version=-1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@


@pytest.mark.asyncio
@pytest.mark.parametrize("knowledgebox", ("EXPERIMENTAL", "STABLE"), indirect=True)
async def test_autofilters_are_returned(
nucliadb_reader: AsyncClient,
nucliadb_writer: AsyncClient,
Expand Down
6 changes: 0 additions & 6 deletions nucliadb/tests/nucliadb/integration/search/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
from nucliadb_protos.writer_pb2_grpc import WriterStub
from tests.utils import broker_resource, inject_message

RELEASE_CHANNELS = (
"STABLE",
"EXPERIMENTAL",
)


class ClassificationLabels:
RESOURCE_ANNOTATED = "user-resource/label"
Expand Down Expand Up @@ -283,7 +278,6 @@ async def kbid(


@pytest.mark.asyncio
@pytest.mark.parametrize("knowledgebox", RELEASE_CHANNELS, indirect=True)
@pytest.mark.parametrize(
"filters",
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


@pytest.mark.asyncio
@pytest.mark.parametrize("knowledgebox", ["STABLE", "EXPERIMENTAL"], indirect=True)
async def test_filtering_expression(nucliadb_reader, nucliadb_writer, knowledgebox):
kbid = knowledgebox

Expand Down
Loading
Loading