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

Add OpenSearch implementation #107

Draft
wants to merge 96 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
a382a58
Create initial GitHub Actions workflow
ElliottKasoar Jul 7, 2023
7e4662c
Add OpenSearch dependency
ElliottKasoar Jun 29, 2023
7d35230
Create initial OpenSearch interface
ElliottKasoar Jul 31, 2023
86cf6fa
Add OpenSearch insertion and deletion functions
ElliottKasoar Jul 31, 2023
0f59b23
Add OpenSearch property functions
ElliottKasoar Jul 31, 2023
21bbae2
Add openmock dependency
ElliottKasoar Jul 31, 2023
375b1fe
Add OpenSearch example notebooks
ElliottKasoar Jul 31, 2023
1ffd18d
Add functions required for OpenSearch CLI
ElliottKasoar Aug 2, 2023
4b6103c
Add function to add properties
ElliottKasoar Aug 3, 2023
d52a2bf
Add function to rename properties
ElliottKasoar Aug 3, 2023
e10bee1
Add function to delete properties
ElliottKasoar Aug 3, 2023
4a47df3
Add luqum query parsing for OpenSearch
ElliottKasoar Aug 8, 2023
3426d54
Fix unit tests for OpenSearch
ElliottKasoar Aug 9, 2023
131e41f
Refactor default OpenSearch query
ElliottKasoar Aug 15, 2023
13fcde8
Add function to return data as dictionary
ElliottKasoar Aug 15, 2023
1d082d0
Update OpenSearch useage tutorial
ElliottKasoar Aug 15, 2023
b94ca47
Add function to delete documents by ID
ElliottKasoar Aug 16, 2023
fae3062
Add function to update documents by ID
ElliottKasoar Aug 16, 2023
e2e8f92
Update extra info parsing for Lucene-like inputs
ElliottKasoar Aug 17, 2023
65fcfeb
Add docstrings and type hints
ElliottKasoar Aug 18, 2023
4c42cd9
Tidy code
ElliottKasoar Aug 21, 2023
bc09c6d
Fix formatting for non-string value error
ElliottKasoar Aug 24, 2023
8b1294e
Add class to read csv data
ElliottKasoar Aug 24, 2023
bf0938d
Enable spacegroups to be stored from Atoms
ElliottKasoar Aug 24, 2023
82ed451
Move structure files to list and make units optional
ElliottKasoar Aug 24, 2023
3f509f0
Update README for OpenSearch
ElliottKasoar Aug 24, 2023
6b74e34
Update assertions for database tests
ElliottKasoar Aug 25, 2023
5899529
Add tests for csv reader
ElliottKasoar Aug 25, 2023
f50be40
Add flake8 and black
ElliottKasoar Aug 25, 2023
61727d1
Apply black formatting
ElliottKasoar Aug 25, 2023
014ef31
Conform to flake8 style
ElliottKasoar Aug 25, 2023
fa6faef
Add notebook for extra information examples
ElliottKasoar Aug 30, 2023
7177392
Enable kwargs for OpenSearch client settings
ElliottKasoar Aug 31, 2023
bbf2c07
Fix property function if property not present
ElliottKasoar Aug 31, 2023
92c5818
Run OpenSearch unit tests with GitHub Actions
ElliottKasoar Aug 25, 2023
5a54d1a
Add refresh function for OpenSearch
ElliottKasoar Sep 1, 2023
b1b81d9
Update unit tests
ElliottKasoar Sep 1, 2023
684aa18
Fix delete property function
ElliottKasoar Sep 1, 2023
d8bef29
Add tolerance for failed connections in testing
ElliottKasoar Sep 1, 2023
6e45d18
Update README
ElliottKasoar Sep 1, 2023
c9006a5
Update OpenSearch notebook
ElliottKasoar Sep 1, 2023
99bfd0f
Apply black formatting
ElliottKasoar Sep 4, 2023
e6476ad
Improve property file reader
ElliottKasoar Sep 6, 2023
e2e9664
Add benchmarking examples
ElliottKasoar Sep 6, 2023
97e3898
Enable uploading list of extra info
ElliottKasoar Sep 7, 2023
4cf65ee
Extend benchmarking
ElliottKasoar Sep 7, 2023
da36f9a
Fix OpenSearch CLI queries
ElliottKasoar Jan 12, 2024
cd0333d
Tidy unit tests
ElliottKasoar Jan 22, 2024
40d5ba3
Add option to disabled SSL
ElliottKasoar Jan 22, 2024
93d86f5
Add initial CLI integration tests
ElliottKasoar Jan 22, 2024
622297f
Catch process errors in CLI tests
ElliottKasoar Jan 22, 2024
4d1baea
Add chunk and timeout kwargs for bulk push
ElliottKasoar Jan 24, 2024
34dd0b8
Refactor backend code
ElliottKasoar Jan 24, 2024
9edd356
Update minimum openserch for security
ElliottKasoar Mar 11, 2024
bc2c25d
Update admin default password in CI
ElliottKasoar Mar 11, 2024
67b9a67
Add query test
ElliottKasoar Mar 12, 2024
a0f1fc3
Add OpenSearch refresh CLI command
ElliottKasoar Mar 13, 2024
1fd03f3
Replace luqum with native query_string
ElliottKasoar Mar 12, 2024
dcba2d2
Speed up property function
ElliottKasoar Apr 23, 2024
05dae68
Apply black formatter
ElliottKasoar Apr 29, 2024
5c7edf0
Add timeout to count
ElliottKasoar Apr 29, 2024
085a581
Add comment for property function
ElliottKasoar Apr 29, 2024
a018e04
Fix deleting keys via CLI
ElliottKasoar Apr 29, 2024
623a5b8
Fix adding keys via CLI
ElliottKasoar Apr 29, 2024
a56761b
Fix renaming properties
ElliottKasoar Apr 29, 2024
0dc63fd
Add notebook with example queries
ElliottKasoar Apr 29, 2024
881137b
Allow multiple properties to be returned
ElliottKasoar Apr 30, 2024
f0314d3
Fix CLI code formatting
ElliottKasoar Apr 30, 2024
ef08360
Apply suggestions from code review
ElliottKasoar Jun 11, 2024
0f47586
Tidy for flake8
ElliottKasoar Jun 11, 2024
8702649
Tidy README formatting
ElliottKasoar Jun 11, 2024
562d1d4
Tidy optional type hints
ElliottKasoar Jun 11, 2024
7781612
Add return type hint
ElliottKasoar Jun 11, 2024
932b4e2
Apply suggestions from code review
ElliottKasoar Jun 11, 2024
7a6affe
Update abcd/backends/atoms_opensearch.py
ElliottKasoar Jun 11, 2024
5abd153
Fix type Optional Union type hints
ElliottKasoar Jun 11, 2024
5356d39
Fix connection type
ElliottKasoar Jun 11, 2024
9b05307
Apply suggestions from code review
ElliottKasoar Jun 11, 2024
c546d6d
Fix renaming keys
ElliottKasoar Jun 11, 2024
3dddc38
Tidy setting db
ElliottKasoar Jun 11, 2024
c77316c
Tidy code
ElliottKasoar Jun 11, 2024
3164fbc
Tidy logs
ElliottKasoar Jun 11, 2024
70449ee
Tidy code
ElliottKasoar Jun 11, 2024
2a1ef18
Fix extra info
ElliottKasoar Jun 12, 2024
3276277
Tidy code
ElliottKasoar Jun 12, 2024
8da3c11
Update mongomock tests for pytest
ElliottKasoar Jun 12, 2024
02afdc9
Update mock opensearch tests for pytest
ElliottKasoar Jun 12, 2024
cd95560
Update CLI tests for pytest
ElliottKasoar Jun 12, 2024
cf70beb
Update property tests for pytest
ElliottKasoar Jun 12, 2024
b95b0b8
Update opensearch tests for pytest
ElliottKasoar Jun 12, 2024
84637db
Fix opensearch mock tests
ElliottKasoar Jun 12, 2024
be2d64b
Fix opensearch test
ElliottKasoar Jun 12, 2024
db3c36a
Tidy code
ElliottKasoar Jun 12, 2024
74d24c7
Fix opensearch test
ElliottKasoar Jun 12, 2024
3ba579d
Fix mock opensearch tests
ElliottKasoar Jun 12, 2024
39086be
Fix histogram query
ElliottKasoar Jun 13, 2024
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
7 changes: 7 additions & 0 deletions .ci/opensearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM docker:stable

RUN apk add --update bash

COPY run-opensearch.sh /run-opensearch.sh

ENTRYPOINT ["/run-opensearch.sh"]
33 changes: 33 additions & 0 deletions .ci/opensearch/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'Run OpenSearch'
description: 'This action spins up an Opensearch instance that can be accessed and used in your subsequent steps.'

inputs:
opensearch-version:
description: 'The version of the OpenSearch you want to run'
required: true
security-enabled:
description: 'Enable or disable HTTPS, enabled by default'
default: 'false'
required: false
nodes:
description: 'Number of nodes in the cluster'
required: false
default: 1
port:
description: 'Port where you want to run OpenSearch'
required: false
default: 9200
opensearch-initial-admin-password:
description: 'The password for the user admin in your cluster'
required: false
default: 'myStrongPassword123!'

runs:
using: 'docker'
image: 'Dockerfile'
env:
OPENSEARCH_VERSION: ${{ inputs.opensearch-version }}
NODES: ${{ inputs.nodes }}
PORT: ${{ inputs.port }}
SECURITY_ENABLED: ${{ inputs.security-enabled }}
OPENSEARCH_INITIAL_ADMIN_PASSWORD: ${{ inputs.opensearch-initial-admin-password }}
9 changes: 9 additions & 0 deletions .ci/opensearch/functions/imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
#
# Sets up all the common variables and imports relevant functions
#
# Version 1.0.1
# - Initial version after refactor
# From https://github.com/opensearch-project/opensearch-py/blob/main/.ci/functions/imports.sh

