Skip to content

Commit a330e00

Browse files
authored
feat: Use allow-utf8-labelnames client capability in UI (#4493)
1 parent 0b0e959 commit a330e00

File tree

7 files changed

+1066
-27
lines changed

7 files changed

+1066
-27
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"scripts": {
99
"type-check": "tsc -p tsconfig.json --noEmit",
1010
"build": "NODE_ENV=production webpack --progress --config scripts/webpack/webpack.prod.js",
11+
"dev": "webpack serve --config scripts/webpack/webpack.dev.js",
1112
"backend:dev": "make build run 'PARAMS=--config.file ./cmd/pyroscope/pyroscope.yaml'",
1213
"lint": "eslint . --ext .js,.tsx,.ts --cache",
1314
"lint:fix": "yarn lint --fix",
@@ -79,6 +80,7 @@
7980
"web-streams-polyfill": "^3.2.1",
8081
"webpack": "^5.94.0",
8182
"webpack-cli": "^5.0.1",
83+
"webpack-dev-server": "^5.2.2",
8284
"webpack-merge": "^5.8.0"
8385
},
8486
"dependencies": {

public/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
```bash
66
yarn install
7-
# Make sure you have the backend running.
7+
# Make sure you have the backend running after building with EMBEDASSETS="".
8+
# Note the frontend is accessible via localhost:4041.
89
yarn dev
910
```
1011

public/app/components/TagsBar.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,13 @@ function LabelsSubmenu({
230230

231231
// Identifies whether a label is in a query or not
232232
function isLabelInQuery(query: string, label: string, labelValue: string) {
233-
return query.includes(`${label}="${labelValue}"`);
233+
// Label names can be either quoted or unquoted:
234+
// - Unquoted: service_name="value"
235+
// - Quoted: "service.name"="value"
236+
const unquotedPattern = `${label}="${labelValue}"`;
237+
const quotedPattern = `"${label}"="${labelValue}"`;
238+
239+
return query.includes(unquotedPattern) || query.includes(quotedPattern);
234240
}
235241

236242
export default TagsBar;

public/app/services/base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export async function request(
3232
headers = {
3333
...config?.headers,
3434
...(tenantID && { 'X-Scope-OrgID': tenantID }),
35+
// Specify client capabilities in `Accept` header
36+
Accept: 'application/json;allow-utf8-labelnames=true',
3537
};
3638
}
3739

@@ -53,6 +55,8 @@ export async function downloadWithOrgID(
5355
headers = {
5456
...config?.headers,
5557
...(tenantID && { 'X-Scope-OrgID': tenantID }),
58+
// Specify client capabilities in `Accept` header
59+
Accept: 'application/json;allow-utf8-labelnames=true',
5660
};
5761
}
5862

public/app/util/query.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ export function appendLabelToQuery(
33
label: string,
44
labelValue: string
55
) {
6+
// Check if label is a "legacy" label name (i.e. only
7+
// contains characters in [a-zA-Z0-9_]). If not legacy,
8+
// need to wrap the label name in quotes
9+
const legacyLabelRegex = /^[a-zA-Z0-9_]+$/;
10+
if (!legacyLabelRegex.test(label)) {
11+
label = `"${label}"`;
12+
}
13+
614
const case1Regexp = new RegExp(`${label}=.+?(\\}|,)`);
715
if (query.match(case1Regexp)) {
816
return query.replace(case1Regexp, `${label}="${labelValue}"$1`);

scripts/webpack/webpack.dev.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ module.exports = merge(common, {
1010
devServer: {
1111
port: 4041,
1212
historyApiFallback: true,
13-
proxy: {
14-
'/pyroscope': 'http://localhost:4040',
15-
'/querier.v1.QuerierService': 'http://localhost:4040',
16-
'/assets/grafana/*': {
13+
proxy: [
14+
{
15+
context: ['/pyroscope'],
16+
target: 'http://localhost:4040',
17+
changeOrigin: true,
18+
},
19+
{
20+
context: ['/querier.v1.QuerierService'],
21+
target: 'http://localhost:4040',
22+
changeOrigin: true,
23+
},
24+
{
25+
context: ['/assets/grafana'],
1726
target: 'http://localhost:4041',
1827
pathRewrite: { '^/assets': '' },
1928
logLevel: 'debug',
2029
},
21-
},
30+
],
2231
},
2332
optimization: {
2433
runtimeChunk: 'single',

0 commit comments

Comments
 (0)