[ENHANCEMENT] TimeSeriesChart: add query name support for query settings#585
[ENHANCEMENT] TimeSeriesChart: add query name support for query settings#585Gladorme wants to merge 6 commits into
Conversation
… for query settings Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
cc39a7d to
f6d19a8
Compare
| seriesIndex: 0, | ||
| querySettings: { | ||
| queryIndex: 0, | ||
| queryName: defaultQueryName(0), |
There was a problem hiding this comment.
that's a massive breaking change. This will break every dashboard created without dashboard as code or by migrating from Grafana.
There was a problem hiding this comment.
Yeah, I will check if I can keep old data model
There was a problem hiding this comment.
Ok, I remember why I did this change. We can't keep index, because it will cause issue when re-ordering queries with query settings. I will rename queryName to queryIndex, but result will be the same => they will need to update queryIndex.
There was a problem hiding this comment.
not sure why we are dropping the queryIndex, the index could be 0 and the name could be whatever. If name is a new field for better UX, queryIndex can be kept as it is.
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
Signed-off-by: Guillaume LADORME <Gladorme@users.noreply.github.com>
| if (querySettings.queryIndex === undefined) { | ||
| return querySettings; | ||
| } |
There was a problem hiding this comment.
It seems that the idea behind this condition was that, if queryIndex was undefined then queryName would already exist. So, simply return the current one. However, this could go wrong. The QuerySettingsOptions object could be completely empty due to the fact that all fields are optional. Therefore, regardless of how queryName is generated, it is still technically possible to receive an empty object. This may open the door to bugs in future.
/* ALL FIELDS ARE OPTIONAL */
export interface QuerySettingsOptions {
queryName?: string;
/**
* @deprecated Use `queryName` instead.
*/
queryIndex?: number;
colorMode?: 'fixed' | 'fixed-single';
colorValue?: string;
lineStyle?: LineStyleType;
areaOpacity?: number;
format?: FormatOptions;
}So, maybe?
if (querySettings.queryIndex === undefined && querySettings.queryName!==undefined)There was a problem hiding this comment.
Unfortunately, we can't enforce validation on cue on one field if one is missing and we don't want to do breaking change
| export interface QuerySettingsOptions { | ||
| queryIndex: number; | ||
| queryName?: string; | ||
| /** | ||
| * @deprecated Use `queryName` instead. | ||
| */ | ||
| queryIndex?: number; | ||
| colorMode?: 'fixed' | 'fixed-single'; | ||
| colorValue?: string; | ||
| lineStyle?: LineStyleType; |
There was a problem hiding this comment.
I understand that from the backend perspective a none-optional queryName could be problematic and probably a breaking change.
queryName?: strings.MinRunes(1)However, from the UI perspective this field looks mandatory and there is no way to drop it. This means that from UI we could still keep it as a none-optional field.
The fact that we could have empty object query settings is not a good idea in my opinion, although from the UI a query name is always guaranteed.
export interface QuerySettingsOptions {
queryName?: string;
/**
* @deprecated Use `queryName` instead.
*/
queryIndex?: number;
colorMode?: 'fixed' | 'fixed-single';
colorValue?: string;
lineStyle?: LineStyleType;
areaOpacity?: number;
format?: FormatOptions;
}There was a problem hiding this comment.
Unfortunately, we can't enforce validation on cue on one field if one is missing and we don't want to do breaking change
| queryName?: strings.MinRunes(1) | ||
| // queryIndex is deprecated, use queryName instead. Kept for backward compatibility. | ||
| queryIndex?: int & >=0 | ||
| colorMode?: "fixed" | "fixed-single" // NB: "palette" could be added later | ||
| colorValue?: =~"^#(?:[0-9a-fA-F]{3}){1,2}$" // hexadecimal color code | ||
| lineStyle?: #lineStyle |
There was a problem hiding this comment.
Look at the following payload that I crafted and sent to the backend.
Since the schema is fully optional now, such a payload is persisted. I think this should be avoided. If we insist that we should keep all fields optional, then maybe we should intercept the req and drop the querySettings completely. (I am just discussing the payload point of view)
There was a problem hiding this comment.
Users could do it yes, but UI form enforce query name. So ok to me with limitation we have
There was a problem hiding this comment.
Users could do it yes, but UI form enforce query name. So ok to me with limitation we have
@jgbernalp Could we also have your opinion about this?
Description
Depends on: perses/shared#69
Add support for query name in query settings + deprecating queryIndex.
Migration guide:
Via the UI:
Go the dashboard, edit timeserieschart panel, go to query settings, update any value and save (it will migrate all query settings of the panel to queryName)
Manually:
Replace
queryIndexbyqueryName.Replace number by string
Query #<index + 1>or use helperdefaultQueryName.Example:
queryIndex: 0becomequeryName: 'Query #1'.Screenshots
Queries:

Query settings:

Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes