-
Notifications
You must be signed in to change notification settings - Fork 316
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
Hackathon - log drain #1373
base: main
Are you sure you want to change the base?
Hackathon - log drain #1373
Changes from all commits
2b58fce
77d334e
4d85cf5
63a972d
154f6eb
3faaec1
f50edbf
530c8eb
c5fcd57
c747686
09a9b67
af79cbc
d6da7b7
3a2a770
2d27c2a
7fab4ad
dd5f505
fd5fb8d
780a05b
5be49e0
0bf9fee
53b2791
97f8f45
793d2f2
9665e5c
3bacfcd
d02bced
fb86891
116c12a
79c1bcd
e18e065
4eb753e
38f1cdd
a049f15
d1f324c
315d27d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,6 @@ apps/**/generated | |
|
||
# bruno | ||
cloud.bru | ||
|
||
|
||
analyze |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ import { useRouter } from "next/router"; | |
import React from "react"; | ||
import { z } from "zod"; | ||
import { trpcClient } from "../../trpc/trpc-client"; | ||
import { AvataxObfuscator } from "../avatax-obfuscator"; | ||
import { AvataxConfig, BaseAvataxConfig } from "../avatax-connection-schema"; | ||
import { AvataxObfuscator } from "../avatax-obfuscator"; | ||
import { AvataxConfigurationForm } from "./avatax-configuration-form"; | ||
import { useAvataxConfigurationStatus } from "./configuration-status"; | ||
|
||
|
@@ -141,6 +141,8 @@ export const EditAvataxConfiguration = () => { | |
); | ||
} | ||
|
||
console.log("config", data.config); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to remove |
||
|
||
return ( | ||
<AvataxConfigurationForm | ||
submit={submit} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Box, Text, Textarea } from "@saleor/macaw-ui"; | ||
import { Input } from "@saleor/react-hook-form-macaw"; | ||
import { Controller, useFormContext, useWatch } from "react-hook-form"; | ||
import { AppToggle } from "../../ui/app-toggle"; | ||
import { AvataxConfig } from "../avatax-connection-schema"; | ||
import { HelperText } from "./form-helper-text"; | ||
|
||
export const LogsSettingsFragment = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should have it in shared packages IMO but I think first we can finish this PR, then plan to enable it in other apps → we will extract form into shared package UI can be shared easily, but we need to make form decoupled from data source |
||
const { control, formState } = useFormContext<AvataxConfig>(); | ||
const isOtelTogleEnabled = useWatch({ | ||
control, | ||
name: "logsSettings.otel.enabled", | ||
}); | ||
const isJSONTogleEnabled = useWatch({ | ||
control, | ||
name: "logsSettings.json.enabled", | ||
}); | ||
|
||
return ( | ||
<> | ||
<Box> | ||
<Text marginBottom={4} as="h3" variant="heading"> | ||
Logs settings | ||
</Text> | ||
<Box display="grid" gap={2}> | ||
<HelperText> | ||
Configure where AvaTax should emit logs. This is useful for debugging and | ||
troubleshooting connection issues. | ||
</HelperText> | ||
<AppToggle | ||
name="logsSettings.otel.enabled" | ||
control={control} | ||
label="OTEL transport" | ||
helperText={<HelperText>Enable sending logs using OpenTelemetry protocol.</HelperText>} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to also:
|
||
/> | ||
<Box display="grid" gap={2}> | ||
<Input | ||
control={control} | ||
name="logsSettings.otel.url" | ||
label="URL to send logs to" | ||
helperText={formState.errors.logsSettings?.otel?.url?.message} | ||
disabled={!isOtelTogleEnabled} | ||
/> | ||
<Controller | ||
name="logsSettings.otel.headers" | ||
control={control} | ||
render={({ field, fieldState: { error } }) => ( | ||
<Textarea | ||
{...field} | ||
error={!!error} | ||
helperText={formState.errors.logsSettings?.otel?.headers?.message} | ||
label="Request headers in JSON format" | ||
disabled={!isOtelTogleEnabled} | ||
/> | ||
)} | ||
/> | ||
</Box> | ||
|
||
<AppToggle | ||
name="logsSettings.json.enabled" | ||
control={control} | ||
label="JSON transport" | ||
helperText={<HelperText>Enable sending logs using json protocol.</HelperText>} | ||
/> | ||
<Box display="grid" gap={2}> | ||
<Input | ||
control={control} | ||
name="logsSettings.json.url" | ||
label="URL to send logs to" | ||
helperText={formState.errors.logsSettings?.json?.url?.message} | ||
disabled={!isJSONTogleEnabled} | ||
/> | ||
<Controller | ||
name="logsSettings.json.headers" | ||
control={control} | ||
render={({ field, fieldState: { error } }) => ( | ||
<Textarea | ||
{...field} | ||
error={!!error} | ||
helperText={formState.errors.logsSettings?.json?.headers?.message} | ||
label="Request headers in JSON format" | ||
disabled={!isJSONTogleEnabled} | ||
/> | ||
)} | ||
/> | ||
</Box> | ||
</Box> | ||
</Box> | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; | |
import { BaseError } from "../../../error"; | ||
import { AppConfig } from "../../../lib/app-config"; | ||
import { AppConfigExtractor, IAppConfigExtractor } from "../../../lib/app-config-extractor"; | ||
import { PublicLog } from "../../public-log-drain/public-events"; | ||
import { PublicLogDrainService } from "../../public-log-drain/public-log-drain.service"; | ||
import { AvataxWebhookServiceFactory } from "../../taxes/avatax-webhook-service-factory"; | ||
import { CalculateTaxesPayload } from "../../webhooks/payloads/calculate-taxes-payload"; | ||
import { CalculateTaxesUseCase } from "./calculate-taxes.use-case"; | ||
|
@@ -113,6 +115,16 @@ const getMockedAppConfig = (): AppConfig => { | |
isAutocommit: false, | ||
isDocumentRecordingEnabled: false, | ||
shippingTaxCode: "123", | ||
logsSettings: { | ||
otel: { | ||
url: "https://otel.example.com", | ||
headers: "Authorization", | ||
}, | ||
json: { | ||
url: "https://http.example.com", | ||
headers: "Authorization", | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
|
@@ -127,6 +139,11 @@ describe("CalculateTaxesUseCase", () => { | |
|
||
instance = new CalculateTaxesUseCase({ | ||
configExtractor: MockConfigExtractor, | ||
publicLogDrain: new PublicLogDrainService([ | ||
{ | ||
async emit(log: PublicLog): Promise<void> {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should add test that checks if log drain emits when use case runs |
||
}, | ||
]), | ||
}); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here we should add json validation, so it doesnt shoot anyone in the foot. it will be hard to notice missing
"
and it will fallback to{}
causing auth errors. so we need custom validation, as simple asjson.parse()
in try/catch