Skip to content

Commit 4f43e13

Browse files
add tenant information as a query parameter to url in Run in vmui button (#485)
1 parent 7f52d4a commit 4f43e13

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* BUGFIX: fix an issue where the `Internal link` from derived fields config was disabled. See [#479](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/479).
66
* BUGFIX: fix an issue where the `show context` failed if disable labels with transformations. See [#480](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/480).
7+
* BUGFIX: add tenant information as a query parameter to `url` in `Run in vmui` button. See [#480](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/480).
78

89
## v0.22.3
910

pkg/plugin/datasource.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,21 @@ func (d *Datasource) VMUIQuery(rw http.ResponseWriter, req *http.Request) {
618618
return
619619
}
620620

621+
accountID := di.grafanaSettings.MultitenancyHeaders["AccountID"]
622+
if accountID == "" {
623+
accountID = "0"
624+
}
625+
626+
projectID := di.grafanaSettings.MultitenancyHeaders["ProjectID"]
627+
if projectID == "" {
628+
projectID = "0"
629+
}
630+
621631
rw.Header().Add("Content-Type", "application/json")
622632
rw.WriteHeader(http.StatusOK)
623633

624-
if _, err := fmt.Fprintf(rw, `{"vmuiURL": %q}`, vmuiUrl); err != nil {
634+
if _, err := fmt.Fprintf(rw, `{"vmuiURL": %q, "accountID": %q, "projectID": %q}`,
635+
vmuiUrl, accountID, projectID); err != nil {
625636
d.logger.Warn("Error writing response", "error", err)
626637
}
627638
}

src/components/QueryEditor/VmuiLink.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { VictoriaLogsDatasource } from "../../datasource";
2222
import { Query } from "../../types";
2323
import { getDurationFromMilliseconds } from "../../utils/timeUtils";
2424

25-
export const getTimeUrlParams = (panelData?: PanelData) => {
25+
const getTimeUrlParams = (panelData?: PanelData) => {
2626
const timeRange = panelData?.timeRange || getDefaultTimeRange();
2727
const rangeRaw = timeRange.raw;
2828
let relativeTimeId = 'none';
@@ -84,12 +84,23 @@ export const relativeTimeOptionsVMUI = [
8484
...o
8585
}))
8686

87+
type Tenant = {
88+
projectID: string;
89+
accountID: string;
90+
}
91+
92+
const DEFAULT_TENANT: Tenant = {
93+
projectID: '0',
94+
accountID: '0',
95+
};
96+
8797
const VmuiLink: FC<Props> = ({
8898
panelData,
8999
query,
90100
datasource,
91101
}) => {
92102
const [baseVmuiUrl, setBaseVmuiUrl] = useState('');
103+
const [tenant, setTenant] = useState<Tenant>(DEFAULT_TENANT);
93104

94105
useEffect(() => {
95106
if (!datasource) {
@@ -98,8 +109,9 @@ const VmuiLink: FC<Props> = ({
98109

99110
const fetchVmuiUrl = async () => {
100111
try {
101-
const resp = await datasource.getResource<{ vmuiURL: string }>('vmui');
112+
const resp = await datasource.getResource<Tenant & { vmuiURL: string }>('vmui');
102113
setBaseVmuiUrl(resp.vmuiURL.includes('#') ? resp.vmuiURL.split('/#')[0] : resp.vmuiURL);
114+
setTenant({ projectID: resp.projectID, accountID: resp.accountID });
103115
} catch (error) {
104116
console.error('Error fetching VMUI URL:', error);
105117
}
@@ -114,10 +126,11 @@ const VmuiLink: FC<Props> = ({
114126

115127
return `${baseVmuiUrl}/#/?` + new URLSearchParams({
116128
...timeParams,
129+
...tenant,
117130
query: queryExpr,
118131
tab: '0',
119132
}).toString();
120-
}, [baseVmuiUrl, datasource, panelData, query.expr]);
133+
}, [baseVmuiUrl, datasource, panelData, query.expr, tenant]);
121134

122135
return (
123136
<a href={textUtil.sanitizeUrl(href)} target="_blank" rel="noopener noreferrer"

0 commit comments

Comments
 (0)