github.com/grafana/pyroscope@v1.18.0/public/app/services/tenant.ts (about) 1 import { RequestNotOkError, request } from '@pyroscope/services/base'; 2 3 export async function isMultiTenancyEnabled() { 4 const res = await request('/querier.v1.QuerierService/LabelNames', { 5 // Without this it would automatically add the OrgID 6 // Which doesn't tell us whether multitenancy is enabled or not 7 headers: { 8 'X-Scope-OrgID': '', 9 'content-type': 'application/json', 10 }, 11 method: 'POST', 12 body: JSON.stringify({ 13 matchers: ['{__profile_type__="app"}'], 14 }), 15 }); 16 17 // If everything went okay even without passing an OrgID, we can assume it's a non multitenant instance 18 if (res.isOk) { 19 return false; 20 } 21 22 return isOrgRequiredError(res); 23 } 24 25 function isOrgRequiredError(res: Awaited<ReturnType<typeof request>>) { 26 // TODO: is 'no org id' a stable message? 27 return ( 28 res.isErr && 29 res.error instanceof RequestNotOkError && 30 res.error.code === 401 && 31 res.error.description.includes('no org id') 32 ); 33 }