Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

feat: make tags work in the ui #620

Merged
merged 5 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions public/app/overrides/services/tags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,61 @@
import { Result } from '@webapp/util/fp';
import { parseResponse, request } from '@webapp/services/base';
import { z } from 'zod';

const seriesLabelsSchema = z.preprocess(
(a: any) => {
if ('labelsSet' in a) {
return a;
}

return { labelsSet: [{ labels: [] }] };
},
z.object({
labelsSet: z.array(
z.object({
labels: z.array(
z.object({
name: z.string(),
value: z.string(),
})
),
})
),
})
);

async function fetchLabelsSeries<T>(
query: string,
transformFn: (t: { name: string; value: string }[]) => T
) {
const profileTypeID = query.replace(/\{.*/g, '');
const response = await request('/querier.v1.QuerierService/Series', {
method: 'POST',
body: JSON.stringify({
matchers: [`{__profile_type__=\"${profileTypeID}\"}`],
}),
headers: {
'content-type': 'application/json',
},
});
const isMetaTag = (tag: string) => tag.startsWith('__') && tag.endsWith('__');

return parseResponse<T>(
response,
seriesLabelsSchema
.transform((res) => {
return res.labelsSet
.flatMap((a) => a.labels)
.filter((a) => !isMetaTag(a.name));
})
.transform(transformFn)
);
}

export async function fetchTags(query: string, from: number, until: number) {
return Result.ok<string[], { message: string }>([]);
return fetchLabelsSeries(query, function (t) {
const labelNames = t.map((a) => a.name);
return Array.from(new Set(labelNames));
});
}

export async function fetchLabelValues(
Expand All @@ -10,7 +64,8 @@ export async function fetchLabelValues(
from: number,
until: number
) {
return Result.err<string[], { message: string }>({
message: 'TODO: implement ',
return fetchLabelsSeries(query, function (t) {
const labelValues = t.filter((l) => label === l.name).map((a) => a.value);
return Array.from(new Set(labelValues));
});
}
1 change: 1 addition & 0 deletions scripts/webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = merge(common, {
port: 4040,
proxy: {
'/pyroscope': 'http://localhost:4100',
'/querier.v1.QuerierService': 'http://localhost:4100',
},
},
optimization: {
Expand Down