Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,57 @@ export const interceptPerformanceArtifactsList = (overrideArtifacts?: {
).as('getCatalogSourceModelArtifacts');
};

/**
* Intercepts performance artifacts with dynamic response based on filterQuery presence.
* Returns 3 artifacts when filterQuery is present, 5 when absent.
* Used to test that perf filters are passed regardless of toggle state.
*/
export const interceptPerformanceArtifactsWithFilterCheck = (): void => {
cy.intercept(
{
method: 'GET',
url: new RegExp(
`/model-registry/api/${MODEL_CATALOG_API_VERSION}/model_catalog/sources/.*/performance_artifacts/.*`,
),
},
(req) => {
const hasFilterQuery = req.url.includes('filterQuery');
// Return different counts based on whether filterQuery is present
const artifactCount = hasFilterQuery ? 3 : 5;
const items = Array.from({ length: artifactCount }, (_, i) =>
mockCatalogPerformanceMetricsArtifact({
customProperties: {
hardware_configuration: {
metadataType: ModelRegistryMetadataType.STRING,
string_value: `${i + 1} x H100-80`,
},
ttft_p90: {
metadataType: ModelRegistryMetadataType.DOUBLE,
double_value: 50 + i * 10,
},
replicas: {
metadataType: ModelRegistryMetadataType.INT,
int_value: String(i + 1),
},
use_case: {
metadataType: ModelRegistryMetadataType.STRING,
string_value: 'chatbot',
},
},
}),
);
req.reply(
mockModArchResponse({
items,
size: artifactCount,
pageSize: 10,
nextPageToken: '',
}),
);
},
).as('getCatalogSourceModelArtifacts');
};

/**
* Intercepts the /artifacts/ endpoint (used to determine if tabs should show)
* @param overrideArtifacts - Optional override for the artifacts response (e.g., empty list)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { modelCatalog } from '~/__tests__/cypress/cypress/pages/modelCatalog';
import {
setupModelCatalogIntercepts,
interceptPerformanceArtifactsWithFilterCheck,
type ModelCatalogInterceptOptions,
} from '~/__tests__/cypress/cypress/support/interceptHelpers/modelCatalog';
import { PERFORMANCE_FILTER_TEST_IDS } from '~/__tests__/cypress/cypress/support/constants';
Expand Down Expand Up @@ -169,6 +170,39 @@ describe('ModelCatalogCard Component', () => {
});
});
});

describe('Benchmark count consistency', () => {
it('should show same benchmark count with toggle OFF as with toggle ON', () => {
// Use dynamic mock that returns different counts based on filterQuery presence
// Returns 3 artifacts when filterQuery present, 5 when absent
setupModelCatalogIntercepts({ useValidatedModel: true });
interceptPerformanceArtifactsWithFilterCheck();

modelCatalog.visit();

// Turn toggle ON to apply default filters
modelCatalog.togglePerformanceView();
modelCatalog.findLoadingState().should('not.exist');

// Verify benchmark count with toggle ON (shows "X of 3 benchmarks")
cy.wait('@getCatalogSourceModelArtifacts');
modelCatalog.findFirstModelCatalogCard().within(() => {
modelCatalog.findValidatedModelBenchmarksCount().should('contain.text', '3 benchmarks');
});

// Turn toggle OFF - should still show same count (filters still passed)
modelCatalog.togglePerformanceView();
modelCatalog.findLoadingState().should('not.exist');

// Verify benchmark count with toggle OFF (shows "View 3 benchmarks")
cy.wait('@getCatalogSourceModelArtifacts');
modelCatalog.findFirstModelCatalogCard().within(() => {
modelCatalog
.findValidatedModelBenchmarkLink()
.should('contain.text', 'View 3 benchmarks');
});
});
});
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ export const ModelCatalogContextProvider: React.FC<ModelCatalogContextProviderPr
[baseSetFilterData, isOnDetailsPage],
);

// Apply default performance filters when filterOptions first loads
React.useEffect(() => {
if (filterOptionsLoaded && filterOptions?.namedQueries) {
resetPerformanceFiltersToDefaults();
}
Comment on lines +289 to +291
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I wonder if we should only have this trigger if there are no perf filters in state (or maybe if at least one of the filters present in namedQueries has no value in state) so we don't accidentally reset them to defaults when filter options are fetched again

}, [filterOptions?.namedQueries, filterOptionsLoaded, resetPerformanceFiltersToDefaults]);

const contextValue = React.useMemo(
() => ({
catalogSourcesLoaded,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,18 @@ const ModelCatalogCardBody: React.FC<ModelCatalogCardBodyProps> = ({
};

// Get performance-specific filter params for the /performance_artifacts endpoint
// Only apply performance filters when toggle is ON
const targetRPS = performanceViewEnabled
? filterData[ModelCatalogNumberFilterKey.MAX_RPS]
: undefined;
// Always apply performance filters to get accurate benchmark counts, regardless of toggle state
const targetRPS = filterData[ModelCatalogNumberFilterKey.MAX_RPS];
// Get full filter key for display purposes
const latencyFieldName = performanceViewEnabled
? getActiveLatencyFieldName(filterData)
: undefined;
const latencyFieldName = getActiveLatencyFieldName(filterData);
// Use short property key (e.g., 'ttft_p90') for the catalog API, not the full filter key
const latencyProperty = latencyFieldName
? parseLatencyFilterKey(latencyFieldName).propertyKey
: undefined;

// Fetch performance artifacts from the new endpoint with server-side filtering
// When toggle is OFF, don't pass filterData so no perf filters are applied
// Always pass filterData so perf filters are applied - this ensures accurate benchmark counts
// The toggle only controls display, not the artifact fetch filters
const [performanceArtifactsList, performanceArtifactsLoaded, performanceArtifactsError] =
useCatalogPerformanceArtifacts(
source?.id || '',
Expand All @@ -94,8 +91,8 @@ const ModelCatalogCardBody: React.FC<ModelCatalogCardBodyProps> = ({
sortOrder: SortOrder.ASC,
}),
},
performanceViewEnabled ? filterData : undefined,
performanceViewEnabled ? filterOptions : undefined,
filterData,
filterOptions,
isValidated, // Only fetch if validated
);

Expand Down
Loading