Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Search: Use search input to query volume API #410

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ jobs:
run: yarn server:ci
- name: Install Playwright Browsers
run: npx playwright install chromium --with-deps
- name: Wait for docker
run: sleep 60
- name: Run e2e tests
id: run-tests
run: yarn e2e
Expand Down
10 changes: 10 additions & 0 deletions src/Components/ServiceSelectionScene/NoVolumeError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { GrotError } from 'Components/GrotError';

export const NoVolumeError = () => {
return (
<GrotError>
<p>No service matched your search.</p>
</GrotError>
);
};
16 changes: 12 additions & 4 deletions src/Components/ServiceSelectionScene/ServiceSelectionScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { buildLokiQuery } from 'services/query';
import { USER_EVENTS_ACTIONS, USER_EVENTS_PAGES, reportAppInteraction } from 'services/analytics';
import { getQueryRunner, setLeverColorOverrides } from 'services/panel';
import { ConfigureVolumeError } from './ConfigureVolumeError';
import { NoVolumeError } from './NoVolumeError';

export const SERVICE_NAME = 'service_name';

Expand All @@ -49,6 +50,8 @@ interface ServiceSelectionComponentState extends SceneObjectState {
searchServicesString: string;
// List of services to be shown in the body
servicesToQuery?: string[];
// in case the volume api errors out
volumeApiError?: boolean;
}

export class StartingPointSelectedEvent extends BusEventBase {
Expand Down Expand Up @@ -114,6 +117,7 @@ export class ServiceSelectionComponent extends SceneObjectBase<ServiceSelectionC
this.setState({
servicesToQuery,
});
this.getServicesByVolume(newState.searchServicesString);
}

// When servicesToQuery is changed, update the body and render the panels with the new services
Expand All @@ -130,7 +134,7 @@ export class ServiceSelectionComponent extends SceneObjectBase<ServiceSelectionC
}

// Run to fetch services by volume
private async getServicesByVolume() {
private async getServicesByVolume(service?: string) {
const timeRange = sceneGraph.getTimeRange(this).state.value;
this.setState({
isServicesByVolumeLoading: true,
Expand All @@ -141,10 +145,11 @@ export class ServiceSelectionComponent extends SceneObjectBase<ServiceSelectionC
}

try {
const serviceSearch = service ? `(?i).*${service}.*` : '.+';
const volumeResponse = await ds.getResource!(
'index/volume',
{
query: `{${SERVICE_NAME}=~".+"}`,
query: `{${SERVICE_NAME}=~"${serviceSearch}"}`,
from: timeRange.from.utc().toISOString(),
to: timeRange.to.utc().toISOString(),
},
Expand All @@ -166,12 +171,14 @@ export class ServiceSelectionComponent extends SceneObjectBase<ServiceSelectionC
.map(([serviceName]) => serviceName); // Extract service names

this.setState({
volumeApiError: false,
servicesByVolume,
isServicesByVolumeLoading: false,
});
} catch (error) {
console.log(`Failed to fetch top services:`, error);
this.setState({
volumeApiError: true,
servicesByVolume: [],
isServicesByVolumeLoading: false,
});
Expand Down Expand Up @@ -279,7 +286,7 @@ export class ServiceSelectionComponent extends SceneObjectBase<ServiceSelectionC

public static Component = ({ model }: SceneComponentProps<ServiceSelectionComponent>) => {
const styles = useStyles2(getStyles);
const { isServicesByVolumeLoading, servicesByVolume, servicesToQuery, body } = model.useState();
const { isServicesByVolumeLoading, servicesByVolume, servicesToQuery, body, volumeApiError } = model.useState();

// searchQuery is used to keep track of the search query in input field
const [searchQuery, setSearchQuery] = useState('');
Expand Down Expand Up @@ -310,7 +317,8 @@ export class ServiceSelectionComponent extends SceneObjectBase<ServiceSelectionC
/>
</Field>
{/** If we don't have any servicesByVolume, volume endpoint is probably not enabled */}
{!isServicesByVolumeLoading && !servicesByVolume?.length && <ConfigureVolumeError />}
{!isServicesByVolumeLoading && volumeApiError && <ConfigureVolumeError />}
{!isServicesByVolumeLoading && !volumeApiError && !servicesByVolume?.length && <NoVolumeError />}
{!isServicesByVolumeLoading && servicesToQuery && servicesToQuery.length > 0 && (
<div className={styles.body}>
<body.Component model={body} />
Expand Down