[BREAKINGCHANGE] remove fetch from usage metrics#124
Conversation
81371d9 to
e9d2fcf
Compare
| const [renderDurationMs, setRenderDurationMs] = useState(0); | ||
| const [pendingQueries, setPendingQueries] = useState(new Map()); | ||
| const [renderErrorCount, setRenderErrorCount] = useState(0); | ||
| const ctx: UsageMetrics = { |
There was a problem hiding this comment.
We should probably separate the types of the context and the type that is sent with the submitMetrics.
There was a problem hiding this comment.
Actually the parameter of the submit function is a subset of the main interface.
So, it should be fine no?
So, as you can see the extra stuff is dropped from the param.
type SubmitMetrics = (
param: Omit<UsageMetrics, 'setRenderDurationMs' | 'setRenderErrorCount' | 'setPendingQueries'>
) => Promise<void>;There was a problem hiding this comment.
The name does not describe what the interface holds, one is the UsageMetricsContext, the other one is the actual UsageMetrics that is sent to the backend.
| project, | ||
| dashboard, | ||
| children, | ||
| submitMetrics, |
There was a problem hiding this comment.
I guess is coming after this is merged. But we need to adjust Perses UI to submit the metrics.
There was a problem hiding this comment.
Is the comment suggesting I need to change something here, or it is only an announcment. Because =>
Yes, we must to provide the submitMetrics from the Perses/UI side.
There was a problem hiding this comment.
We should have at least an issue to track this should be added, otherwise usage metrics won't be stored leading to data loss
There was a problem hiding this comment.
We should have at least an issue to track this should be added, otherwise usage metrics won't be stored leading to data loss
Let's lift the optional ? and then make it BREAKINGCHANGE. Inherently it is BREAKINGCHANGE.
WDYT?
e9d2fcf to
e435f82
Compare
| method: HttpMethod; | ||
| contentType: ContentType; | ||
| headers?: Record<string, string>; | ||
| fetch: (...args: Parameters<typeof globalThis.fetch>) => Promise<Response>; |
There was a problem hiding this comment.
This is breaking the plugins that use this interface. I don't think the interface should be changed like this. A better approach would be to create a fetchProvider which plugins or components can use
There was a problem hiding this comment.
So, as you know we are trying to drop the fetch-core dependency. Where do you want to place the fetchProvider? Such a provider will be placed in the shared, meaning, again there will be the same dependency but somewhere else. Unless, we move the entire logic of the fetch into that provider under the plugin-system,
Again, maybe it could have its own small package...
This is becoming a dilemma
It should either move to plugin-system or have its own package.
/* FROM CORE =to=> plugin-system or a dedicated package */
export async function fetch(...args: Parameters<typeof globalThis.fetch>): Promise<Response> {
const response = await globalThis.fetch(...args);
if (response.ok === false) {
const contentType = response.headers.get('content-type');
if (contentType?.includes('application/json')) {
const json = await response.clone().json();
if (json.error) {
throw new UserFriendlyError(json.error, response.status);
}
if (json.message) {
throw new UserFriendlyError(json.message, response.status);
}
}
const text = await response.clone().text();
if (text) {
throw new UserFriendlyError(text, response.status);
}
throw new FetchError(response);
}
return response;
}There was a problem hiding this comment.
it probably has to be in the new api package. But it will provide a default implementation like above, then you can use a hook from the plugins to use it. And the provider can accept a custom globalThis.fetch
There was a problem hiding this comment.
@Nexucis
It seems inevitably there will be a small package!
This will contain the fetch and the following types.
@jgbernalp We also need to find a relevant name for the new package. @Nexucis believes api might be vague.
import { HTTPProxy } from './http-proxy';
export type RequestHeaders = Record<string, string>;
export interface HTTPDatasourceSpec {
directUrl?: string;
proxy?: HTTPProxy;
}6a6c92f to
e3a0326
Compare
Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com> Signed-off-by: Seyed Mahmoud SHAHROKNI <seyedmahmoud.shahrokni@amadeus.com>
e3a0326 to
d3aedc8
Compare
This PR removes the fetch (from core) dependency in
plugin-system\src\runtime\UsageMetricsProvider.tsxThis is an IOC (inversion of control) kind of change which gives the consumer the responsibility of
Submitting Metricsas this should not be the concern of the plugin-system. From the Perses/Perses perspective, this responsibility will reside in UI, probably somewhere around ui\app\src\views\projects\dashboards\HelperDashboardView.tsxThis change also includes a bug fix. Apparently, there is a direct mutation of the context which should be fixed by this PR.
Finally there is a change in test files. Please read the comment about the dependency
Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes
See e2e docs for more details. Common issues include: