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

[Monitor][Codegen] Use generated TelemetryItem (as Envelope) #11280

Merged
merged 18 commits into from
Oct 8, 2020

Conversation

markwolff
Copy link
Contributor

$ rm Contracts/Envelope.ts
  • Use swagger generated TelemetryItem (as Envelope) interface instead .bond file Envelope class

@ghost ghost added the Monitor Monitor, Monitor Ingestion, Monitor Query label Sep 15, 2020
envelope.data.baseData.measurements = {
...envelope.data.baseData.measurements,
baseData.type = `Queue Message | ${namespace}`;
(baseData as any).source = `${peerAddress}/${messageBusDestination}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

baseData is currently generated as an empty interface for each Envelope type. I need to investigate whether the TS extension or the swagger file should be improved to make these nicer to work with

Copy link
Member

Choose a reason for hiding this comment

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

I'd hope we can generate something better than empty! @srnagar - any thoughts on how the swagger can be improved?

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

One small point of confusion I have is are we using Envelope to refer to the REST shape or the nice shape we want to present to customers? It feels like it was the REST shape before, whereas TelemetryItem is the nice convenience shape with better names.

envelope.data.baseData.measurements = {
...envelope.data.baseData.measurements,
baseData.type = `Queue Message | ${namespace}`;
(baseData as any).source = `${peerAddress}/${messageBusDestination}`;
Copy link
Member

Choose a reason for hiding this comment

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

I'd hope we can generate something better than empty! @srnagar - any thoughts on how the swagger can be improved?

@jmealo
Copy link

jmealo commented Oct 6, 2020

@xirzec @markwolff: I'm using this in staging. Any chance we can publish the latest preview to npm? I'm looking forward to metrics exporting. Keep up the good work!

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

Some thoughts -- mostly I'm worried that our public shape isn't very well defined. I feel like we could better express the shapes that go into / come out of this library better with TypeScript than we are. If that's a codegen limitation, we could also consider hand-authoring some of the shapes.

@@ -23,7 +23,7 @@ export interface TelemetryItem {
/**
* Event date time when telemetry item was created. This is the wall clock time on the client when the event was generated. There is no guarantee that the client's time is accurate. This field must be formatted in UTC ISO 8601 format, with a trailing 'Z' character, as described publicly on https://en.wikipedia.org/wiki/ISO_8601#UTC. Note: the number of decimal seconds digits provided are variable (and unspecified). Consumers should handle this, i.e. managed code consumers should not use format 'O' for parsing as it specifies a fixed length. Example: 2009-06-15T13:45:30.0000000Z.
*/
time: Date;
time: string;
Copy link
Member

Choose a reason for hiding this comment

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

did we really mean to make this a string and not a Date? Usually Date is easier to work with.

Copy link
Contributor Author

@markwolff markwolff Oct 8, 2020

Choose a reason for hiding this comment

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

Agreed. Have you gotten dates to be cross-lang interoperable in other client SDKs? Maybe the mapper/serializer could handle mapping Date to string?

https://github.com/Azure/azure-rest-api-specs/blob/27cc07ddd294d98e05cb301e07a72378df9f87e8/specification/applicationinsights/data-plane/Monitor.Exporters/preview/2020-09-15_Preview/swagger.json#L850-L853

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't it work if you do something like this?

"startTime": {
  "type": "string",
  "format": "date-time",
  "description": "The time when an indexer should start running."
}

*/
test?: string;
[property: string]: any;
Copy link
Member

Choose a reason for hiding this comment

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

This means anything that mixes in with MonitorDomain isn't type-checked by TS as all properties are valid. It would be best to avoid this if possible, since it's easy to make typos.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can go away once autorest supports oneOf polymophism. Until then, this is meant to be a temporary workaround

break;
default: // no op
}
}

return envelope;
return envelope as Envelope;
Copy link
Member

Choose a reason for hiding this comment

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

All the casts in this function seem fragile, since we're basically opting in and out of types.

Would it be possible to assemble the envelope at the end to avoid the partial? And perhaps to type all the base data separately before assigning to the envelope? It's a little tricky, but I feel like there should be a way to assemble a syntactically valid Envelope without having to turn off typechecks.


assert.strictEqual(envelope.data?.baseData?.source, undefined);
assert.strictEqual(envelope.data?.baseData?.measurements, undefined);
const baseData = envelope.data?.baseData as RemoteDependencyData;
Copy link
Member

Choose a reason for hiding this comment

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

how do you imagine folks actually using this? I submit if they have to do their own casts, we're not providing much value to TS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. The baseData types won't be very useful until we can use some oneOf schemas in the swagger file

markwolff and others added 4 commits October 8, 2020 13:15
…/httpSender.ts

Co-authored-by: Jeff Fisher <jeffish@microsoft.com>
…:Azure/azure-sdk-for-js into feature/monitor/codegen/migrate-envelope
@markwolff markwolff merged commit 5a4d307 into master Oct 8, 2020
@markwolff markwolff deleted the feature/monitor/codegen/migrate-envelope branch October 8, 2020 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Monitor Monitor, Monitor Ingestion, Monitor Query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants