diff --git a/discovery-provider/compose/docker-compose.redis.yml b/discovery-provider/compose/docker-compose.redis.yml index 21c39c299e6..877c148518b 100644 --- a/discovery-provider/compose/docker-compose.redis.yml +++ b/discovery-provider/compose/docker-compose.redis.yml @@ -34,6 +34,7 @@ services: volumes: esdata: + networks: audius_dev: external: true diff --git a/discovery-provider/es-indexer/docker-compose.yml b/discovery-provider/es-indexer/docker-compose.yml deleted file mode 100644 index 89e727af1c4..00000000000 --- a/discovery-provider/es-indexer/docker-compose.yml +++ /dev/null @@ -1,55 +0,0 @@ -# https://gist.github.com/jakelandis/f152f7f6ea7f994c7438e35dcff07113 - -version: '3' -services: - elasticsearch: - image: docker.elastic.co/elasticsearch/elasticsearch:8.1.0 - container_name: elasticsearch - environment: - - network.host=0.0.0.0 - - discovery.type=single-node - - cluster.name=docker-cluster - - node.name=cluster1-node1 - - action.auto_create_index=false - - xpack.license.self_generated.type=basic - - xpack.security.enabled=false - - 'ES_JAVA_OPTS=-Xms512m -Xmx512m' - ulimits: - memlock: - soft: -1 - hard: -1 - ports: - - 9200:9200 - volumes: - - esdata:/usr/share/elasticsearch/data - networks: - - esnet - - kibana: - image: docker.elastic.co/kibana/kibana:8.1.0 - container_name: kibana - environment: - ELASTICSEARCH_HOSTS: http://elasticsearch:9200 - SERVER_HOSTS: 0.0.0.0 - ports: - - '5601:5601' - networks: - - esnet - depends_on: - - elasticsearch - - redis: - image: redis:6.2-alpine - container_name: redis - ports: - - '6379:6379' - command: redis-server --save 20 1 --loglevel warning - volumes: - - redisdata:/data - -networks: - esnet: - -volumes: - esdata: - redisdata: diff --git a/discovery-provider/src/queries/get_health.py b/discovery-provider/src/queries/get_health.py index 9435d6b76dd..3eb4fb57d14 100644 --- a/discovery-provider/src/queries/get_health.py +++ b/discovery-provider/src/queries/get_health.py @@ -4,6 +4,7 @@ from datetime import datetime from typing import Dict, Optional, Tuple, TypedDict, cast +from elasticsearch import Elasticsearch from redis import Redis from src.eth_indexing.event_scanner import eth_indexing_last_scanned_block_key from src.models import Block, IPLDBlacklistBlock @@ -20,6 +21,7 @@ from src.queries.get_spl_audio import get_spl_audio_health_info from src.utils import db_session, helpers, redis_connection, web3_provider from src.utils.config import shared_config +from src.utils.elasticdsl import ES_INDEXES, esclient from src.utils.helpers import redis_get_or_restore, redis_set_and_dump from src.utils.prometheus_metric import PrometheusMetric, PrometheusType from src.utils.redis_constants import ( @@ -329,6 +331,12 @@ def get_health(args: GetHealthArgs, use_redis_cache: bool = True) -> Tuple[Dict, health_results["meets_min_requirements"] = True if verbose: + # Elasticsearch health + if esclient: + health_results["elasticsearch"] = get_elasticsearch_health_info( + esclient, latest_indexed_block_num + ) + # DB connections check db_connections_json, db_connections_error = _get_db_conn_state() health_results["db_connections"] = db_connections_json @@ -371,6 +379,25 @@ def get_health(args: GetHealthArgs, use_redis_cache: bool = True) -> Tuple[Dict, return health_results, is_unhealthy +def get_elasticsearch_health_info( + esclient: Elasticsearch, latest_indexed_block_num: int +) -> Dict[str, Dict[str, int]]: + elasticsearch_health = {} + for index_name in ES_INDEXES: + resp = esclient.search( + index=index_name, + aggs={"max_blocknumber": {"max": {"field": "blocknumber"}}}, + size=0, + ) + blocknumber = int(resp["aggregations"]["max_blocknumber"]["value"]) + elasticsearch_health[index_name] = { + "blocknumber": blocknumber, + "db_block_difference": latest_indexed_block_num - blocknumber, + } + + return elasticsearch_health + + def health_check_prometheus_exporter(): health_results, is_unhealthy = get_health({}) diff --git a/discovery-provider/src/utils/elasticdsl.py b/discovery-provider/src/utils/elasticdsl.py index 7bf9a093696..67985dfbfd2 100644 --- a/discovery-provider/src/utils/elasticdsl.py +++ b/discovery-provider/src/utils/elasticdsl.py @@ -8,7 +8,6 @@ if es_url: esclient = Elasticsearch(es_url) - # uses aliases ES_PLAYLISTS = "playlists" ES_REPOSTS = "reposts" @@ -16,6 +15,8 @@ ES_TRACKS = "tracks" ES_USERS = "users" +ES_INDEXES = [ES_PLAYLISTS, ES_REPOSTS, ES_SAVES, ES_TRACKS, ES_USERS] + def listify(things): if isinstance(things, list):