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

Addressing the following Redis related issues. #172

Merged
merged 8 commits into from
Feb 3, 2023
Merged
47 changes: 24 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,27 @@ You can:

The following are the different environment variables that are looked up that allow configuring the schema registry in different ways.

| Variable Name | Description | Default |
| --------------------- | ----------------------------------------------------------------------------- | ------------------------- |
| DB_HOST | Host name of the MySQL server | gql-schema-registry-db |
| DB_USERNAME | Username to connect to MySQL | root |
| DB_SECRET | Password used to connect to MySQL | root |
| DB_PORT | Port used when connecting to MySQL | 3306 |
| DB_NAME | Name of the MySQL database to connect to | schema-registry |
| DB_EXECUTE_MIGRATIONS | Controls whether DB migrations are executed upon registry startup or not | true |
| REDIS_HOST | Host name of the Redis server | gql-schema-registry-redis |
| REDIS_PORT | Port used when connecting to Redis | 6379 |
| REDIS_SECRET | Password used to connect to Redis | Empty |
| ASSETS_URL | Controls the url that web assets are served from | localhost:6001 |
| NODE_ENV | Specifies the environment. Use _production_ to load js/css from `dist/assets` | Empty |
| ASYNC_SCHEMA_UPDATES | Specifies if async achema updates is enabled | false |
| KAFKA_BROKER_HOST | Host name of the Kafka broker, used if ASYNC_SCHEMA_UPDATES = true | gql-schema-registry-kafka |
| KAFKA_BROKER_PORT | Port used when connecting to Kafka, used if ASYNC_SCHEMA_UPDATES = true | 9092 |
| KAFKA_SCHEMA_TOPIC | Topic with new schema | graphql-schema-updates |
| KAFKA_QUERIES_TOPIC | Topic with new schema | graphql-queries |
| LOG_LEVEL | Minimum level of logs to output | info |
| LOG_TYPE | Output log type, supports pretty or json. | pretty |
| Variable Name | Description | Default |
|------------------------|-------------------------------------------------------------------------------|---------------------------|
| DB_HOST | Host name of the MySQL server | gql-schema-registry-db |
| DB_USERNAME | Username to connect to MySQL | root |
| DB_SECRET | Password used to connect to MySQL | root |
| DB_PORT | Port used when connecting to MySQL | 3306 |
| DB_NAME | Name of the MySQL database to connect to | schema-registry |
| DB_EXECUTE_MIGRATIONS | Controls whether DB migrations are executed upon registry startup or not | true |
| REDIS_HOST | Host name of the Redis server | gql-schema-registry-redis |
| REDIS_PORT | Port used when connecting to Redis | 6379 |
| REDIS_SECRET | Password used to connect to Redis | Empty |
| ASSETS_URL | Controls the url that web assets are served from | localhost:6001 |
| NODE_ENV | Specifies the environment. Use _production_ to load js/css from `dist/assets` | Empty |
| ASYNC_SCHEMA_UPDATES | Specifies if async achema updates is enabled | false |
| KAFKA_BROKER_HOST | Host name of the Kafka broker, used if ASYNC_SCHEMA_UPDATES = true | gql-schema-registry-kafka |
| KAFKA_BROKER_PORT | Port used when connecting to Kafka, used if ASYNC_SCHEMA_UPDATES = true | 9092 |
| KAFKA_SCHEMA_TOPIC | Topic with new schema | graphql-schema-updates |
| KAFKA_QUERIES_TOPIC | Topic with new schema | graphql-queries |
| LOG_LEVEL | Minimum level of logs to output | info |
| LOG_TYPE | Output log type, supports pretty or json. | pretty |
| LOG_STREAMING_ENABLED | Controls whether logs are streamed over Redis to be presented in UI | false |
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to enable it by default to have richest experience by default

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or what do you think.. should we move to most minimal version by default (no redis, no kafka.. maybe even no mysql -> sqlite?)

Copy link
Contributor Author

@ehardy ehardy Nov 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to enable it by default to have richest experience by default

Sounds reasonable to me. As long as there's a configuration to disable it, I don't mind having to disable it within our deployments. I'll invert the logic.


For development we rely on docker network and use hostnames from `docker-compose.yml`.
Node service uses to connect to mysql & redis and change it if you install it with own setup.
Expand Down Expand Up @@ -390,21 +391,21 @@ See main [blog post](https://medium.com/pipedrive-engineering/journey-to-federat

<details>
<summary><h3>🟢 GET /health</h3></summary>

returns "ok" when service is up
</details>

<details>
<summary><h3>🟢 GET /schema/latest</h3></summary>

Simplified version of /schema/compose where latest versions from different services are composed.
Some services prefer this to use this natural schema composition, as its natural and time-based.

</details>

<details>
<summary><h3>🟡 POST /schema/compose</h3></summary>

Advanced version of schema composition, where you need to provide services & their versions.
Used by graphql gateway to fetch schema based on currently running containers.

Expand Down
1 change: 1 addition & 0 deletions docker-compose.base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
image: redis:6-alpine
ports:
- 6004:6379
command: redis-server --requirepass password
environment:
SERVICE_NAME: 'gql-schema-registry-redis'
networks:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
- WITH_WEBPACK=${WITH_WEBPACK-1}
- DB_SCHEMA_REGISTRY=gql-schema-registry-db
- NODE_ENV=production
- REDIS_PASSWORD=password
volumes:
- .:/app/
restart: always
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"test:unit:coverage": "jest --config test/unit/jest.coverage.cjs --color --detectOpenHandles --forceExit",
"test:unit:frontend:coverage": "jest --config test/unit-frontend/jest.config.ts --color --detectOpenHandles --forceExit",
"test:watch": "jest --config jest.config.ts --watch",
"test:integration": "DB_HOST=localhost DB_PORT=6000 REDIS_HOST=localhost REDIS_PORT=6004 PORT=6001 jest --config test/integration/jest.config.cjs --color --detectOpenHandles --runInBand --forceExit",
"test:integration:coverage": "DB_HOST=localhost DB_PORT=6000 REDIS_HOST=localhost REDIS_PORT=6004 PORT=6001 jest --config test/integration/jest.coverage.cjs --color --detectOpenHandles --runInBand --forceExit",
"test:integration": "DB_HOST=localhost DB_PORT=6000 REDIS_HOST=localhost REDIS_PORT=6004 REDIS_SECRET=password PORT=6001 jest --config test/integration/jest.config.cjs --color --detectOpenHandles --runInBand --forceExit",
"test:integration:coverage": "DB_HOST=localhost DB_PORT=6000 REDIS_HOST=localhost REDIS_PORT=6004 REDIS_SECRET=password PORT=6001 jest --config test/integration/jest.coverage.cjs --color --detectOpenHandles --runInBand --forceExit",
"test:functional": "./node_modules/.bin/jest --config test/functional/jest.config.cjs",
"test:performance": "TARGET_URL=localhost:6001 k6 run test/perf/minimum.test.js",
"test:performance:dockerized": "docker-compose -f docker-compose.perf-tests.yml run --rm k6 run /scripts/minimum.test.js",
Expand Down
8 changes: 6 additions & 2 deletions src/graphql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ export default {
)
);

// @ts-ignore
return logs?.redis;
if (process.env.LOG_STREAMING_ENABLED === 'true') {
// @ts-ignore
return logs?.redis;
}

return '';
},

search: async (_, { filter }) => {
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as kafka from './kafka';
import config from './config';
import router from './router';
import { logger } from './logger';
import diplomat from './diplomat';
import redis from './redis';

const app = express();

Expand Down Expand Up @@ -100,6 +102,14 @@ export default async function init() {
return server;
}

const redisConfig = diplomat.getServiceInstance(
'gql-schema-registry-redis'
);

if (redisConfig.host) {
redis.initRedis();
}

if (config.asyncSchemaUpdates) {
kafka.init();
}
Expand Down
9 changes: 6 additions & 3 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import RedisTransport from 'winston-redis-stream';

const logTransports = [new transports.Console()];

if (process.env.REDIS_HOST) {
if (process.env.LOG_STREAMING_ENABLED === 'true' && process.env.REDIS_HOST) {
try {
const redis = new RedisTransport({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
redis: {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
password: process.env.REDIS_SECRET,
},
channel: 'logs',
});
logTransports.push(redis);
Expand Down