insights: update gql schema to allow errors for some insightviews #44491
Conversation
Bundle size report 📦
Look at the Statoscope report for a full comparison between the commits 0d6b1e9 and 77009d4 or learn more. Open explanation
|
vovakulikov
left a comment
There was a problem hiding this comment.
@chwarwick left a few comments
| seriesToggleState.setSelectedSeriesIds([]) | ||
| setInsightData(parsedData) | ||
| const node = data.insightViews.nodes[0] | ||
| if (node !== null) { |
There was a problem hiding this comment.
@chwarwick should we throw an error here if we didn't find insight here? Or this wouldn't be the case here because we filter out the null insights at the query before (where we fetch insight configurations)?
Thought: Even if we filter out the null insights at the beginning it still should be possible to fetch insight configuration without a problem but encounter a problem and get a null value here in the backend insight card. Therefore I think we should handle error case here as well.
There was a problem hiding this comment.
Also, I noticed that in the standalone insight page gql handler, we stopped polling manually in case of insight null value. Should we also handle this in this component?
There was a problem hiding this comment.
At first I was thinking that if we have a null insight it would always have an error, which is true for our current implementation but the schema does allow that to be null and have no error so I should handle that.
The polling I don't think is an issue because it will get stoped by isFetchingHistoricalData being undefined
There was a problem hiding this comment.
@vovakulikov after looking at this more I do not believe there needs to be any additional changes.
If there was an error in 1 more of the resolvers the insight is returned null and the apollo error is populated. This display the error in the card.
Polling will be stoped because a null/undefined insight will produce a falsey isFetchingHistoricalData
| @@ -0,0 +1,3 @@ | |||
| export function isNotNull<T>(value: T | null): value is T { | |||
There was a problem hiding this comment.
nice i was thinking something like this had to exist somewhere I just couldn't find it.
|
So this seems to always ignore the errored insights (hide them in lists and treat as a "not found" error for single view). That's an improvement to before, but I think ideally we would still render a card for those insights and pluck the error out of the |
|
@felixfbecker this is what we discussed with @chwarwick last week when we were having a conversation about this PR. I think it should be technically possible, we would have to change our typings about insight configuration and add there a union type like: Instead of just filtering out the null insights at the top level. This idea doesn't block this PR though. I think this might be a good follow up issue for this handling errored insight story. @chwarwick if you're agree can you fill a follow up issue for this. (I will make a quick investigation about how difficult it would be to have more verbose error handling before our next planning meeting) |
|
Agree that it doesn't block. The GraphQL schema would quickly become a mess if we added an |
|
@felixfbecker I didn't mean the schema, I was talking about FE types and components API. |
@felixfbecker There is a follow up issue for that, this issue is meant to eliminate the worst case scenario of 1 bad insight making the entire insights section unusable. |
|
Thanks, but noting that follow-up issue goes much further than what I was suggesting – I'm just suggesting displaying the error, not returning enough data to allow mutation. Even if https://github.com/sourcegraph/sourcegraph/issues/38951 is implemented, there can still be unexpected error cases in which it would probably be good to not just make those insights "disappear" but surface the error at least so the user knows something is wrong and is not just wondering "where did my insights go?". |

Updates the schema to allow for some insight views to error while still returning the rest of the insights. Previously with the schema as
[InsightView!]!any error would propagate up until it found a nullable field which would remove all insightviews and make the insights UI unusable.closes https://github.com/sourcegraph/sourcegraph/issues/42301
Test plan
With an error forced on the 2nd insight:
{ "errors": [ { "message": "simulated error", "path": ["insightViews", "nodes", 1, "presentation"] } ], "data": { "insightViews": { "nodes": [ { "id": "aW5zaWdodF92aWV3OiIySEhORjFUU29oazNnM0drNUxEaDM3UnYyMEgi", "defaultSeriesDisplayOptions": { "limit": 20, "sortOptions": { "mode": "RESULT_COUNT", "direction": "DESC", "__typename": "SeriesSortOptions" }, "__typename": "SeriesDisplayOptions" }, "appliedSeriesDisplayOptions": { "limit": 20, "sortOptions": { "mode": "RESULT_COUNT", "direction": "DESC", "__typename": "SeriesSortOptions" }, "__typename": "SeriesDisplayOptions" }, "isFrozen": false, "appliedFilters": { "includeRepoRegex": "", "excludeRepoRegex": "", "searchContexts": [], "__typename": "InsightViewFilters" }, "dashboardReferenceCount": 0, "dashboards": { "nodes": [], "__typename": "InsightsDashboardConnection" }, "presentation": { "__typename": "LineChartInsightViewPresentation", "title": "TODO FIXME", "seriesPresentation": [ { "seriesId": "2HXcICBeRFSkdZl1okp5Adbqzqz", "label": "FIXME", "color": "var(--oc-grape-7)", "__typename": "LineChartDataSeriesPresentation" }, { "seriesId": "2HXcIDyGCbux9SvdM7DcqcbDuUY", "label": "TODO", "color": "var(--oc-grape-7)", "__typename": "LineChartDataSeriesPresentation" } ] }, "dataSeriesDefinitions": [ { "seriesId": "2HXcICBeRFSkdZl1okp5Adbqzqz", "query": "FIXME ", "repositoryScope": { "repositories": [], "__typename": "InsightRepositoryScope" }, "timeScope": { "unit": "DAY", "value": 9, "__typename": "InsightIntervalTimeScope" }, "isCalculated": true, "generatedFromCaptureGroups": false, "groupBy": null, "__typename": "SearchInsightDataSeriesDefinition" }, { "seriesId": "2HXcIDyGCbux9SvdM7DcqcbDuUY", "query": "TODO ", "repositoryScope": { "repositories": [], "__typename": "InsightRepositoryScope" }, "timeScope": { "unit": "DAY", "value": 9, "__typename": "InsightIntervalTimeScope" }, "isCalculated": true, "generatedFromCaptureGroups": false, "groupBy": null, "__typename": "SearchInsightDataSeriesDefinition" } ], "__typename": "InsightView" }, null ], "__typename": "InsightViewConnection" } } }The dashboard still renders non-erroring insights:
