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

feat(asset): add variable query #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TigranVardanyan
Copy link
Collaborator

Pull Request

🀨 Rationale

Added variable query to Asset datasource

πŸ‘©β€πŸ’» Implementation

  • Implemented metricFindQuery method
  • Added VariableQueryEditor

πŸ§ͺ Testing

  • Unit testing
  • Manual testing

βœ… Checklist

@markacamps
Copy link

Have we started the review yet? @CiprianAnton @kkerezsi


export type Props = QueryEditorProps<AssetDataSource, AssetQuery>

export class AssetQueryEditorCommon {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is kind of a strange implementation here. you are basically having a common class that you use in 2 places. You are also creating references to your methods from the datasource and components . I think a better solution here is to create a custom react hook and pass the methods in the components here needed.


readonly loadMinionIdOptions = (ids: SystemMetadata[] | void): Array<SelectableValue<string>> => {
if (!ids) {
return []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing the endline ;


const onWorkspaceChange = (item?: SelectableValue<string>): void => {
if (item?.value && item.value !== query.workspace) {
// if workspace changed, reset Systems and Assets fields
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just remove all comments from this component

import { AssetQuery } from "../types";
import { FloatingError, parseErrorMessage } from "../../../core/errors";

export function AssetVariableQueryEditor(props: Props) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a description/summary to your component instead. Something like :

This component is going to be used to render Assets as part of Grafana Variables. 

The following components will query for assets based by workspace and system

const render = setupRenderer(AssetVariableQueryEditor, FakeAssetDataSource);
const workspacesLoaded = () => waitForElementToBeRemoved(screen.getByTestId('Spinner'));


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra empty line

expect(screen.getByText('1')).toBeInTheDocument();

// User selects different workspace
await select(screen.getAllByRole('combobox')[0], 'Default workspace', { container: document.body });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can test what happens when the call to the backend fails.

We should get a floating error right ?

conditions.push(`workspace = "${workspace}"`);
}
const assetFilter = conditions.join(' and ');
const assetsResponse: AssetModel[] = await this.queryAssets(assetFilter, 1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this we need to specify in the HLD and discuss with Josh. Should we query for 1000 assets here ? We also don't have projection here so it will eat up a lot of unnecessary resources both on client and on the backend

@@ -98,6 +99,22 @@ export class AssetDataSource extends DataSourceBase<AssetMetadataQuery> {
}
}

async metricFindQuery({ minionIds, workspace }: AssetQuery): Promise<MetricFindValue[]> {
const conditions = [];
if (minionIds?.length) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we'd probably want to implement a query builder using the builder pattern to reduce complexity

@kkerezsi
Copy link
Collaborator

kkerezsi commented Oct 3, 2024

@TigranVardanyan I think here we'd need to get @joshuaprewitt feedback here to make sure that we are not building something that will eventually be rewritten to due missing/wrong requirements.

Please add a more detailed explanation and provide some screenshots to highlight how this code change will affect the product in the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants