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

DataFrame: Handle nanosecond-precision timestamp fields #64529

Merged
merged 1 commit into from Apr 6, 2023

Conversation

gabor
Copy link
Contributor

@gabor gabor commented Mar 9, 2023

requires grafana/grafana-plugin-sdk-go#647

  • we modify the typescript dataframe-field type, we add nanos
  • we modify the json-to-dataframe to handle the nanos field

(NOTE: an example usage is in #64687)

@@ -136,6 +136,7 @@ export interface Field<T = any, V = Vector<T>> {
*/
config: FieldConfig;
values: V; // The raw field values
additionalValues?: Record<string, V>;
Copy link
Member

Choose a reason for hiding this comment

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

Given that this is a pattern we know applies to time, and struggle to think of good cases for other things should we do something liket:

Suggested change
additionalValues?: Record<string, V>;
/** When type === FieldType.time, we can support nanosecond time bla bla bla... 8?
nanos?: number[];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can do 👍 .. just to doublecheck, we can go directly to a javascript-array, no need to have an ArrayVector ?

@gabor
Copy link
Contributor Author

gabor commented Mar 10, 2023

@ryantxu @leeoniya , i updated the PR:

  • field is now called nanos and has the nubmers as an array
  • added support to dataframeToJSON to make the cycle complete :)

@gabor gabor requested review from leeoniya and ryantxu March 10, 2023 15:46
@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2023

⚠️   Possible breaking changes

(Open the links below in a new tab to go to the correct steps)

grafana-data has possible breaking changes (more info)

Console output
Read our guideline

@grafanabot grafanabot added the levitate breaking change A label indicating a breaking change and assigned by Levitate. label Mar 10, 2023
@gabor gabor marked this pull request as ready for review March 13, 2023 13:24
@gabor gabor requested review from a team as code owners March 13, 2023 13:24
@gabor gabor requested review from tskarhed, JoaoSilvaGrafana and andresmgot and removed request for a team March 13, 2023 13:24
Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

👍 Code LGTM, I only found a couple of minor things. You can ignore the "breaking change" notice.

// TODO: expand arrays further using bases,factors

return {
const dataFrameField: Field & { entities: FieldValueEntityLookup } = {
...f,
type: type ?? guessFieldType(f.name, buffer),
config: f.config ?? {},
values: new ArrayVector(buffer),
// the presence of this prop is an optimization signal & lookup for consumers
entities: entities ?? {},
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since you are not using nanos elsewhere it can be defined here inline: nanos: data?.nanos?.[index],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, i agree. the question is this... the nanos field will always be there that way, but it's value will be undefined. in other words, with current code:

{ a: 1, b: 2}

inline nanos code:

{ a: 1, b: 2, nanos: undefined }

what i do not know, do we care about such details of not having a field "be there but value will be undefined"?

delete (sfield as any).entities;
data.values.push(values.toArray());

if (nanos != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the type of nanos is number[] | undefined, either the type or this condition is wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

!= null covers both null and undefined with fewer chars :)

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL javascript magic

> undefined != null
false
> undefined === null
false
> undefined == null
true

Anyway, it's just a nit but if nanos can be null I would define the type as nanos?: number[] | null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry @andresmgot , it's an annoying trick (the != null) and i in general really dislike such tricks, but this one is so good at basically isNullish(value) 😿

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, it's just a nit but if nanos can be null I would define the type as nanos?: number[] | null

it's a little tricky, but: field.nanos can never be null.

(dataframejson.nanos is a different thing, and that one is an array-of-arrays-or-nulls 😄 , like: [null, null, [1,2,3,4], null])

and the way we extract a value from that strange array causes the null to appear in our life, and that's why we need to check for both null and undefined later.

@gabor gabor changed the title DRAFT: logs: handle nanosec-timestamp fields Logs: handle nanosec-timestamp fields Mar 14, 2023
Copy link
Contributor

@leeoniya leeoniya left a comment

Choose a reason for hiding this comment

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

LGTM 👍

some notes:

the title of the PR/merge should likely not be "Logs:", but "DataFrame:"

  • we modify the typescript dataframe-field type, we add additionalValues

this description looks outdated relative to the current code

@gabor gabor changed the title Logs: handle nanosec-timestamp fields DataFrame: Handle nanosecond-precision timestamp fields Apr 5, 2023
@gabor gabor added this to the 10.0.0 milestone Apr 5, 2023
@gabor gabor added add to changelog no-backport Skip backport of PR and removed levitate breaking change A label indicating a breaking change and assigned by Levitate. labels Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants