Skip to content

Commit

Permalink
move enabled flag to global state
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 committed May 22, 2024
1 parent 298febd commit 4b81b23
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 34 deletions.
3 changes: 0 additions & 3 deletions public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface ObservabilityAppDeps {
pplService: any;
dslService: any;
savedObjects: any;
config: PublicConfig;
timestampUtils: any;
queryManager: QueryManager;
startPage: string;
Expand Down Expand Up @@ -60,7 +59,6 @@ export const App = ({
pplService,
dslService,
savedObjects,
config,
timestampUtils,
queryManager,
startPage,
Expand Down Expand Up @@ -94,7 +92,6 @@ export const App = ({
pplService={pplService}
dslService={dslService}
savedObjects={savedObjects}
config={config}
timestampUtils={timestampUtils}
queryManager={queryManager}
parentBreadcrumb={parentBreadcrumb}
Expand Down
5 changes: 1 addition & 4 deletions public/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AppMountParameters, CoreStart } from '../../../../src/core/public';
import { DataSourceManagementPluginSetup } from '../../../../src/plugins/data_source_management/public';
import { AppPluginStartDependencies } from '../types';
import { App } from './app';
import { PublicConfig } from '../plugin';

export const Observability = (
CoreStartProp: CoreStart,
Expand All @@ -24,8 +23,7 @@ export const Observability = (
startPage: string,
dataSourcePluggables,
dataSourceManagement: DataSourceManagementPluginSetup,
savedObjectsMDSClient: CoreStart['savedObjects'],
config: PublicConfig
savedObjectsMDSClient: CoreStart['savedObjects']
) => {
const { setHeaderActionMenu } = AppMountParametersProp;
const { dataSource } = DepsStart;
Expand All @@ -36,7 +34,6 @@ export const Observability = (
pplService={pplService}
dslService={dslService}
savedObjects={savedObjects}
config={config}
timestampUtils={timestampUtils}
queryManager={queryManager}
startPage={startPage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface TraceViewProps extends TraceAnalyticsCoreDeps {
dataSourceMDSId: DataSourceOption[];
dataSourceManagement: DataSourceManagementPluginSetup;
setActionMenu: (menuMount: MountPoint | undefined) => void;
tenant?: string;
tenant?: string | undefined;
}

export function TraceView(props: TraceViewProps) {
Expand Down
12 changes: 5 additions & 7 deletions public/components/trace_analytics/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
DataSourceSelectableConfig,
} from '../../../../../src/plugins/data_source_management/public';
import { DataSourceOption } from '../../../../../src/plugins/data_source_management/public/components/data_source_menu/types';
import { coreRefs } from '../../framework/core_refs';
import { FilterType } from './components/common/filters/filters';
import { loadTenantInfo } from './components/common/indices';
import { SearchBarProps } from './components/common/search_bar';
import { ServiceView, Services } from './components/services';
import { TraceView, Traces } from './components/traces';
Expand All @@ -29,8 +31,6 @@ import {
handleJaegerIndicesExistRequest,
} from './requests/request_handler';
import { TraceSideBar } from './trace_side_nav';
import { loadTenantInfo } from './components/common/indices';
import { PublicConfig } from '../../plugin';

export interface TraceAnalyticsCoreDeps {
parentBreadcrumb: ChromeBreadcrumb;
Expand All @@ -43,9 +43,7 @@ export interface TraceAnalyticsCoreDeps {
savedObjectsMDSClient: SavedObjectsStart;
}

interface HomeProps extends RouteComponentProps, TraceAnalyticsCoreDeps {
config: PublicConfig;
}
interface HomeProps extends RouteComponentProps, TraceAnalyticsCoreDeps {}

export type TraceAnalyticsMode = 'jaeger' | 'data_prepper';

Expand Down Expand Up @@ -108,7 +106,7 @@ export const Home = (props: HomeProps) => {

useEffect(() => {
if (!tenantLoaded)
loadTenantInfo(props.http, props.config.multitenancy.enabled).then((tenant) => {
loadTenantInfo(props.http, coreRefs.traceMultitenancyEnabled!).then((tenant) => {
setTenantLoaded(true);
setTenantName(tenant);
handleDataPrepperIndicesExistRequest(
Expand All @@ -119,7 +117,7 @@ export const Home = (props: HomeProps) => {
);
handleJaegerIndicesExistRequest(props.http, setJaegerIndicesExist, tenant);
});
}, [props.config.multitenancy.enabled, tenantLoaded, dataSourceMDSId]);
}, [coreRefs.traceMultitenancyEnabled!, tenantLoaded, dataSourceMDSId]);

const modes = [
{ id: 'jaeger', title: 'Jaeger', 'data-test-subj': 'jaeger-mode' },
Expand Down
6 changes: 3 additions & 3 deletions public/components/trace_analytics/requests/request_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { getTenantIndexName } from '../../../../common/utils/tenant_index_name';
import { CoreStart } from '../../../../../../src/core/public';
import {
DATA_PREPPER_INDEX_NAME,
Expand All @@ -12,6 +11,7 @@ import {
TRACE_ANALYTICS_DSL_ROUTE,
TRACE_ANALYTICS_JAEGER_INDICES_ROUTE,
} from '../../../../common/constants/trace_analytics';
import { getTenantIndexName } from '../../../../common/utils/tenant_index_name';
import { TraceAnalyticsMode } from '../home';

export async function handleDslRequest(
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function handleDslRequest(

export async function handleJaegerIndicesExistRequest(
http: CoreStart['http'],
setJaegerIndicesExist,
setJaegerIndicesExist: (val: boolean) => void,
dataSourceMDSId?: string,
tenant?: string
) {
Expand All @@ -91,7 +91,7 @@ export async function handleJaegerIndicesExistRequest(

export async function handleDataPrepperIndicesExistRequest(
http: CoreStart['http'],
setDataPrepperIndicesExist,
setDataPrepperIndicesExist: (val: boolean) => void,
dataSourceMDSId?: string,
tenant?: string
) {
Expand Down
1 change: 1 addition & 0 deletions public/framework/core_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CoreRefs {
public application?: ApplicationStart;
public queryAssistEnabled?: boolean;
public summarizeEnabled?: boolean;
public traceMultitenancyEnabled?: boolean;
public dashboard?: DashboardStart;
public dashboardProviders?: unknown;
public overlays?: OverlayStart;
Expand Down
12 changes: 6 additions & 6 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { i18n } from '@osd/i18n';
import { htmlIdGenerator } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React from 'react';
import {
AppCategory,
AppMountParameters,
Expand Down Expand Up @@ -97,14 +97,14 @@ import {
SetupDependencies,
} from './types';

export interface PublicConfig {
interface PublicConfig {
query_assist: {
enabled: boolean;
};
summarize: {
enabled: boolean;
};
multitenancy: {
traceMultitenancy: {
enabled: boolean;
};
}
Expand Down Expand Up @@ -269,8 +269,7 @@ export class ObservabilityPlugin
startPage,
dataSourcePluggables, // just pass down for now due to time constraint, later may better expose this as context
dataSourceManagement,
coreStart.savedObjects,
this.config
coreStart.savedObjects
);
};

Expand Down Expand Up @@ -403,6 +402,7 @@ export class ObservabilityPlugin
coreRefs.dashboard = startDeps.dashboard;
coreRefs.queryAssistEnabled = this.config.query_assist.enabled;
coreRefs.summarizeEnabled = this.config.summarize.enabled;
coreRefs.traceMultitenancyEnabled = this.config.traceMultitenancy.enabled;
coreRefs.overlays = core.overlays;
coreRefs.dataSource = startDeps.dataSource;

Expand Down
4 changes: 2 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const observabilityConfig = {
summarize: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
multitenancy: schema.object({
traceMultitenancy: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
}),
Expand All @@ -34,6 +34,6 @@ export const config: PluginConfigDescriptor<ObservabilityConfig> = {
exposeToBrowser: {
query_assist: true,
summarize: true,
multitenancy: true,
traceMultitenancy: true,
},
};
12 changes: 4 additions & 8 deletions server/routes/trace_analytics_dsl_router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ import {
TRACE_ANALYTICS_DSL_ROUTE,
TRACE_ANALYTICS_JAEGER_INDICES_ROUTE,
} from '../../common/constants/trace_analytics';
import { addRequestToMetric } from '../common/metrics/metrics_helper';
import { getTenantIndexName } from '../../common/utils/tenant_index_name';
import { addRequestToMetric } from '../common/metrics/metrics_helper';

export function registerTraceAnalyticsDslRouter(router: IRouter, dataSourceEnabled: boolean) {
router.post(
{
path: TRACE_ANALYTICS_DATA_PREPPER_INDICES_ROUTE,
validate: {
body: schema.object({
tenant: schema.maybe(schema.string()),
}),
body: schema.any(),
query: schema.object({
dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })),
}),
Expand Down Expand Up @@ -68,9 +66,7 @@ export function registerTraceAnalyticsDslRouter(router: IRouter, dataSourceEnabl
{
path: TRACE_ANALYTICS_JAEGER_INDICES_ROUTE,
validate: {
body: schema.object({
tenant: schema.maybe(schema.string()),
}),
body: schema.any(),
query: schema.object({
dataSourceMDSId: schema.maybe(schema.string({ defaultValue: '' })),
}),
Expand Down Expand Up @@ -148,7 +144,7 @@ export function registerTraceAnalyticsDslRouter(router: IRouter, dataSourceEnabl
},
async (context, request, response) => {
addRequestToMetric('trace_analytics', 'get', 'count');
const { index, size, ...rest } = request.body;
const { index, size, tenant, ...rest } = request.body;
const { dataSourceMDSId } = request.query;
const params: RequestParams.Search = {
index: index || getTenantIndexName(DATA_PREPPER_INDEX_NAME, tenant),
Expand Down

0 comments on commit 4b81b23

Please sign in to comment.