Skip to content

Commit

Permalink
feat(ingest): rest-emitter: make test_connection more robust (#3919)
Browse files Browse the repository at this point in the history
Co-authored-by: Shirshanka Das <[email protected]>
  • Loading branch information
anshbansal and shirshanka authored Jan 20, 2022
1 parent b32975d commit 4aa1421
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions datahub-frontend/app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public CompletableFuture<Result> proxy(String path) throws ExecutionException, I
@Nonnull
public Result appConfig() {
final ObjectNode config = Json.newObject();
config.put("application", "datahub-frontend");
config.put("appVersion", _config.getString("app.version"));
config.put("isInternal", _config.getBoolean("linkedin.internal"));
config.put("shouldShowDatasetLineage", _config.getBoolean("linkedin.show.dataset.lineage"));
Expand Down
33 changes: 21 additions & 12 deletions metadata-ingestion/src/datahub/emitter/rest_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from requests.adapters import HTTPAdapter, Retry
from requests.exceptions import HTTPError, RequestException

from datahub import __package_name__
from datahub.configuration.common import OperationalError
from datahub.configuration.common import ConfigurationError, OperationalError
from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.emitter.serialization_helper import pre_json_transform
from datahub.metadata.com.linkedin.pegasus2avro.mxe import (
Expand Down Expand Up @@ -72,10 +71,6 @@ def __init__(
extra_headers: Optional[Dict[str, str]] = None,
ca_certificate_path: Optional[str] = None,
):
if ":9002" in gms_server:
logger.warning(
"the rest emitter should connect to GMS (usually port 8080) instead of frontend"
)
self._gms_server = gms_server
self._token = token

Expand Down Expand Up @@ -127,12 +122,26 @@ def __init__(

def test_connection(self) -> None:
response = self._session.get(f"{self._gms_server}/config")
response.raise_for_status()
config: dict = response.json()
if config.get("noCode") != "true":
raise ValueError(
f"This version of {__package_name__} requires GMS v0.8.0 or higher"
)
if response.status_code == 200:
config: dict = response.json()
if config.get("noCode") == "true":
return
else:
# Looks like we either connected to an old GMS or to some other service. Let's see if we can determine which before raising an error
# A common misconfiguration is connecting to datahub-frontend so we special-case this check
if (
config.get("config", {}).get("application") == "datahub-frontend"
or config.get("config", {}).get("shouldShowDatasetLineage")
is not None
):
message = "You seem to have connected to the frontend instead of the GMS endpoint. The rest emitter should connect to DataHub GMS (usually <datahub-gms-host>:8080) or Frontend GMS API (usually <frontend>:9002/api/gms)"
else:
message = "You have either connected to a pre-v0.8.0 DataHub GMS instance, or to a different server altogether! Please check your configuration and make sure you are talking to the DataHub GMS endpoint."
raise ConfigurationError(message)
else:
auth_message = "Maybe you need to set up authentication? "
message = f"Unable to connect to {self._gms_server}/config with status_code: {response.status_code}. {auth_message if response.status_code == 401 else ''}Please check your configuration and make sure you are talking to the DataHub GMS (usually <datahub-gms-host>:8080) or Frontend GMS API (usually <frontend>:9002/api/gms)."
raise ConfigurationError(message)

def emit(
self,
Expand Down

0 comments on commit 4aa1421

Please sign in to comment.