Skip to content

Commit e59acb6

Browse files
authored
Merge pull request #849 from Altinity/issue-836
Add absent user information
2 parents 95aa985 + b5ac4b6 commit e59acb6

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pkg/eval/eval_query.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ type EvalQuery struct {
5151
Database string `json:"database"`
5252
Table string `json:"table"`
5353
MaxDataPoints int64
54-
FrontendDatasource bool `json:"frontendDatasource"`
54+
FrontendDatasource bool `json:"frontendDatasource"`
55+
MetadataUserLogin string `json:"metadataUserLogin"`
5556
From time.Time
5657
To time.Time
5758
}
@@ -1934,7 +1935,11 @@ func (s *EvalQueryScanner) RemoveComments(query string) (string, error) {
19341935

19351936
func (s *EvalQueryScanner) AddMetadata(query string, q *EvalQuery) string {
19361937
if q.FrontendDatasource {
1937-
return "/* grafana dashboard=$__dashboard, user=$__user */\n" + query
1938+
userLogin := q.MetadataUserLogin
1939+
if userLogin == "" {
1940+
userLogin = "$__user"
1941+
}
1942+
return "/* grafana dashboard=$__dashboard, user=" + userLogin + " */\n" + query
19381943
}
19391944
return "/* grafana alerts rule=" + q.RuleUid + " query=" + q.RefId + " */ " + query
19401945
}

src/datasource/datasource.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
QueryFilterOptions,
1616
TypedVariableModel, VariableSupportType,
1717
} from '@grafana/data';
18-
import { BackendSrv, DataSourceWithBackend, getBackendSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
18+
import { BackendSrv, config, DataSourceWithBackend, getBackendSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
1919

2020
import {CHDataSourceOptions, CHQuery, DatasourceMode, DEFAULT_QUERY} from '../types/types';
2121
import {QueryEditor, QueryEditorVariable} from '../views/QueryEditor/QueryEditor';
@@ -831,6 +831,8 @@ export class CHDataSource
831831
from: options.range.from.toISOString(), // Convert to Unix timestamp
832832
to: options.range.to.toISOString(), // Convert to Unix timestamp
833833
},
834+
// Pass actual user login for metadata (fix for issue #836)
835+
metadataUserLogin: config.bootData?.user?.login || '',
834836
};
835837

836838
// Apply template variable replacements (these don't require backend processing)

0 commit comments

Comments
 (0)