source ./.ci/opensearch/functions/wait-for-container.sh
42 changes: 42 additions & 0 deletions .ci/opensearch/functions/wait-for-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# Exposes a routine scripts can call to wait for a container if that container set up a health command
#
# Please source .ci/functions/imports.sh as a whole not just this file
#
# Version 1.0.1
# - Initial version after refactor
# - Make sure wait_for_contiainer is silent
# From https://github.com/opensearch-project/opensearch-py/blob/main/.ci/functions/wait-for-container.sh

function container_running {
if [[ "$(docker ps -q -f name=$1)" ]]; then
return 0;
else return 1;
fi
}

function wait_for_container {
set +x
until ! container_running "$1" || (container_running "$1" && [[ "$(docker inspect -f "{{.State.Health.Status}}" ${1})" != "starting" ]]); do
echo ""
docker inspect -f "{{range .State.Health.Log}}{{.Output}}{{end}}" ${1}
echo -e "\033[34;1mINFO:\033[0m waiting for node $1 to be up\033[0m"
sleep 4;
done;

# Always show logs if the container is running, this is very useful both on CI as well as while developing
if container_running $1; then
docker logs $1
fi

if ! container_running $1 || [[ "$(docker inspect -f "{{.State.Health.Status}}" ${1})" != "healthy" ]]; then
echo -e "\033[31;1mERROR:\033[0m Failed to start $1 in detached mode beyond health checks\033[0m"
echo -e "\033[31;1mERROR:\033[0m dumped the docker log before shutting the node down\033[0m"
return 1
else
echo
echo -e "\033[32;1mSUCCESS:\033[0m Detached and healthy: ${1}\033[0m"
return 0
fi
}
57 changes: 57 additions & 0 deletions .ci/opensearch/run-opensearch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
source ./.ci/opensearch/functions/imports.sh
set -euxo pipefail

if [[ -z $OPENSEARCH_VERSION ]]; then
echo -e "\033[31;1mERROR:\033[0m Required environment variable [OPENSEARCH_VERSION] not set\033[0m"
exit 1
fi

OPENSEARCH_REQUIRED_VERSION="latest"
# Starting in 2.12.0, security demo configuration script requires an initial admin password
if [ "$OPENSEARCH_VERSION" != "$OPENSEARCH_REQUIRED_VERSION" ]; then
OPENSEARCH_INITIAL_ADMIN_PASSWORD="admin"
fi

for (( node=1; node<=${NODES-1}; node++ ))
do
port=$((PORT + $node - 1))

if [[ "$SECURITY_ENABLED" == "true" ]]; then
healthcmd="curl -vvv -s --insecure -u admin:$OPENSEARCH_INITIAL_ADMIN_PASSWORD --fail https://localhost:$port/_cluster/health || exit 1"
security=($(cat <<-END

END
))
elif [[ "$SECURITY_ENABLED" == "false" ]]; then
healthcmd="curl -vvv -s --fail http://localhost:$port/_cluster/health || exit 1"
security=($(cat <<-END
--env plugins.security.disabled=true
END
))
fi

docker run \
--rm \
--detach \
--name="os${node}" \
--env "cluster.name=docker-opensearch" \
--env "http.port=${port}" \
--env discovery.type=single-node \
--env bootstrap.memory_lock=true \
--env "OPENSEARCH_JAVA_OPTS=-Xms4g -Xmx4g" \
--env OPENSEARCH_INITIAL_ADMIN_PASSWORD=$OPENSEARCH_INITIAL_ADMIN_PASSWORD \
"${security[@]}" \
--publish "${port}:${port}" \
--ulimit nofile=65536:65536 \
--ulimit memlock=-1:-1 \
--health-cmd="$(echo $healthcmd)" \
--health-interval=2s \
--health-retries=20 \
--health-timeout=2s \
opensearchproject/opensearch:${OPENSEARCH_VERSION}

if wait_for_container "os$node"; then
echo -e "\033[32;1mSUCCESS:\033[0m OpenSearch up and running\033[0m"
fi
done
7 changes: 7 additions & 0 deletions .ci/opensearch/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

script_path=$(dirname $(realpath -s $0))
source $script_path/functions/imports.sh
set -euxo pipefail

echo $script_path/functions/imports.sh
16 changes: 16 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[flake8]
select = B,BLK,C,E,F,I,S,W
max-complexity = 30
max-line-length = 88
ignore = E203,W503 # ignore conflicts with black
application-import-names = abcd,tests
import-order-style = google
exclude =
abcd/backends/atoms_pymongo.py,
abcd/frontends,
abcd/model.py,
abcd/parsers/queries_new.py,
abcd/parsers/queries.py,
abcd/parsers/extras.py,
abcd/server,
tests/__init__.py
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
opensearch: ['1.0.1', '2.0.1', 'latest']
security-enabled: ["true", "false"]

steps:
- uses: actions/checkout@v4

- name: Configure sysctl limits
run: |
sudo swapoff -a
sudo sysctl -w vm.swappiness=1
sudo sysctl -w fs.file-max=262144
sudo sysctl -w vm.max_map_count=262144

- name: Start OpenSearch
uses: ./.ci/opensearch
with:
port: 9250
opensearch-version: ${{ matrix.opensearch }}
security-enabled: ${{ matrix.security-enabled }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -29,6 +46,10 @@ jobs:
- name: Run unit tests
run: |
poetry run pytest --cov=abcd --cov-report xml --cov-report term:skip-covered
env:
port: 9250
security_enabled: ${{ matrix.security-enabled }}
opensearch-version: ${{ matrix.opensearch }}

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
Expand Down
Loading