Skip to content

Commit

Permalink
feat: Add observe_monitor_v2 resource (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
obs-gh-owengoebel authored Jul 23, 2024
1 parent 5af538d commit 55e5617
Show file tree
Hide file tree
Showing 13 changed files with 3,949 additions and 14 deletions.
31 changes: 31 additions & 0 deletions client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,37 @@ func (c *Client) GetMonitor(ctx context.Context, id string) (*meta.Monitor, erro
return c.Meta.GetMonitor(ctx, id)
}

func (c *Client) CreateMonitorV2(ctx context.Context, workspaceId string, input *meta.MonitorV2Input) (*meta.MonitorV2, error) {
if !c.Flags[flagObs2110] {
c.obs2110.Lock()
defer c.obs2110.Unlock()
}
if c.Config.ManagingObjectID != nil {
input.ManagedById = c.Config.ManagingObjectID
}
return c.Meta.CreateMonitorV2(ctx, workspaceId, input)
}

func (c *Client) UpdateMonitorV2(ctx context.Context, id string, input *meta.MonitorV2Input) (*meta.MonitorV2, error) {
if !c.Flags[flagObs2110] {
c.obs2110.Lock()
defer c.obs2110.Unlock()
}
return c.Meta.UpdateMonitorV2(ctx, id, input)
}

func (c *Client) DeleteMonitorV2(ctx context.Context, id string) error {
if !c.Flags[flagObs2110] {
c.obs2110.Lock()
defer c.obs2110.Unlock()
}
return c.Meta.DeleteMonitorV2(ctx, id)
}

func (c *Client) GetMonitorV2(ctx context.Context, id string) (*meta.MonitorV2, error) {
return c.Meta.GetMonitorV2(ctx, id)
}

// CreateMonitorActionAttachment creates a monitor action attachment
func (c *Client) CreateMonitorActionAttachment(ctx context.Context, input *meta.MonitorActionAttachmentInput) (*meta.MonitorActionAttachment, error) {
if !c.Flags[flagObs2110] {
Expand Down
280 changes: 280 additions & 0 deletions client/internal/meta/operation/monitorv2.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
# definitions of monitor v2 data

fragment MonitorV2Comparison on MonitorV2Comparison {
compareFn
# @genqlient(flatten: true)
compareValue {
...PrimitiveValue
}
}

fragment MonitorV2ColumnPath on MonitorV2ColumnPath {
name
path
}

fragment MonitorV2LinkColumnMeta on MonitorV2LinkColumnMeta {
# @genqlient(flatten: true)
srcFields {
...MonitorV2ColumnPath
}
dstFields
targetDataset
}

fragment MonitorV2LinkColumn on MonitorV2LinkColumn {
name
# @genqlient(flatten: true)
meta {
...MonitorV2LinkColumnMeta
}
}

fragment MonitorV2Column on MonitorV2Column {
# @genqlient(flatten: true)
linkColumn {
...MonitorV2LinkColumn
}
# @genqlient(flatten: true)
columnPath {
...MonitorV2ColumnPath
}
}

fragment MonitorV2ColumnComparison on MonitorV2ColumnComparison {
# @genqlient(flatten: true)
column {
...MonitorV2Column
}
# @genqlient(flatten: true)
compareValues {
...MonitorV2Comparison
}
}

fragment MonitorV2CountRule on MonitorV2CountRule {
# @genqlient(flatten: true)
compareValues {
...MonitorV2Comparison
}
# @genqlient(flatten: true)
compareGroups {
...MonitorV2ColumnComparison
}
}

fragment MonitorV2ThresholdRule on MonitorV2ThresholdRule {
# @genqlient(flatten: true)
compareValues {
...MonitorV2Comparison
}
valueColumnName
aggregation
# @genqlient(flatten: true)
compareGroups {
...MonitorV2ColumnComparison
}
}

fragment MonitorV2PromoteRule on MonitorV2PromoteRule {
# @genqlient(flatten: true)
compareColumns {
...MonitorV2ColumnComparison
}
}

fragment MonitorV2Rule on MonitorV2Rule {
level
# @genqlient(flatten: true)
count {
...MonitorV2CountRule
}
# @genqlient(flatten: true)
threshold {
...MonitorV2ThresholdRule
}
# @genqlient(flatten: true)
promote {
...MonitorV2PromoteRule
}
}

fragment MonitorV2Definition on MonitorV2Definition{
inputQuery {
outputStage
# @genqlient(flatten: true)
stages {
...StageQuery
}
}
# @genqlient(flatten: true)
rules {
...MonitorV2Rule
}
lookbackTime
dataStabilizationDelay
# @genqlient(flatten: true)
groupings {
...MonitorV2Column
}
# @genqlient(flatten: true)
scheduling {
...MonitorV2Scheduling
}
}

fragment MonitorV2IntervalSchedule on MonitorV2IntervalSchedule {
interval
randomize
}

fragment MonitorV2TransformSchedule on MonitorV2TransformSchedule {
freshnessGoal
}

fragment MonitorV2Scheduling on MonitorV2Scheduling {
# @genqlient(flatten: true)
interval {
...MonitorV2IntervalSchedule
}
# @genqlient(flatten: true)
transform {
...MonitorV2TransformSchedule
}
}

# @genqlient(for: "MonitorV2Input.comment", omitempty: true)
# @genqlient(for: "MonitorV2Input.iconUrl", omitempty: true)
# @genqlient(for: "MonitorV2Input.description", omitempty: true)
# @genqlient(for: "MonitorV2Input.managedById", omitempty: true)
# @genqlient(for: "MonitorV2Input.folderId", omitempty: true)
# @genqlient(for: "MonitorV2DefinitionInput.dataStabilizationDelay", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.count", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.threshold", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.promote", omitempty: true)
# @genqlient(for: "MonitorV2ColumnInput.linkColumn", omitempty: true)
# @genqlient(for: "MonitorV2ColumnInput.columnPath", omitempty: true)
# @genqlient(for: "MonitorV2LinkColumnInput.meta", omitempty: true)
# @genqlient(for: "MonitorV2ColumnPathInput.path", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageID", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.stageID", omitempty: true)
# @genqlient(for: "StageQueryInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.id", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.bool", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.float64", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.int64", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.string", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.timestamp", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.duration", omitempty: true)
fragment MonitorV2 on MonitorV2 {
id
workspaceId
createdBy
createdDate
name
iconUrl
description
managedById
folderId
comment
rollupStatus
ruleKind
# @genqlient(flatten: true)
definition {
...MonitorV2Definition
}
}

# definitions of monitorv2 CRUD ops

# @genqlient(for: "MonitorV2Input.comment", omitempty: true)
# @genqlient(for: "MonitorV2Input.iconUrl", omitempty: true)
# @genqlient(for: "MonitorV2Input.description", omitempty: true)
# @genqlient(for: "MonitorV2Input.managedById", omitempty: true)
# @genqlient(for: "MonitorV2Input.folderId", omitempty: true)
# @genqlient(for: "MonitorV2DefinitionInput.dataStabilizationDelay", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.count", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.threshold", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.promote", omitempty: true)
# @genqlient(for: "MonitorV2ColumnInput.linkColumn", omitempty: true)
# @genqlient(for: "MonitorV2ColumnInput.columnPath", omitempty: true)
# @genqlient(for: "MonitorV2LinkColumnInput.meta", omitempty: true)
# @genqlient(for: "MonitorV2ColumnPathInput.path", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageID", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.stageID", omitempty: true)
# @genqlient(for: "StageQueryInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.id", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.bool", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.float64", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.int64", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.string", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.timestamp", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.duration", omitempty: true)
mutation createMonitorV2(
$workspaceId: ObjectId!,
$input: MonitorV2Input!
) {
# @genqlient(flatten: true)
monitorV2: createMonitorV2(workspaceId:$workspaceId, input:$input) {
...MonitorV2
}
}

# @genqlient(for: "MonitorV2Input.comment", omitempty: true)
# @genqlient(for: "MonitorV2Input.iconUrl", omitempty: true)
# @genqlient(for: "MonitorV2Input.description", omitempty: true)
# @genqlient(for: "MonitorV2Input.managedById", omitempty: true)
# @genqlient(for: "MonitorV2Input.folderId", omitempty: true)
# @genqlient(for: "MonitorV2DefinitionInput.dataStabilizationDelay", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.count", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.threshold", omitempty: true)
# @genqlient(for: "MonitorV2RuleInput.promote", omitempty: true)
# @genqlient(for: "MonitorV2ColumnInput.linkColumn", omitempty: true)
# @genqlient(for: "MonitorV2ColumnInput.columnPath", omitempty: true)
# @genqlient(for: "MonitorV2LinkColumnInput.meta", omitempty: true)
# @genqlient(for: "MonitorV2ColumnPathInput.path", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageID", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.stageID", omitempty: true)
# @genqlient(for: "StageQueryInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.id", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.bool", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.float64", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.int64", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.string", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.timestamp", omitempty: true)
# @genqlient(for: "PrimitiveValueInput.duration", omitempty: true)
mutation updateMonitorV2(
$id: ObjectId!,
$input: MonitorV2Input!
) {
# @genqlient(flatten: true)
monitorV2: updateMonitorV2(id:$id, input:$input) {
...MonitorV2
}
}

query getMonitorV2($id: ObjectId!) {
# @genqlient(flatten: true)
monitorV2: monitorV2(id: $id) {
...MonitorV2
}
}

mutation deleteMonitorV2($id: ObjectId!) {
# @genqlient(flatten: true)
resultStatus: deleteMonitorV2(id: $id) {
...ResultStatus
}
}

query lookupMonitorV2($workspaceId: ObjectId, $folderId: ObjectId, $nameExact: String, $nameSubstring: String) {
monitorV2s: searchMonitorV2(workspaceId: $workspaceId, folderId: $folderId, nameExact: $nameExact, nameSubstring: $nameSubstring) {
# @genqlient(flatten: true)
results {
...MonitorV2
}
}
}
3 changes: 3 additions & 0 deletions client/internal/meta/schema/monitorv2.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ type MonitorV2Column @goModel(model: "observe/meta/metatypes.MonitorV2Column") {
Column path is any non-link typed column along with an optional path which the user wants to group by.
"""
columnPath: MonitorV2ColumnPath

}

input MonitorV2ColumnInput @goModel(model: "observe/meta/metatypes.MonitorV2ColumnInput") {
Expand Down Expand Up @@ -568,6 +569,7 @@ type MonitorV2CountRule @goModel(model: "observe/meta/metatypes.MonitorV2CountRu
(one rule for < 80 and one rule for > 90).
"""
compareValues: [MonitorV2Comparison!]!

"""
CompareGroups is a list of comparisons made against the columns which the monitor is grouped by.
This gives the option to add extra dimension to the existing rule by specifying which column of
Expand Down Expand Up @@ -620,6 +622,7 @@ input MonitorV2ThresholdRuleInput @goModel(model: "observe/meta/metatypes.Monito


# The monitor will promote each event in the raw input dataset into an alert. In order to uniquely identify

# and deduplicate these alerts, the groupings will help deduplicate the rows in the dataset:
# - Event Dataset: Rows can be deduplicated using the `groupings` field of the MonitorV2Definition.
# - Interval Dataset: Rows can be deduplicated using the `groupings` field of the MonitorV2Definition.
Expand Down
Loading

0 comments on commit 55e5617

Please sign in to comment.