mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge branch 'master' of github.com:grafana/grafana
This commit is contained in:
@@ -25,7 +25,7 @@ export class PostgresMetaQuery {
|
||||
|
||||
findMetricTable() {
|
||||
// query that returns first table found that has a timestamp(tz) column and a float column
|
||||
const query = `
|
||||
let query = `
|
||||
SELECT
|
||||
quote_ident(table_name) as table_name,
|
||||
( SELECT
|
||||
@@ -47,11 +47,9 @@ SELECT
|
||||
ORDER BY ordinal_position LIMIT 1
|
||||
) AS value_column
|
||||
FROM information_schema.tables t
|
||||
WHERE
|
||||
table_schema IN (
|
||||
SELECT CASE WHEN trim(unnest) = '"$user"' THEN user ELSE trim(unnest) END
|
||||
FROM unnest(string_to_array(current_setting('search_path'),','))
|
||||
) AND
|
||||
WHERE `;
|
||||
query += this.buildSchemaConstraint();
|
||||
query += ` AND
|
||||
EXISTS
|
||||
( SELECT 1
|
||||
FROM information_schema.columns c
|
||||
@@ -76,8 +74,14 @@ LIMIT 1
|
||||
buildSchemaConstraint() {
|
||||
const query = `
|
||||
table_schema IN (
|
||||
SELECT CASE WHEN trim(unnest) = \'"$user"\' THEN user ELSE trim(unnest) END
|
||||
FROM unnest(string_to_array(current_setting(\'search_path\'),\',\'))
|
||||
SELECT
|
||||
CASE WHEN trim(s[i]) = '"$user"' THEN user ELSE trim(s[i]) END
|
||||
FROM
|
||||
generate_series(
|
||||
array_lower(string_to_array(current_setting('search_path'),','),1),
|
||||
array_upper(string_to_array(current_setting('search_path'),','),1)
|
||||
) as i,
|
||||
string_to_array(current_setting('search_path'),',') s
|
||||
)`;
|
||||
return query;
|
||||
}
|
||||
@@ -92,11 +96,7 @@ table_schema IN (
|
||||
query += ' AND table_name = ' + this.quoteIdentAsLiteral(parts[1]);
|
||||
return query;
|
||||
} else {
|
||||
query = `
|
||||
table_schema IN (
|
||||
SELECT CASE WHEN trim(unnest) = \'"$user"\' THEN user ELSE trim(unnest) END
|
||||
FROM unnest(string_to_array(current_setting(\'search_path\'),\',\'))
|
||||
)`;
|
||||
query = this.buildSchemaConstraint();
|
||||
query += ' AND table_name = ' + this.quoteIdentAsLiteral(table);
|
||||
|
||||
return query;
|
||||
@@ -149,18 +149,8 @@ table_schema IN (
|
||||
}
|
||||
|
||||
buildDatatypeQuery(column: string) {
|
||||
let query = `
|
||||
SELECT udt_name
|
||||
FROM information_schema.columns
|
||||
WHERE
|
||||
table_schema IN (
|
||||
SELECT schema FROM (
|
||||
SELECT CASE WHEN trim(unnest) = \'"$user"\' THEN user ELSE trim(unnest) END as schema
|
||||
FROM unnest(string_to_array(current_setting(\'search_path\'),\',\'))
|
||||
) s
|
||||
WHERE EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = s.schema)
|
||||
)
|
||||
`;
|
||||
let query = 'SELECT udt_name FROM information_schema.columns WHERE ';
|
||||
query += this.buildSchemaConstraint();
|
||||
query += ' AND table_name = ' + this.quoteIdentAsLiteral(this.target.table);
|
||||
query += ' AND column_name = ' + this.quoteIdentAsLiteral(column);
|
||||
return query;
|
||||
|
||||
@@ -15,7 +15,7 @@ const builtInWords = [
|
||||
.join('|')
|
||||
.split('|');
|
||||
|
||||
const metricNameRegexp = /([A-Za-z]\w*)\b(?![\(\]{=!",])/g;
|
||||
const metricNameRegexp = /([A-Za-z:][\w:]*)\b(?![\(\]{=!",])/g;
|
||||
const selectorRegexp = /{([^{]*)}/g;
|
||||
|
||||
// addLabelToQuery('foo', 'bar', 'baz') => 'foo{bar="baz"}'
|
||||
|
||||
@@ -28,6 +28,7 @@ describe('addLabelToQuery()', () => {
|
||||
expect(addLabelToQuery('foo{instance="my-host.com:9100"}', 'bar', 'baz')).toBe(
|
||||
'foo{bar="baz",instance="my-host.com:9100"}'
|
||||
);
|
||||
expect(addLabelToQuery('foo:metric:rate1m', 'bar', 'baz')).toBe('foo:metric:rate1m{bar="baz"}');
|
||||
expect(addLabelToQuery('foo{list="a,b,c"}', 'bar', 'baz')).toBe('foo{bar="baz",list="a,b,c"}');
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user