Skip to content

Commit

Permalink
H-3710: Support DNS for HaRPC client and align environment variables (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored Dec 11, 2024
1 parent b231c02 commit e453b1b
Show file tree
Hide file tree
Showing 24 changed files with 217 additions and 144 deletions.
8 changes: 5 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ HASH_TEMPORAL_VISIBILITY_PG_DATABASE=temporal_visibility
HASH_GRAPH_PG_USER=graph
HASH_GRAPH_PG_PASSWORD=graph
HASH_GRAPH_PG_DATABASE=graph
HASH_GRAPH_LOG_LEVEL=trace,h2=info,tokio_util=debug,tower=info,tonic=debug,hyper=info,tokio_postgres=info,rustls=info,tarpc=warn
HASH_GRAPH_LOG_LEVEL=info

HASH_GRAPH_TYPE_FETCHER_HOST=localhost
HASH_GRAPH_TYPE_FETCHER_PORT=4455

HASH_GRAPH_REALTIME_PG_USER=realtime
HASH_GRAPH_REALTIME_PG_PASSWORD=realtime

HASH_GRAPH_API_HOST=127.0.0.1
HASH_GRAPH_API_PORT=4000
HASH_GRAPH_HTTP_HOST=127.0.0.1
HASH_GRAPH_HTTP_PORT=4000
HASH_GRAPH_RPC_HOST=127.0.0.1
HASH_GRAPH_RPC_PORT=4002
HASH_GRAPH_TEST_API_HOST=127.0.0.1
HASH_GRAPH_TEST_API_PORT=4001

Expand Down
3 changes: 3 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ HASH_TEMPORAL_PG_DATABASE=dev_temporal
HASH_TEMPORAL_VISIBILITY_PG_DATABASE=dev_temporal_visibility
HASH_GRAPH_PG_DATABASE=dev_graph

HASH_GRAPH_RPC_ENABLED=true
HASH_RPC_ENABLED=true

# For locally-running minio instance
AWS_REGION=local
AWS_S3_UPLOADS_ENDPOINT=http://localhost:9000
Expand Down
6 changes: 4 additions & 2 deletions apps/hash-ai-worker-ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ The service uses the following environment variables:
- `HASH_TEMPORAL_SERVER_PORT`: The port that the Temporal server is running on (defaults to `7233`).
- `OPENAI_API_KEY`: The OpenAI API key that is made available to workflows and activities.
- `ANTHROPIC_API_KEY`: The Anthropic API key that is made available to workflows and activities.
- `HASH_GRAPH_API_HOST`: The host address that the HASH Graph API is running on, e.g. `graph`, `127.0.0.1`
- `HASH_GRAPH_API_PORT`: The port that the HASH Graph API is running on, e.g. `4000`
- `HASH_GRAPH_HTTP_HOST`: The host address that the HASH Graph service is running on, e.g. `graph`, `127.0.0.1`
- `HASH_GRAPH_HTTP_PORT`: The port that the HASH Graph HTTP service is running on, e.g. `4000`
- `HASH_GRAPH_RPC_HOST`: The host address that the HASH Graph RPC service is running on, e.g. `graph`, `127.0.0.1`
- `HASH_GRAPH_RPC_PORT`: The port that the HASH Graph RPC service is running on, e.g. `4002`
- `INTERNAL_API_HOST`: The host for the internal API, required if the internal API is not running locally for workflows making use of the `getWebSearchResultsActivity` activity
- `INTERNAL_API_KEY`: The API key used to authenticate with the internal API, required for workflows making use of the `getWebSearchResultsActivity` activity
- `HASH_VAULT_HOST`: The host address (including protocol) that the Vault server is running on, e.g. `http://127.0.0.1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { getRequiredEnv } from "@local/hash-backend-utils/environment";
import { logger } from "../../shared/logger.js";

export const graphApiClient = createGraphClient(logger, {
host: getRequiredEnv("HASH_GRAPH_API_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_API_PORT"), 10),
host: getRequiredEnv("HASH_GRAPH_HTTP_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10),
});
4 changes: 2 additions & 2 deletions apps/hash-ai-worker-ts/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ async function run() {
logger.info("Starting AI worker...");

const graphApiClient = createGraphClient(logger, {
host: getRequiredEnv("HASH_GRAPH_API_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_API_PORT"), 10),
host: getRequiredEnv("HASH_GRAPH_HTTP_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10),
});

logger.info("Created Graph client");
Expand Down
4 changes: 2 additions & 2 deletions apps/hash-api/src/ensure-system-graph-is-initialized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const context: ImpureGraphContext<false, true> = {
},
},
graphApi: createGraphClient(logger, {
host: getRequiredEnv("HASH_GRAPH_API_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_API_PORT"), 10),
host: getRequiredEnv("HASH_GRAPH_HTTP_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10),
}),
temporalClient: await createTemporalClient(logger),
};
Expand Down
4 changes: 2 additions & 2 deletions apps/hash-api/src/generate-ontology-type-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ const generateOntologyIds = async () => {
serviceName: "generate-ontology-ids",
});

const graphApiHost = getRequiredEnv("HASH_GRAPH_API_HOST");
const graphApiPort = parseInt(getRequiredEnv("HASH_GRAPH_API_PORT"), 10);
const graphApiHost = getRequiredEnv("HASH_GRAPH_HTTP_HOST");
const graphApiPort = parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10);

const graphApi = createGraphClient(logger, {
host: graphApiHost,
Expand Down
12 changes: 6 additions & 6 deletions apps/hash-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ const main = async () => {
const redisEncryptedTransit =
process.env.HASH_REDIS_ENCRYPTED_TRANSIT === "true";

const graphApiHost = getRequiredEnv("HASH_GRAPH_API_HOST");
const graphApiPort = parseInt(getRequiredEnv("HASH_GRAPH_API_PORT"), 10);
const graphApiHost = getRequiredEnv("HASH_GRAPH_HTTP_HOST");
const graphApiPort = parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10);

await Promise.all([
waitOnResource(`tcp:${redisHost}:${redisPort}`, logger),
Expand Down Expand Up @@ -542,8 +542,8 @@ const main = async () => {

shutdown.addCleanup("ManagedRuntime", () => runtime.dispose());

const rpcHost = process.env.HASH_RPC_HOST ?? "127.0.0.1";
const rpcPort = parseInt(process.env.HASH_RPC_PORT ?? "4002", 10);
const rpcHost = getRequiredEnv("HASH_GRAPH_RPC_HOST");
const rpcPort = parseInt(process.env.HASH_GRAPH_RPC_PORT ?? "4002", 10);

app.get("/rpc/echo", (req, res, next) => {
// eslint-disable-next-line func-names
Expand All @@ -560,10 +560,10 @@ const main = async () => {
}).pipe(
Effect.provide(
RpcClient.connectLayer(
Transport.multiaddr(`/ip4/${rpcHost}/tcp/${rpcPort}`),
Transport.multiaddr(`/dns/${rpcHost}/tcp/${rpcPort}`),
),
),
Logger.withMinimumLogLevel(LogLevel.Trace),
Logger.withMinimumLogLevel(LogLevel.Info),
);

runtime.runCallback(effect, {
Expand Down
4 changes: 2 additions & 2 deletions apps/hash-api/src/seed-data/seed-flow-test-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ const createSystemEntityTypeIfNotExists: ImpureGraphFunction<
*/
const seedFlowTestTypes = async () => {
const graphApi = createGraphClient(logger, {
host: getRequiredEnv("HASH_GRAPH_API_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_API_PORT"), 10),
host: getRequiredEnv("HASH_GRAPH_HTTP_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10),
});

const context = { graphApi, provenance };
Expand Down
10 changes: 5 additions & 5 deletions apps/hash-external-services/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ services:
HASH_GRAPH_ALLOWED_URL_DOMAIN_PATTERN: "${HASH_GRAPH_ALLOWED_URL_DOMAIN_PATTERN}"
HASH_GRAPH_TYPE_FETCHER_HOST: "type-fetcher"
HASH_GRAPH_TYPE_FETCHER_PORT: "${HASH_GRAPH_TYPE_FETCHER_PORT}"
HASH_GRAPH_API_HOST: "0.0.0.0"
HASH_GRAPH_API_PORT: "${HASH_GRAPH_API_PORT}"
HASH_GRAPH_HTTP_HOST: "0.0.0.0"
HASH_GRAPH_HTTP_PORT: "${HASH_GRAPH_HTTP_PORT}"
HASH_GRAPH_LOG_LEVEL: "${HASH_GRAPH_LOG_LEVEL}"
HASH_GRAPH_LOG_CONSOLE_FORMAT: "${HASH_GRAPH_LOG_CONSOLE_FORMAT:-full}"
HASH_GRAPH_LOG_FOLDER: "/logs/graph-service"
Expand All @@ -173,7 +173,7 @@ services:
"server",
"--healthcheck",
"--api-port",
"${HASH_GRAPH_API_PORT}",
"${HASH_GRAPH_HTTP_PORT}",
]
interval: 2s
timeout: 2s
Expand All @@ -197,8 +197,8 @@ services:
API_ORIGIN: "${API_ORIGIN}"
HASH_SEED_USERS: "${HASH_SEED_USERS}"

HASH_GRAPH_API_HOST: "graph"
HASH_GRAPH_API_PORT: "${HASH_GRAPH_API_PORT}"
HASH_GRAPH_HTTP_HOST: "graph"
HASH_GRAPH_HTTP_PORT: "${HASH_GRAPH_HTTP_PORT}"
LOG_LEVEL: "${LOG_LEVEL}"

HASH_REDIS_HOST: "redis"
Expand Down
29 changes: 9 additions & 20 deletions apps/hash-graph/src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,22 @@ use crate::{
};

#[derive(Debug, Clone, Parser)]
pub struct ApiAddress {
pub struct HttpAddress {
/// The host the REST client is listening at.
#[clap(long, default_value = "127.0.0.1", env = "HASH_GRAPH_API_HOST")]
#[clap(long, default_value = "127.0.0.1", env = "HASH_GRAPH_HTTP_HOST")]
pub api_host: String,

/// The port the REST client is listening at.
#[clap(long, default_value_t = 4000, env = "HASH_GRAPH_API_PORT")]
#[clap(long, default_value_t = 4000, env = "HASH_GRAPH_HTTP_PORT")]
pub api_port: u16,
}

impl fmt::Display for ApiAddress {
impl fmt::Display for HttpAddress {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}:{}", self.api_host, self.api_port)
}
}

impl TryFrom<ApiAddress> for SocketAddr {
type Error = Report<AddrParseError>;

fn try_from(address: ApiAddress) -> Result<Self, Report<AddrParseError>> {
address
.to_string()
.parse::<Self>()
.attach_printable(address)
}
}

#[derive(Debug, Clone, Parser)]
pub struct RpcAddress {
/// The host the RPC client is listening at.
Expand Down Expand Up @@ -107,7 +96,7 @@ pub struct ServerArgs {

/// The address the REST server is listening at.
#[clap(flatten)]
pub api_address: ApiAddress,
pub http_address: HttpAddress,

/// Enable the experimental RPC server.
#[clap(long, default_value_t = false, env = "HASH_GRAPH_RPC_ENABLED")]
Expand Down Expand Up @@ -237,7 +226,7 @@ where
pub async fn server(args: ServerArgs) -> Result<(), Report<GraphError>> {
if args.healthcheck {
return wait_healthcheck(
|| healthcheck(args.api_address.clone()),
|| healthcheck(args.http_address.clone()),
args.wait,
args.timeout.map(Duration::from_secs),
)
Expand Down Expand Up @@ -330,9 +319,9 @@ pub async fn server(args: ServerArgs) -> Result<(), Report<GraphError>> {
rest_api_router(dependencies)
};

tracing::info!("Listening on {}", args.api_address);
tracing::info!("Listening on {}", args.http_address);
axum::serve(
TcpListener::bind((args.api_address.api_host, args.api_address.api_port))
TcpListener::bind((args.http_address.api_host, args.http_address.api_port))
.await
.change_context(GraphError)?,
router.into_make_service_with_connect_info::<SocketAddr>(),
Expand All @@ -343,7 +332,7 @@ pub async fn server(args: ServerArgs) -> Result<(), Report<GraphError>> {
Ok(())
}

pub async fn healthcheck(address: ApiAddress) -> Result<(), Report<HealthcheckError>> {
pub async fn healthcheck(address: HttpAddress) -> Result<(), Report<HealthcheckError>> {
let request_url = format!("http://{address}/api-doc/openapi.json");

timeout(
Expand Down
12 changes: 6 additions & 6 deletions apps/hash-graph/src/subcommand/test_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tokio_postgres::NoTls;

use crate::{
error::{GraphError, HealthcheckError},
subcommand::{server::ApiAddress, wait_healthcheck},
subcommand::{server::HttpAddress, wait_healthcheck},
};

#[derive(Debug, Parser)]
Expand All @@ -31,7 +31,7 @@ pub struct TestServerArgs {

/// The address the REST server is listening at.
#[clap(flatten)]
pub api_address: ApiAddress,
pub http_address: HttpAddress,

/// Runs the healthcheck for the test server.
#[clap(long, default_value_t = false)]
Expand Down Expand Up @@ -63,7 +63,7 @@ pub async fn test_server(args: TestServerArgs) -> Result<(), Report<GraphError>>

if args.healthcheck {
return wait_healthcheck(
|| healthcheck(args.api_address.clone()),
|| healthcheck(args.http_address.clone()),
args.wait,
args.timeout.map(Duration::from_secs),
)
Expand Down Expand Up @@ -101,9 +101,9 @@ pub async fn test_server(args: TestServerArgs) -> Result<(), Report<GraphError>>

let router = hash_graph_test_server::routes(pool, zanzibar_client);

tracing::info!("Listening on {}", args.api_address);
tracing::info!("Listening on {}", args.http_address);
axum::serve(
TcpListener::bind((args.api_address.api_host, args.api_address.api_port))
TcpListener::bind((args.http_address.api_host, args.http_address.api_port))
.await
.change_context(GraphError)?,
router.into_make_service_with_connect_info::<SocketAddr>(),
Expand All @@ -114,7 +114,7 @@ pub async fn test_server(args: TestServerArgs) -> Result<(), Report<GraphError>>
Ok(())
}

pub async fn healthcheck(address: ApiAddress) -> Result<(), Report<HealthcheckError>> {
pub async fn healthcheck(address: HttpAddress) -> Result<(), Report<HealthcheckError>> {
let request_url = format!("http://{address}/snapshot");

timeout(
Expand Down
6 changes: 4 additions & 2 deletions apps/hash-integration-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ This app is a Temporal worker that is able to run workflows and activities for d

The service uses the following environment variables:

- `HASH_GRAPH_API_HOST`: The host address (including protocol) that the HASH Graph API is running on, e.g. `http://localhost`
- `HASH_GRAPH_API_PORT`: The port that the HASH Graph API is running on, e.g. `4000`
- `HASH_GRAPH_HTTP_HOST`: The host address that the HASH Graph HTTP service is running on, e.g. `graph`, `127.0.0.1`
- `HASH_GRAPH_HTTP_PORT`: The port that the HASH Graph HTTP service is running on, e.g. `4000`
- `HASH_GRAPH_RPC_HOST`: The host address that the HASH Graph RPC service is running on, e.g. `graph`, `127.0.0.1`
- `HASH_GRAPH_RPC_PORT`: The port that the HASH Graph RPC service is running on, e.g. `4002`
- `HASH_TEMPORAL_SERVER_HOST`: The host address (including protocol) that the Temporal server is running on (defaults to `http://localhost`).
- `HASH_TEMPORAL_SERVER_PORT`: The port that the Temporal server is running on (defaults to `7233`).
- `HASH_VAULT_HOST`: The host address (including protocol) that the Vault server is running on, e.g. `http://127.0.0.1`
Expand Down
4 changes: 2 additions & 2 deletions apps/hash-integration-worker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ async function run() {
// eslint-disable-next-line no-console
console.info("Starting integration worker...");
const graphApiClient = createGraphClient(logger, {
host: getRequiredEnv("HASH_GRAPH_API_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_API_PORT"), 10),
host: getRequiredEnv("HASH_GRAPH_HTTP_HOST"),
port: parseInt(getRequiredEnv("HASH_GRAPH_HTTP_PORT"), 10),
});

const worker = await Worker.create({
Expand Down
Loading

0 comments on commit e453b1b

Please sign in to comment.