-
Notifications
You must be signed in to change notification settings - Fork 318
refactor: unify source types and remove ambiguity #1194
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
Open
knudtty
wants to merge
8
commits into
main
Choose a base branch
from
aaron/source-tech-debt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
23d5fde
unify source types and remove ambiguity
knudtty 5b3ed93
Merge branch 'main' into aaron/source-tech-debt
knudtty e25a223
fix linting
knudtty 0d65ec6
fix: sources not searching properly
knudtty 2108f6c
add defaults to source switches
knudtty 5403a87
testing: add robust source testing
knudtty e6330c2
Merge branch 'main' into aaron/source-tech-debt
knudtty feabfd3
fix source lint for ai
knudtty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,133 @@ | ||
import { | ||
LogSourceSchema, | ||
MetricsDataType, | ||
MetricSourceSchema, | ||
SessionSourceSchema, | ||
SourceKind, | ||
TraceSourceSchema, | ||
TSource, | ||
} from '@hyperdx/common-utils/dist/types'; | ||
import mongoose, { Schema } from 'mongoose'; | ||
import { z } from 'zod'; | ||
|
||
type ObjectId = mongoose.Types.ObjectId; | ||
|
||
export interface ISource extends Omit<TSource, 'connection'> { | ||
team: ObjectId; | ||
connection: ObjectId | string; | ||
} | ||
import { objectIdSchema } from '@/utils/zod'; | ||
|
||
const sourceExtension = { | ||
team: objectIdSchema.or(z.instanceof(mongoose.Types.ObjectId)), | ||
connection: objectIdSchema.or(z.instanceof(mongoose.Types.ObjectId)), | ||
}; | ||
const SourceModelSchema = z.discriminatedUnion('kind', [ | ||
LogSourceSchema.extend(sourceExtension), | ||
TraceSourceSchema.extend(sourceExtension), | ||
SessionSourceSchema.extend(sourceExtension), | ||
MetricSourceSchema.extend(sourceExtension), | ||
]); | ||
export type ISource = z.infer<typeof SourceModelSchema>; | ||
export type SourceDocument = mongoose.HydratedDocument<ISource>; | ||
|
||
export const Source = mongoose.model<ISource>( | ||
'Source', | ||
new Schema<ISource>( | ||
{ | ||
kind: { | ||
type: String, | ||
enum: Object.values(SourceKind), | ||
required: true, | ||
}, | ||
team: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
required: true, | ||
ref: 'Team', | ||
}, | ||
from: { | ||
databaseName: String, | ||
tableName: String, | ||
}, | ||
timestampValueExpression: String, | ||
connection: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
required: true, | ||
ref: 'Connection', | ||
}, | ||
|
||
name: String, | ||
displayedTimestampValueExpression: String, | ||
implicitColumnExpression: String, | ||
serviceNameExpression: String, | ||
bodyExpression: String, | ||
tableFilterExpression: String, | ||
eventAttributesExpression: String, | ||
resourceAttributesExpression: String, | ||
defaultTableSelectExpression: String, | ||
uniqueRowIdExpression: String, | ||
severityTextExpression: String, | ||
traceIdExpression: String, | ||
spanIdExpression: String, | ||
traceSourceId: String, | ||
sessionSourceId: String, | ||
metricSourceId: String, | ||
new Schema<ISource>({ | ||
name: String, | ||
kind: { | ||
type: String, | ||
enum: Object.values(SourceKind), | ||
required: true, | ||
}, | ||
from: { | ||
databaseName: String, | ||
tableName: String, | ||
}, | ||
team: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
required: true, | ||
ref: 'Team', | ||
}, | ||
connection: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
required: true, | ||
ref: 'Connection', | ||
}, | ||
}), | ||
); | ||
|
||
durationExpression: String, | ||
durationPrecision: Number, | ||
parentSpanIdExpression: String, | ||
spanNameExpression: String, | ||
export const LogSource = Source.discriminator< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Broke out the mongoose models into the base model ( |
||
Extract<TSource, { kind: SourceKind.Log }> | ||
>( | ||
SourceKind.Log, | ||
new mongoose.Schema<Extract<TSource, { kind: SourceKind.Log }>>({ | ||
timestampValueExpression: String, | ||
defaultTableSelectExpression: String, | ||
serviceNameExpression: String, | ||
severityTextExpression: String, | ||
bodyExpression: String, | ||
eventAttributesExpression: String, | ||
resourceAttributesExpression: String, | ||
displayedTimestampValueExpression: String, | ||
metricSourceId: String, | ||
traceSourceId: String, | ||
traceIdExpression: String, | ||
spanIdExpression: String, | ||
implicitColumnExpression: String, | ||
uniqueRowIdExpression: String, | ||
tableFilterExpression: String, | ||
}), | ||
); | ||
|
||
logSourceId: String, | ||
spanKindExpression: String, | ||
statusCodeExpression: String, | ||
statusMessageExpression: String, | ||
spanEventsValueExpression: String, | ||
export const TraceSource = Source.discriminator< | ||
Extract<TSource, { kind: SourceKind.Trace }> | ||
>( | ||
SourceKind.Trace, | ||
new mongoose.Schema<Extract<TSource, { kind: SourceKind.Trace }>>({ | ||
defaultTableSelectExpression: String, | ||
timestampValueExpression: String, | ||
durationExpression: String, | ||
durationPrecision: Number, | ||
traceIdExpression: String, | ||
spanIdExpression: String, | ||
parentSpanIdExpression: String, | ||
spanNameExpression: String, | ||
spanKindExpression: String, | ||
logSourceId: String, | ||
sessionSourceId: String, | ||
metricSourceId: String, | ||
statusCodeExpression: String, | ||
statusMessageExpression: String, | ||
serviceNameExpression: String, | ||
resourceAttributesExpression: String, | ||
eventAttributesExpression: String, | ||
spanEventsValueExpression: String, | ||
implicitColumnExpression: String, | ||
}), | ||
); | ||
|
||
metricTables: { | ||
type: { | ||
[MetricsDataType.Gauge]: String, | ||
[MetricsDataType.Histogram]: String, | ||
[MetricsDataType.Sum]: String, | ||
[MetricsDataType.Summary]: String, | ||
[MetricsDataType.ExponentialHistogram]: String, | ||
}, | ||
default: undefined, | ||
export const MetricSource = Source.discriminator< | ||
Extract<TSource, { kind: SourceKind.Metric }> | ||
>( | ||
SourceKind.Metric, | ||
new mongoose.Schema<Extract<TSource, { kind: SourceKind.Metric }>>({ | ||
metricTables: { | ||
type: { | ||
[MetricsDataType.Gauge]: String, | ||
[MetricsDataType.Histogram]: String, | ||
[MetricsDataType.Sum]: String, | ||
[MetricsDataType.Summary]: String, | ||
[MetricsDataType.ExponentialHistogram]: String, | ||
}, | ||
default: undefined, | ||
}, | ||
{ | ||
toJSON: { virtuals: true }, | ||
timestamps: true, | ||
}, | ||
), | ||
timestampValueExpression: String, | ||
resourceAttributesExpression: String, | ||
logSourceId: String, | ||
}), | ||
); | ||
|
||
export const SessionSource = Source.discriminator< | ||
Extract<TSource, { kind: SourceKind.Session }> | ||
>( | ||
SourceKind.Session, | ||
new mongoose.Schema<Extract<TSource, { kind: SourceKind.Session }>>({ | ||
traceSourceId: String, | ||
timestampValueExpression: String, | ||
}), | ||
); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should also handle default case