Skip to content

Commit 93e36b5

Browse files
authored
fix: connection creation revamp (#947)
Fixes HDX-1926
1 parent a06c8cd commit 93e36b5

File tree

7 files changed

+52
-24
lines changed

7 files changed

+52
-24
lines changed

.changeset/young-plants-whisper.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
"@hyperdx/api": patch
4+
"@hyperdx/app": patch
5+
---
6+
7+
fix: remove id from post for connection creation endpoint

docker/hyperdx/entry.local.base.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ npx concurrently \
6363
"--names=API,APP,ALERT-TASK" \
6464
"PORT=${HYPERDX_API_PORT:-8000} HYPERDX_APP_PORT=${HYPERDX_APP_PORT:-8080} node -r ./packages/api/tracing ./packages/api/index" \
6565
"cd ./packages/app/packages/app && HOSTNAME='0.0.0.0' HYPERDX_API_PORT=${HYPERDX_API_PORT:-8000} PORT=${HYPERDX_APP_PORT:-8080} node server.js" \
66-
"node -r ./packages/api/tracing ./packages/api/tasks/index check-alerts"
66+
"node -r ./packages/api/tracing ./packages/api/tasks/index check-alerts" \
6767
> /var/log/app.log 2>&1 &
6868

6969
echo ""

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
"scripts": {
3131
"setup": "yarn install && husky install",
3232
"app:dev": "npx concurrently -k -n 'API,APP,ALERTS-TASK,COMMON-UTILS' -c 'green.bold,blue.bold,yellow.bold,magenta' 'nx run @hyperdx/api:dev' 'nx run @hyperdx/app:dev' 'nx run @hyperdx/api:dev-task check-alerts' 'nx run @hyperdx/common-utils:dev'",
33+
"app:dev:local": "npx concurrently -k -n 'APP,COMMON-UTILS' -c 'blue.bold,magenta' 'nx run @hyperdx/app:dev:local' 'nx run @hyperdx/common-utils:dev'",
3334
"app:lint": "nx run @hyperdx/app:ci:lint",
3435
"dev": "docker compose -f docker-compose.dev.yml up -d && yarn app:dev && docker compose -f docker-compose.dev.yml down",
36+
"dev:local": "IS_LOCAL_APP_MODE='DANGEROUSLY_is_local_app_mode💀' yarn dev",
3537
"dev:down": "docker compose -f docker-compose.dev.yml down",
3638
"dev:compose": "docker compose -f docker-compose.dev.yml",
3739
"lint": "npx nx run-many -t ci:lint",

packages/api/src/routers/api/connections.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ router.get('/', async (req, res, next) => {
2626
router.post(
2727
'/',
2828
validateRequest({
29-
body: ConnectionSchema,
29+
body: ConnectionSchema.omit({ id: true }),
3030
}),
3131
async (req, res, next) => {
3232
try {
3333
const { teamId } = getNonNullUserWithTeam(req);
3434

35-
await createConnection(teamId.toString(), {
35+
const connection = await createConnection(teamId.toString(), {
3636
...req.body,
3737
password: req.body.password ?? '',
3838
team: teamId,
3939
});
4040

41-
res.status(200).send();
41+
res.status(200).send({ id: connection._id.toString() });
4242
} catch (e) {
4343
next(e);
4444
}

packages/app/src/components/ConnectionForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ export function ConnectionForm({
146146
};
147147

148148
if (isNew) {
149+
const { id, ...connection } = normalizedData;
149150
createConnection.mutate(
150-
{ connection: normalizedData },
151+
{ connection },
151152
{
152153
onSuccess: () => {
153154
notifications.show({

packages/app/src/components/OnboardingModal.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,31 @@ export default function OnboardingModal({
6363
}
6464
}
6565
}
66-
await createConnectionMutation.mutateAsync({
67-
connection: {
68-
id: 'local',
69-
name: 'Demo',
70-
host: 'https://sql-clickhouse.clickhouse.com',
71-
username: 'otel_demo',
72-
password: '',
66+
let createdConnectionId = '';
67+
await createConnectionMutation.mutateAsync(
68+
{
69+
connection: {
70+
name: 'Demo',
71+
host: 'https://sql-clickhouse.clickhouse.com',
72+
username: 'otel_demo',
73+
password: '',
74+
},
7375
},
74-
});
76+
{
77+
onSuccess(data) {
78+
createdConnectionId = data.id;
79+
},
80+
onError(error) {
81+
console.error('Failed to create demo connection: ', error);
82+
return;
83+
},
84+
},
85+
);
7586
const logSource = await createSourceMutation.mutateAsync({
7687
source: {
7788
kind: SourceKind.Log,
7889
name: 'Demo Logs',
79-
connection: 'local',
90+
connection: createdConnectionId,
8091
from: {
8192
databaseName: 'otel_v2',
8293
tableName: 'otel_logs',
@@ -98,7 +109,7 @@ export default function OnboardingModal({
98109
source: {
99110
kind: SourceKind.Trace,
100111
name: 'Demo Traces',
101-
connection: 'local',
112+
connection: createdConnectionId,
102113
from: {
103114
databaseName: 'otel_v2',
104115
tableName: 'otel_traces',
@@ -127,7 +138,7 @@ export default function OnboardingModal({
127138
source: {
128139
kind: SourceKind.Metric,
129140
name: 'Demo Metrics',
130-
connection: 'local',
141+
connection: createdConnectionId,
131142
from: {
132143
databaseName: 'otel_v2',
133144
tableName: '',
@@ -150,7 +161,7 @@ export default function OnboardingModal({
150161
source: {
151162
kind: SourceKind.Session,
152163
name: 'Demo Sessions',
153-
connection: 'local',
164+
connection: createdConnectionId,
154165
from: {
155166
databaseName: 'otel_v2',
156167
tableName: 'hyperdx_sessions',

packages/app/src/connection.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ export function useConnections() {
5656
export function useCreateConnection() {
5757
const queryClient = useQueryClient();
5858

59-
return useMutation<void, Error, { connection: Connection }>({
60-
mutationFn: async ({ connection }: { connection: Connection }) => {
59+
return useMutation<
60+
{ id: string },
61+
Error,
62+
{ connection: Omit<Connection, 'id'> }
63+
>({
64+
mutationFn: async ({ connection }) => {
6165
if (IS_LOCAL_MODE) {
6266
const isValid = await testLocalConnection({
6367
host: connection.host,
@@ -71,22 +75,25 @@ export function useCreateConnection() {
7175
);
7276
}
7377

78+
// id key in local connection and return value
79+
const createdConnection = { id: 'local' };
80+
7481
// should be only one connection
7582
setLocalConnections([
7683
{
7784
...connection,
78-
id: 'local',
85+
...createdConnection,
7986
},
8087
]);
81-
return;
88+
return createdConnection;
8289
}
8390

84-
await hdxServer('connections', {
91+
const res = await hdxServer('connections', {
8592
method: 'POST',
8693
json: connection,
87-
});
94+
}).json<{ id: string }>();
8895

89-
return;
96+
return res;
9097
},
9198
onSuccess: () => {
9299
queryClient.invalidateQueries({ queryKey: ['connections'] });

0 commit comments

Comments
 (0)