grafana / cog

Code Generation with a human touch
Apache License 2.0
48 stars 2 forks source link

Use the datasource type within queries to unmarshal them #567

Closed K-Phoen closed 1 month ago

K-Phoen commented 1 month ago

To determine in which Go struct to unmarshal a dataquery, cog's runtime currently only looks at the datasource details contained in the panel (if it exists). To make the unmarshalling more accurate, we should also look into the query itself since it can hold a DatasourceRef.

This PR only updates the Go jenny, other languages should mimic this behavior.

Relates to #566 and #560

github-actions[bot] commented 1 month ago

Note: in addition to the changes introduced by this PR, the diff includes unreleased changes living in main.

### 🔎 Changes to `grafana-foundation-sdk@next+cog-v0.0.x` ```patch diff --git a/.github/workflows/typescript-release.yaml b/.github/workflows/typescript-release.yaml index b5d29dc..12d6c19 100644 --- a/.github/workflows/typescript-release.yaml +++ b/.github/workflows/typescript-release.yaml @@ -20,6 +20,7 @@ jobs: permissions: contents: read + id-token: write defaults: run: diff --git a/go/accesspolicy/types_gen.go b/go/accesspolicy/types_gen.go index e388a21..f6932d9 100644 --- a/go/accesspolicy/types_gen.go +++ b/go/accesspolicy/types_gen.go @@ -12,6 +12,27 @@ type AccessPolicy struct { Rules []AccessRule `json:"rules"` } +func (resource AccessPolicy) Equals(other AccessPolicy) bool { + if !resource.Scope.Equals(other.Scope) { + return false + } + if !resource.Role.Equals(other.Role) { + return false + } + + if len(resource.Rules) != len(other.Rules) { + return false + } + + for i1 := range resource.Rules { + if !resource.Rules[i1].Equals(other.Rules[i1]) { + return false + } + } + + return true +} + type RoleRef struct { // Policies can apply to roles, teams, or users // Applying policies to individual users is supported, but discouraged @@ -20,11 +41,36 @@ type RoleRef struct { Xname string `json:"xname"` } +func (resource RoleRef) Equals(other RoleRef) bool { + if resource.Kind != other.Kind { + return false + } + if resource.Name != other.Name { + return false + } + if resource.Xname != other.Xname { + return false + } + + return true +} + type ResourceRef struct { Kind string `json:"kind"` Name string `json:"name"` } +func (resource ResourceRef) Equals(other ResourceRef) bool { + if resource.Kind != other.Kind { + return false + } + if resource.Name != other.Name { + return false + } + + return true +} + type AccessRule struct { // The kind this rule applies to (dashboards, alert, etc) Kind string `json:"kind"` @@ -35,6 +81,26 @@ type AccessRule struct { Target *string `json:"target,omitempty"` } +func (resource AccessRule) Equals(other AccessRule) bool { + if resource.Kind != other.Kind { + return false + } + if resource.Verb != other.Verb { + return false + } + if resource.Target == nil && other.Target != nil || resource.Target != nil && other.Target == nil { + return false + } + + if resource.Target != nil { + if *resource.Target != *other.Target { + return false + } + } + + return true +} + type RoleRefKind string const ( diff --git a/go/alerting/types_gen.go b/go/alerting/types_gen.go index 89f5def..a346ebb 100644 --- a/go/alerting/types_gen.go +++ b/go/alerting/types_gen.go @@ -64,6 +64,56 @@ func (resource *Query) UnmarshalJSON(raw []byte) error { return nil } +func (resource Query) Equals(other Query) bool { + if resource.DatasourceUid == nil && other.DatasourceUid != nil || resource.DatasourceUid != nil && other.DatasourceUid == nil { + return false + } + + if resource.DatasourceUid != nil { + if *resource.DatasourceUid != *other.DatasourceUid { + return false + } + } + if resource.Model == nil && other.Model != nil || resource.Model != nil && other.Model == nil { + return false + } + + if resource.Model != nil { + if !resource.Model.Equals(other.Model) { + return false + } + } + if resource.QueryType == nil && other.QueryType != nil || resource.QueryType != nil && other.QueryType == nil { + return false + } + + if resource.QueryType != nil { + if *resource.QueryType != *other.QueryType { + return false + } + } + if resource.RefId == nil && other.RefId != nil || resource.RefId != nil && other.RefId == nil { + return false + } + + if resource.RefId != nil { + if *resource.RefId != *other.RefId { + return false + } + } + if resource.RelativeTimeRange == nil && other.RelativeTimeRange != nil || resource.RelativeTimeRange != nil && other.RelativeTimeRange == nil { + return false + } + + if resource.RelativeTimeRange != nil { + if !resource.RelativeTimeRange.Equals(*other.RelativeTimeRange) { + return false + } + } + + return true +} + type RuleGroup struct { FolderUid *string `json:"folderUid,omitempty"` // The interval, in seconds, at which all rules in the group are evaluated. @@ -73,6 +123,48 @@ type RuleGroup struct { Title *string `json:"title,omitempty"` } +func (resource RuleGroup) Equals(other RuleGroup) bool { + if resource.FolderUid == nil && other.FolderUid != nil || resource.FolderUid != nil && other.FolderUid == nil { + return false + } + + if resource.FolderUid != nil { + if *resource.FolderUid != *other.FolderUid { + return false + } + } + if resource.Interval == nil && other.Interval != nil || resource.Interval != nil && other.Interval == nil { + return false + } + + if resource.Interval != nil { + if *resource.Interval != *other.Interval { + return false + } + } + + if len(resource.Rules) != len(other.Rules) { + return false + } + + for i1 := range resource.Rules { + if !resource.Rules[i1].Equals(other.Rules[i1]) { + return false + } + } + if resource.Title == nil && other.Title != nil || resource.Title != nil && other.Title == nil { + return false + } + + if resource.Title != nil { + if *resource.Title != *other.Title { + return false + } + } + + return true +} + type NotificationSettings struct { GroupBy []string `json:"group_by,omitempty"` GroupInterval *string `json:"group_interval,omitempty"` @@ -82,6 +174,61 @@ type NotificationSettings struct { RepeatInterval *string `json:"repeat_interval,omitempty"` } +func (resource NotificationSettings) Equals(other NotificationSettings) bool { + + if len(resource.GroupBy) != len(other.GroupBy) { + return false + } + + for i1 := range resource.GroupBy { + if resource.GroupBy[i1] != other.GroupBy[i1] { + return false + } + } + if resource.GroupInterval == nil && other.GroupInterval != nil || resource.GroupInterval != nil && other.GroupInterval == nil { + return false + } + + if resource.GroupInterval != nil { + if *resource.GroupInterval != *other.GroupInterval { + return false + } + } + if resource.GroupWait == nil && other.GroupWait != nil || resource.GroupWait != nil && other.GroupWait == nil { + return false + } + + if resource.GroupWait != nil { + if *resource.GroupWait != *other.GroupWait { + return false + } + } + + if len(resource.MuteTimeIntervals) != len(other.MuteTimeIntervals) { + return false + } + + for i1 := range resource.MuteTimeIntervals { + if resource.MuteTimeIntervals[i1] != other.MuteTimeIntervals[i1] { + return false + } + } + if resource.Receiver != other.Receiver { + return false + } + if resource.RepeatInterval == nil && other.RepeatInterval != nil || resource.RepeatInterval != nil && other.RepeatInterval == nil { + return false + } + + if resource.RepeatInterval != nil { + if *resource.RepeatInterval != *other.RepeatInterval { + return false + } + } + + return true +} + // Duration in seconds. type Duration int64 @@ -108,6 +255,53 @@ type ContactPoint struct { Uid *string `json:"uid,omitempty"` } +func (resource ContactPoint) Equals(other ContactPoint) bool { + if resource.DisableResolveMessage == nil && other.DisableResolveMessage != nil || resource.DisableResolveMessage != nil && other.DisableResolveMessage == nil { + return false + } + + if resource.DisableResolveMessage != nil { + if *resource.DisableResolveMessage != *other.DisableResolveMessage { + return false + } + } + if resource.Name == nil && other.Name != nil || resource.Name != nil && other.Name == nil { + return false + } + + if resource.Name != nil { + if *resource.Name != *other.Name { + return false + } + } + if resource.Provenance == nil && other.Provenance != nil || resource.Provenance != nil && other.Provenance == nil { + return false + } + + if resource.Provenance != nil { + if *resource.Provenance != *other.Provenance { + return false + } + } + if resource.Settings != other.Settings { + return false + } + if resource.Type != other.Type { + return false + } + if resource.Uid == nil && other.Uid != nil || resource.Uid != nil && other.Uid == nil { + return false + } + + if resource.Uid != nil { + if *resource.Uid != *other.Uid { + return false + } + } + + return true +} + type Json any type MatchRegexps map[string]string @@ -127,6 +321,38 @@ type Matcher struct { Value *string `json:"Value,omitempty"` } +func (resource Matcher) Equals(other Matcher) bool { + if resource.Name == nil && other.Name != nil || resource.Name != nil && other.Name == nil { + return false + } + + if resource.Name != nil { + if *resource.Name != *other.Name { + return false + } + } + if resource.Type == nil && other.Type != nil || resource.Type != nil && other.Type == nil { + return false + } + + if resource.Type != nil { + if *resource.Type != *other.Type { + return false + } + } + if resource.Value == nil && other.Value != nil || resource.Value != nil && other.Value == nil { + return false + } + + if resource.Value != nil { + if *resource.Value != *other.Value { + return false + } + } + + return true +} + // Matchers is a slice of Matchers that is sortable, implements Stringer, and // provides a Matches method to match a LabelSet against all Matchers in the // slice. Note that some users of Matchers might require it to be sorted. @@ -137,6 +363,30 @@ type MuteTiming struct { TimeIntervals []TimeInterval `json:"time_intervals,omitempty"` } +func (resource MuteTiming) Equals(other MuteTiming) bool { + if resource.Name == nil && other.Name != nil || resource.Name != nil && other.Name == nil { + return false + } + + if resource.Name != nil { + if *resource.Name != *other.Name { + return false + } + } + + if len(resource.TimeIntervals) != len(other.TimeIntervals) { + return false + } + + for i1 := range resource.TimeIntervals { + if !resource.TimeIntervals[i1].Equals(other.TimeIntervals[i1]) { + return false + } + } + + return true +} + type NotificationTemplate struct { Name *string `json:"name,omitempty"` Provenance *Provenance `json:"provenance,omitempty"` @@ -144,6 +394,47 @@ type NotificationTemplate struct { Version *string `json:"version,omitempty"` } +func (resource NotificationTemplate) Equals(other NotificationTemplate) bool { + if resource.Name == nil && other.Name != nil || resource.Name != nil && other.Name == nil { + return false + } + + if resource.Name != nil { + if *resource.Name != *other.Name { + return false + } + } + if resource.Provenance == nil && other.Provenance != nil || resource.Provenance != nil && other.Provenance == nil { + return false + } + + if resource.Provenance != nil { + if *resource.Provenance != *other.Provenance { + return false + } + } + if resource.Template == nil && other.Template != nil || resource.Template != nil && other.Template == nil { + return false + } + + if resource.Template != nil { + if *resource.Template != *other.Template { + return false + } + } + if resource.Version == nil && other.Version != nil || resource.Version != nil && other.Version == nil { + return false + } + + if resource.Version != nil { + if *resource.Version != *other.Version { + return false + } + } + + return true +} + type ObjectMatcher []string type ObjectMatchers []ObjectMatcher @@ -173,11 +464,144 @@ type Rule struct { Updated *time.Time `json:"updated,omitempty"` } +func (resource Rule) Equals(other Rule) bool { + + if len(resource.Annotations) != len(other.Annotations) { + return false + } + + for key1 := range resource.Annotations { + if resource.Annotations[key1] != other.Annotations[key1] { + return false + } + } + if resource.Condition != other.Condition { + return false + } + + if len(resource.Data) != len(other.Data) { + return false + } + + for i1 := range resource.Data { + if !resource.Data[i1].Equals(other.Data[i1]) { + return false + } + } + if resource.ExecErrState != other.ExecErrState { + return false + } + if resource.FolderUID != other.FolderUID { + return false + } + if resource.For != other.For { + return false + } + if resource.Id == nil && other.Id != nil || resource.Id != nil && other.Id == nil { + return false + } + + if resource.Id != nil { + if *resource.Id != *other.Id { + return false + } + } + if resource.IsPaused == nil && other.IsPaused != nil || resource.IsPaused != nil && other.IsPaused == nil { + return false + } + + if resource.IsPaused != nil { + if *resource.IsPaused != *other.IsPaused { + return false + } + } + + if len(resource.Labels) != len(other.Labels) { + return false + } + + for key1 := range resource.Labels { + if resource.Labels[key1] != other.Labels[key1] { + return false + } + } + if resource.NoDataState != other.NoDataState { + return false + } + if resource.NotificationSettings == nil && other.NotificationSettings != nil || resource.NotificationSettings != nil && other.NotificationSettings == nil { + return false + } + + if resource.NotificationSettings != nil { + if !resource.NotificationSettings.Equals(*other.NotificationSettings) { + return false + } + } + if resource.OrgID != other.OrgID { + return false + } + if resource.Provenance == nil && other.Provenance != nil || resource.Provenance != nil && other.Provenance == nil { + return false + } + + if resource.Provenance != nil { + if *resource.Provenance != *other.Provenance { + return false + } + } + if resource.Record == nil && other.Record != nil || resource.Record != nil && other.Record == nil { + return false + } + + if resource.Record != nil { + if !resource.Record.Equals(*other.Record) { + return false + } + } + if resource.RuleGroup != other.RuleGroup { + return false + } + if resource.Title != other.Title { + return false + } + if resource.Uid == nil && other.Uid != nil || resource.Uid != nil && other.Uid == nil { + return false + } + + if resource.Uid != nil { + if *resource.Uid != *other.Uid { + return false + } + } + if resource.Updated == nil && other.Updated != nil || resource.Updated != nil && other.Updated == nil { + return false + } + + if resource.Updated != nil { + if *resource.Updated != *other.Updated { + return false + } + } + + return true +} + type RecordRule struct { From string `json:"from"` Metric string `json:"metric"` } +func (resource RecordRule) Equals(other RecordRule) bool { + if resource.From != other.From { + return false + } + if resource.Metric != other.Metric { + return false + } + + return true +} + // RelativeTimeRange is the per query start and end time // for requests. type RelativeTimeRange struct { @@ -189,6 +613,29 @@ type RelativeTimeRange struct { To *Duration `json:"to,omitempty"` } +func (resource RelativeTimeRange) Equals(other RelativeTimeRange) bool { + if resource.From == nil && other.From != nil || resource.From != nil && other.From == nil { + return false + } + + if resource.From != nil { + if *resource.From != *other.From { + return false + } + } + if resource.To == nil && other.To != nil || resource.To != nil && other.To == nil { + return false + } + + if resource.To != nil { + if *resource.To != *other.To { + return false + } + } + + return true +} + // A Route is a node that contains definitions of how to handle alerts. This is modified // from the upstream alertmanager in that it adds the ObjectMatchers property. type NotificationPolicy struct { @@ -236,11 +683,199 @@ type NotificationPolicy struct { Routes []NotificationPolicy `json:"routes,omitempty"` } +func (resource NotificationPolicy) Equals(other NotificationPolicy) bool { + + if len(resource.ActiveTimeIntervals) != len(other.ActiveTimeIntervals) { + return false + } + + for i1 := range resource.ActiveTimeIntervals { + if resource.ActiveTimeIntervals[i1] != other.ActiveTimeIntervals[i1] { + return false + } + } + if resource.Continue == nil && other.Continue != nil || resource.Continue != nil && other.Continue == nil { + return false + } + + if resource.Continue != nil { + if *resource.Continue != *other.Continue { + return false + } + } + + if len(resource.GroupBy) != len(other.GroupBy) { + return false + } + + for i1 := range resource.GroupBy { + if resource.GroupBy[i1] != other.GroupBy[i1] { + return false + } + } + if resource.GroupInterval == nil && other.GroupInterval != nil || resource.GroupInterval != nil && other.GroupInterval == nil { + return false + } + + if resource.GroupInterval != nil { + if *resource.GroupInterval != *other.GroupInterval { + return false + } + } + if resource.GroupWait == nil && other.GroupWait != nil || resource.GroupWait != nil && other.GroupWait == nil { + return false + } + + if resource.GroupWait != nil { + if *resource.GroupWait != *other.GroupWait { + return false + } + } + + if len(resource.Match) != len(other.Match) { + return false + } + + for key1 := range resource.Match { + if resource.Match[key1] != other.Match[key1] { + return false + } + } + if resource.MatchRe == nil && other.MatchRe != nil || resource.MatchRe != nil && other.MatchRe == nil { + return false + } + + if resource.MatchRe != nil { + + if len(*resource.MatchRe) != len(*other.MatchRe) { + return false + } + + for key1 := range *resource.MatchRe { + if (*resource.MatchRe)[key1] != (*other.MatchRe)[key1] { + return false + } + } + } + if resource.Matchers == nil && other.Matchers != nil || resource.Matchers != nil && other.Matchers == nil { + return false + } + + if resource.Matchers != nil { + + if len(*resource.Matchers) != len(*other.Matchers) { + return false + } + + for i1 := range *resource.Matchers { + if !(*resource.Matchers)[i1].Equals((*other.Matchers)[i1]) { + return false + } + } + } + + if len(resource.MuteTimeIntervals) != len(other.MuteTimeIntervals) { + return false + } + + for i1 := range resource.MuteTimeIntervals { + if resource.MuteTimeIntervals[i1] != other.MuteTimeIntervals[i1] { + return false + } + } + if resource.ObjectMatchers == nil && other.ObjectMatchers != nil || resource.ObjectMatchers != nil && other.ObjectMatchers == nil { + return false + } + + if resource.ObjectMatchers != nil { + + if len(*resource.ObjectMatchers) != len(*other.ObjectMatchers) { + return false + } + + for i1 := range *resource.ObjectMatchers { + + if len((*resource.ObjectMatchers)[i1]) != len((*other.ObjectMatchers)[i1]) { + return false + } + + for i2 := range (*resource.ObjectMatchers)[i1] { + if (*resource.ObjectMatchers)[i1][i2] != (*other.ObjectMatchers)[i1][i2] { + return false + } + } + } + } + if resource.Provenance == nil && other.Provenance != nil || resource.Provenance != nil && other.Provenance == nil { + return false + } + + if resource.Provenance != nil { + if *resource.Provenance != *other.Provenance { + return false + } + } + if resource.Receiver == nil && other.Receiver != nil || resource.Receiver != nil && other.Receiver == nil { + return false + } + + if resource.Receiver != nil { + if *resource.Receiver != *other.Receiver { + return false + } + } + if resource.RepeatInterval == nil && other.RepeatInterval != nil || resource.RepeatInterval != nil && other.RepeatInterval == nil { + return false + } + + if resource.RepeatInterval != nil { + if *resource.RepeatInterval != *other.RepeatInterval { + return false + } + } + + if len(resource.Routes) != len(other.Routes) { + return false + } + + for i1 := range resource.Routes { + if !resource.Routes[i1].Equals(other.Routes[i1]) { + return false + } + } + + return true +} + type TimeInterval struct { Name *string `json:"name,omitempty"` TimeIntervals []TimeIntervalItem `json:"time_intervals,omitempty"` } +func (resource TimeInterval) Equals(other TimeInterval) bool { + if resource.Name == nil && other.Name != nil || resource.Name != nil && other.Name == nil { + return false + } + + if resource.Name != nil { + if *resource.Name != *other.Name { + return false + } + } + + if len(resource.TimeIntervals) != len(other.TimeIntervals) { + return false + } + + for i1 := range resource.TimeIntervals { + if !resource.TimeIntervals[i1].Equals(other.TimeIntervals[i1]) { + return false + } + } + + return true +} + type TimeIntervalItem struct { DaysOfMonth []string `json:"days_of_month,omitempty"` Location *string `json:"location,omitempty"` @@ -250,11 +885,98 @@ type TimeIntervalItem struct { Years []string `json:"years,omitempty"` } +func (resource TimeIntervalItem) Equals(other TimeIntervalItem) bool { + + if len(resource.DaysOfMonth) != len(other.DaysOfMonth) { + return false + } + + for i1 := range resource.DaysOfMonth { + if resource.DaysOfMonth[i1] != other.DaysOfMonth[i1] { + return false + } + } + if resource.Location == nil && other.Location != nil || resource.Location != nil && other.Location == nil { + return false + } + + if resource.Location != nil { + if *resource.Location != *other.Location { + return false + } + } + + if len(resource.Months) != len(other.Months) { + return false + } + + for i1 := range resource.Months { + if resource.Months[i1] != other.Months[i1] { + return false + } + } + + if len(resource.Times) != len(other.Times) { + return false + } + + for i1 := range resource.Times { + if !resource.Times[i1].Equals(other.Times[i1]) { + return false + } + } + + if len(resource.Weekdays) != len(other.Weekdays) { + return false + } + + for i1 := range resource.Weekdays { + if resource.Weekdays[i1] != other.Weekdays[i1] { + return false + } + } + + if len(resource.Years) != len(other.Years) { + return false + } + + for i1 := range resource.Years { + if resource.Years[i1] != other.Years[i1] { + return false + } + } + + return true +} + type TimeIntervalTimeRange struct { EndTime *string `json:"end_time,omitempty"` StartTime *string `json:"start_time,omitempty"` } +func (resource TimeIntervalTimeRange) Equals(other TimeIntervalTimeRange) bool { + if resource.EndTime == nil && other.EndTime != nil || resource.EndTime != nil && other.EndTime == nil { + return false + } + + if resource.EndTime != nil { + if *resource.EndTime != *other.EndTime { + return false + } + } + if resource.StartTime == nil && other.StartTime != nil || resource.StartTime != nil && other.StartTime == nil { + return false + } + + if resource.StartTime != nil { + if *resource.StartTime != *other.StartTime { + return false + } + } + + return true +} + type ContactPointType string const ( diff --git a/go/annotationslist/types_gen.go b/go/annotationslist/types_gen.go index bb5cb53..1bbdd09 100644 --- a/go/annotationslist/types_gen.go +++ b/go/annotationslist/types_gen.go @@ -21,6 +21,48 @@ type Options struct { NavigateAfter string `json:"navigateAfter"` } +func (resource Options) Equals(other Options) bool { + if resource.OnlyFromThisDashboard != other.OnlyFromThisDashboard { + return false + } + if resource.OnlyInTimeRange != other.OnlyInTimeRange { + return false + } + + if len(resource.Tags) != len(other.Tags) { + return false + } + + for i1 := range resource.Tags { + if resource.Tags[i1] != other.Tags[i1] { + return false + } + } + if resource.Limit != other.Limit { + return false + } + if resource.ShowUser != other.ShowUser { + return false + } + if resource.ShowTime != other.ShowTime { + return false + } + if resource.ShowTags != other.ShowTags { + return false + } + if resource.NavigateToPanel != other.NavigateToPanel { + return false + } + if resource.NavigateBefore != other.NavigateBefore { + return false + } + if resource.NavigateAfter != other.NavigateAfter { + return false + } + + return true +} + func VariantConfig() variants.PanelcfgConfig { return variants.PanelcfgConfig{ Identifier: "annolist", diff --git a/go/azuremonitor/azuremonitorquery_builder_gen.go b/go/azuremonitor/azuremonitorquery_builder_gen.go index 98dfacc..52bf6e8 100644 --- a/go/azuremonitor/azuremonitorquery_builder_gen.go +++ b/go/azuremonitor/azuremonitorquery_builder_gen.go @@ -5,6 +5,7 @@ package azuremonitor import ( cog "github.com/grafana/grafana-foundation-sdk/go/cog" variants "github.com/grafana/grafana-foundation-sdk/go/cog/variants" + dashboard "github.com/grafana/grafana-foundation-sdk/go/dashboard" ) var _ cog.Builder[variants.Dataquery] = (*AzureMonitorQueryBuilder)(nil) @@ -162,7 +163,7 @@ func (builder *AzureMonitorQueryBuilder) Region(region string) *AzureMonitorQuer // For non mixed scenarios this is undefined. // TODO find a better way to do this ^ that's friendly to schema // TODO this shouldn't be unknown but DataSourceRef | null -func (builder *AzureMonitorQueryBuilder) Datasource(datasource any) *AzureMonitorQueryBuilder { +func (builder *AzureMonitorQueryBuilder) Datasource(datasource dashboard.DataSourceRef) *AzureMonitorQueryBuilder { builder.internal.Datasource = &datasource return builder diff --git a/go/azuremonitor/types_gen.go b/go/azuremonitor/types_gen.go index 8de4bf8..3c2dab8 100644 --- a/go/azuremonitor/types_gen.go +++ b/go/azuremonitor/types_gen.go @@ -8,6 +8,7 @@ import ( "fmt" variants "github.com/grafana/grafana-foundation-sdk/go/cog/variants" + dashboard "github.com/grafana/grafana-foundation-sdk/go/dashboard" ) type AzureMonitorQuery struct { @@ -43,7 +44,7 @@ type AzureMonitorQuery struct { // For non mixed scenarios this is undefined. // TODO find a better way to do this ^ that's friendly to schema // TODO this shouldn't be unknown but DataSourceRef | null - Datasource any `json:"datasource,omitempty"` + Datasource *dashboard.DataSourceRef `json:"datasource,omitempty"` // Used only for exemplar queries from Prometheus Query *string `json:"query,omitempty"` } @@ -65,6 +66,158 @@ func VariantConfig() variants.DataqueryConfig { } } +func (resource AzureMonitorQuery) Equals(otherCandidate variants.Dataquery) bool { + if otherCandidate == nil { + return false + } + + other, ok := otherCandidate.(AzureMonitorQuery) + if !ok { + return false + } + if resource.RefId != other.RefId { + return false + } + if resource.Hide == nil && other.Hide != nil || resource.Hide != nil && other.Hide == nil { + return false + } + + if resource.Hide != nil { + if *resource.Hide != *other.Hide { + return false + } + } + if resource.QueryType == nil && other.QueryType != nil || resource.QueryType != nil && other.QueryType == nil { + return false + } + + if resource.QueryType != nil { + if *resource.QueryType != *other.QueryType { + return false + } + } + if resource.Subscription == nil && other.Subscription != nil || resource.Subscription != nil && other.Subscription == nil { + return false + } + + if resource.Subscription != nil { + if *resource.Subscription != *other.Subscription { + return false + } + } + + if len(resource.Subscriptions) != len(other.Subscriptions) { + return false + } + + for i1 := range resource.Subscriptions { + if resource.Subscriptions[i1] != other.Subscriptions[i1] { + return false + } + } + if resource.AzureMonitor == nil && other.AzureMonitor != nil || resource.AzureMonitor != nil && other.AzureMonitor == nil { + return false + } + + if resource.AzureMonitor != nil { + if !resource.AzureMonitor.Equals(*other.AzureMonitor) { + return false + } + } + if resource.AzureLogAnalytics == nil && other.AzureLogAnalytics != nil || resource.AzureLogAnalytics != nil && other.AzureLogAnalytics == nil { + return false + } + + if resource.AzureLogAnalytics != nil { + if !resource.AzureLogAnalytics.Equals(*other.AzureLogAnalytics) { + return false + } + } + if resource.AzureResourceGraph == nil && other.AzureResourceGraph != nil || resource.AzureResourceGraph != nil && other.AzureResourceGraph == nil { + return false + } + + if resource.AzureResourceGraph != nil { + if !resource.AzureResourceGraph.Equals(*other.AzureResourceGraph) { + return false + } + } + if resource.AzureTraces == nil && other.AzureTraces != nil || resource.AzureTraces != nil && other.AzureTraces == nil { + return false + } + + if resource.AzureTraces != nil { + if !resource.AzureTraces.Equals(*other.AzureTraces) { + return false + } + } + if resource.GrafanaTemplateVariableFn == nil && other.GrafanaTemplateVariableFn != nil || resource.GrafanaTemplateVariableFn != nil && other.GrafanaTemplateVariableFn == nil { + return false + } + + if resource.GrafanaTemplateVariableFn != nil { + if !resource.GrafanaTemplateVariableFn.Equals(*other.GrafanaTemplateVariableFn) { + return false + } + } + if resource.ResourceGroup == nil && other.ResourceGroup != nil || resource.ResourceGroup != nil && other.ResourceGroup == nil { + return false + } + + if resource.ResourceGroup != nil { + if *resource.ResourceGroup != *other.ResourceGroup { + return false + } + } + if resource.Namespace == nil && other.Namespace != nil || resource.Namespace != nil && other.Namespace == nil { + return false + } + + if resource.Namespace != nil { + if *resource.Namespace != *other.Namespace { + return false + } + } + if resource.Resource == nil && other.Resource != nil || resource.Resource != nil && other.Resource == nil { + return false + } + + if resource.Resource != nil { + if *resource.Resource != *other.Resource { + return false + } + } + if resource.Region == nil && other.Region != nil || resource.Region != nil && other.Region == nil { + return false + } + + if resource.Region != nil { + if *resource.Region != *other.Region { + return false + } + } + if resource.Datasource == nil && other.Datasource != nil || resource.Datasource != nil && other.Datasource == nil { + return false + } + + if resource.Datasource != nil { + if !resource.Datasource.Equals(*other.Datasource) { + return false + } + } + if resource.Query == nil && other.Query != nil || resource.Query != nil && other.Query == nil { + return false + } + + if resource.Query != nil { + if *resource.Query != *other.Query { + return false + } + } + + return true +} + // Defines the supported queryTypes. GrafanaTemplateVariableFn is deprecated type AzureQueryType string @@ -125,6 +278,176 @@ type AzureMetricQuery struct { ResourceName *string `json:"resourceName,omitempty"` } +func (resource AzureMetricQuery) Equals(other AzureMetricQuery) bool { + + if len(resource.Resources) != len(other.Resources) { + return false + } + + for i1 := range resource.Resources { + if !resource.Resources[i1].Equals(other.Resources[i1]) { + return false + } + } + if resource.MetricNamespace == nil && other.MetricNamespace != nil || resource.MetricNamespace != nil && other.MetricNamespace == nil { + return false + } + + if resource.MetricNamespace != nil { + if *resource.MetricNamespace != *other.MetricNamespace { + return false + } + } + if resource.CustomNamespace == nil && other.CustomNamespace != nil || resource.CustomNamespace != nil && other.CustomNamespace == nil { + return false + } + + if resource.CustomNamespace != nil { + if *resource.CustomNamespace != *other.CustomNamespace { + return false + } + } + if resource.MetricName == nil && other.MetricName != nil || resource.MetricName != nil && other.MetricName == nil { + return false + } + + if resource.MetricName != nil { + if *resource.MetricName != *other.MetricName { + return false + } + } + if resource.Region == nil && other.Region != nil || resource.Region != nil && other.Region == nil { + return false + } + + if resource.Region != nil { + if *resource.Region != *other.Region { + return false + } + } + if resource.TimeGrain == nil && other.TimeGrain != nil || resource.TimeGrain != nil && other.TimeGrain == nil { + return false + } + + if resource.TimeGrain != nil { + if *resource.TimeGrain != *other.TimeGrain { + return false + } + } + if resource.Aggregation == nil && other.Aggregation != nil || resource.Aggregation != nil && other.Aggregation == nil { + return false + } + + if resource.Aggregation != nil { + if *resource.Aggregation != *other.Aggregation { + return false + } + } + + if len(resource.DimensionFilters) != len(other.DimensionFilters) { + return false + } + + for i1 := range resource.DimensionFilters { + if !resource.DimensionFilters[i1].Equals(other.DimensionFilters[i1]) { + return false + } + } + if resource.Top == nil && other.Top != nil || resource.Top != nil && other.Top == nil { + return false + } + + if resource.Top != nil { + if *resource.Top != *other.Top { + return false + } + } + + if len(resource.AllowedTimeGrainsMs) != len(other.AllowedTimeGrainsMs) { + return false + } + + for i1 := range resource.AllowedTimeGrainsMs { + if resource.AllowedTimeGrainsMs[i1] != other.AllowedTimeGrainsMs[i1] { + return false + } + } + if resource.Alias == nil && other.Alias != nil || resource.Alias != nil && other.Alias == nil { + return false + } + + if resource.Alias != nil { + if *resource.Alias != *other.Alias { + return false + } + } + if resource.TimeGrainUnit == nil && other.TimeGrainUnit != nil || resource.TimeGrainUnit != nil && other.TimeGrainUnit == nil { + return false + } + + if resource.TimeGrainUnit != nil { + if *resource.TimeGrainUnit != *other.TimeGrainUnit { + return false + } + } + if resource.Dimension == nil && other.Dimension != nil || resource.Dimension != nil && other.Dimension == nil { + return false + } + + if resource.Dimension != nil { + if *resource.Dimension != *other.Dimension { + return false + } + } + if resource.DimensionFilter == nil && other.DimensionFilter != nil || resource.DimensionFilter != nil && other.DimensionFilter == nil { + return false + } + + if resource.DimensionFilter != nil { + if *resource.DimensionFilter != *other.DimensionFilter { + return false + } + } + if resource.MetricDefinition == nil && other.MetricDefinition != nil || resource.MetricDefinition != nil && other.MetricDefinition == nil { + return false + } + + if resource.MetricDefinition != nil { + if *resource.MetricDefinition != *other.MetricDefinition { + return false + } + } + if resource.ResourceUri == nil && other.ResourceUri != nil || resource.ResourceUri != nil && other.ResourceUri == nil { + return false + } + + if resource.ResourceUri != nil { + if *resource.ResourceUri != *other.ResourceUri { + return false + } + } + if resource.ResourceGroup == nil && other.ResourceGroup != nil || resource.ResourceGroup != nil && other.ResourceGroup == nil { + return false + } + + if resource.ResourceGroup != nil { + if *resource.ResourceGroup != *other.ResourceGroup { + return false + } + } + if resource.ResourceName == nil && other.ResourceName != nil || resource.ResourceName != nil && other.ResourceName == nil { + return false + } + + if resource.ResourceName != nil { + if *resource.ResourceName != *other.ResourceName { + return false + } + } + + return true +} + // Azure Monitor Logs sub-query properties type AzureLogsQuery struct { // KQL query to be executed. @@ -147,6 +470,93 @@ type AzureLogsQuery struct { IntersectTime *bool `json:"intersectTime,omitempty"` } +func (resource AzureLogsQuery) Equals(other AzureLogsQuery) bool { + if resource.Query == nil && other.Query != nil || resource.Query != nil && other.Query == nil { + return false + } + + if resource.Query != nil { + if *resource.Query != *other.Query { + return false + } + } + if resource.ResultFormat == nil && other.ResultFormat != nil || resource.ResultFormat != nil && other.ResultFormat == nil { + return false + } + + if resource.ResultFormat != nil { + if *resource.ResultFormat != *other.ResultFormat { + return false + } + } + + if len(resource.Resources) != len(other.Resources) { + return false + } + + for i1 := range resource.Resources { + if resource.Resources[i1] != other.Resources[i1] { + return false + } + } + if resource.DashboardTime == nil && other.DashboardTime != nil || resource.DashboardTime != nil && other.DashboardTime == nil { + return false + } + + if resource.DashboardTime != nil { + if *resource.DashboardTime != *other.DashboardTime { + return false + } + } + if resource.TimeColumn == nil && other.TimeColumn != nil || resource.TimeColumn != nil && other.TimeColumn == nil { + return false + } + + if resource.TimeColumn != nil { + if *resource.TimeColumn != *other.TimeColumn { + return false + } + } + if resource.BasicLogsQuery == nil && other.BasicLogsQuery != nil || resource.BasicLogsQuery != nil && other.BasicLogsQuery == nil { + return false + } + + if resource.BasicLogsQuery != nil { + if *resource.BasicLogsQuery != *other.BasicLogsQuery { + return false + } + } + if resource.Workspace == nil && other.Workspace != nil || resource.Workspace != nil && other.Workspace == nil { + return false + } + + if resource.Workspace != nil { + if *resource.Workspace != *other.Workspace { + return false + } + } + if resource.Resource == nil && other.Resource != nil || resource.Resource != nil && other.Resource == nil { + return false + } + + if resource.Resource != nil { + if *resource.Resource != *other.Resource { + return false + } + } + if resource.IntersectTime == nil && other.IntersectTime != nil || resource.IntersectTime != nil && other.IntersectTime == nil { + return false + } + + if resource.IntersectTime != nil { + if *resource.IntersectTime != *other.IntersectTime { + return false + } + } + + return true +} + // Application Insights Traces sub-query properties type AzureTracesQuery struct { // Specifies the format results should be returned as. @@ -163,6 +573,68 @@ type AzureTracesQuery struct { Query *string `json:"query,omitempty"` } +func (resource AzureTracesQuery) Equals(other AzureTracesQuery) bool { + if resource.ResultFormat == nil && other.ResultFormat != nil || resource.ResultFormat != nil && other.ResultFormat == nil { + return false + } + + if resource.ResultFormat != nil { + if *resource.ResultFormat != *other.ResultFormat { + return false + } + } + + if len(resource.Resources) != len(other.Resources) { + return false + } + + for i1 := range resource.Resources { + if resource.Resources[i1] != other.Resources[i1] { + return false + } + } + if resource.OperationId == nil && other.OperationId != nil || resource.OperationId != nil && other.OperationId == nil { + return false + } + + if resource.OperationId != nil { + if *resource.OperationId != *other.OperationId { + return false + } + } + + if len(resource.TraceTypes) != len(other.TraceTypes) { + return false + } + + for i1 := range resource.TraceTypes { + if resource.TraceTypes[i1] != other.TraceTypes[i1] { + return false + } + } + + if len(resource.Filters) != len(other.Filters) { + return false + } + + for i1 := range resource.Filters { + if !resource.Filters[i1].Equals(other.Filters[i1]) { + return false + } + } + if resource.Query == nil && other.Query != nil || resource.Query != nil && other.Query == nil { + return false + } + + if resource.Query != nil { + if *resource.Query != *other.Query { + return false + } + } + + return true +} + type AzureTracesFilter struct { // Property name, auto-populated based on available traces. Property string `json:"property"` @@ -172,6 +644,27 @@ type AzureTracesFilter struct { Filters []string `json:"filters"` } +func (resource AzureTracesFilter) Equals(other AzureTracesFilter) bool { + if resource.Property != other.Property { + return false + } + if resource.Operation != other.Operation { + return false + } + + if len(resource.Filters) != len(other.Filters) { + return false + } + + for i1 := range resource.Filters { + if resource.Filters[i1] != other.Filters[i1] { + return false + } + } + + return true +} + type ResultFormat string const ( @@ -188,6 +681,29 @@ type AzureResourceGraphQuery struct { ResultFormat *string `json:"resultFormat,omitempty"` } +func (resource AzureResourceGraphQuery) Equals(other AzureResourceGraphQuery) bool { + if resource.Query == nil && other.Query != nil || resource.Query != nil && other.Query == nil { + return false + } + + if resource.Query != nil { + if *resource.Query != *other.Query { + return false + } + } + if resource.ResultFormat == nil && other.ResultFormat != nil || resource.ResultFormat != nil && other.ResultFormat == nil { + return false + } + + if resource.ResultFormat != nil { + if *resource.ResultFormat != *other.ResultFormat { + return false + } + } + + return true +} + type AzureMonitorResource struct { Subscription *string `json:"subscription,omitempty"` ResourceGroup *string `json:"resourceGroup,omitempty"` @@ -196,6 +712,56 @@ type AzureMonitorResource struct { Region *string `json:"region,omitempty"` } +func (resource AzureMonitorResource) Equals(other AzureMonitorResource) bool { + if resource.Subscription == nil && other.Subscription != nil || resource.Subscription != nil && other.Subscription == nil { + return false + } + + if resource.Subscription != nil { + if *resource.Subscription != *other.Subscription { + return false + } + } + if resource.ResourceGroup == nil && other.ResourceGroup != nil || resource.ResourceGroup != nil && other.ResourceGroup == nil { + return false + } + + if resource.ResourceGroup != nil { + if *resource.ResourceGroup != *other.ResourceGroup { + return false + } + } + if resource.ResourceName == nil && other.ResourceName != nil || resource.ResourceName != nil && other.ResourceName == nil { + return false + } + + if resource.ResourceName != nil { + if *resource.ResourceName != *other.ResourceName { + return false + } + } + if resource.MetricNamespace == nil && other.MetricNamespace != nil || resource.MetricNamespace != nil && other.MetricNamespace == nil { + return false + } + + if resource.MetricNamespace != nil { + if *resource.MetricNamespace != *other.MetricNamespace { + return false + } + } + if resource.Region == nil && other.Region != nil || resource.Region != nil && other.Region == nil { + return false + } + + if resource.Region != nil { + if *resource.Region != *other.Region { + return false + } + } + + return true +} + type AzureMetricDimension struct { // Name of Dimension to be filtered on. Dimension *string `json:"dimension,omitempty"` @@ -207,6 +773,48 @@ type AzureMetricDimension struct { Filter *string `json:"filter,omitempty"` } +func (resource AzureMetricDimension) Equals(other AzureMetricDimension) bool { + if resource.Dimension == nil && other.Dimension != nil || resource.Dimension != nil && other.Dimension == nil { + return false + } + + if resource.Dimension != nil { + if *resource.Dimension != *other.Dimension { + return false + } + } + if resource.Operator == nil && other.Operator != nil || resource.Operator != nil && other.Operator == nil { + return false + } + + if resource.Operator != nil { + if *resource.Operator != *other.Operator { + return false + } + } + + if len(resource.Filters) != len(other.Filters) { + return false + } + + for i1 := range resource.Filters { + if resource.Filters[i1] != other.Filters[i1] { + return false + } + } + if resource.Filter == nil && other.Filter != nil || resource.Filter != nil && other.Filter == nil { + return false + } + + if resource.Filter != nil { + if *resource.Filter != *other.Filter { + return false + } + } + + return true +} + type GrafanaTemplateVariableQueryType string const ( @@ -225,33 +833,138 @@ type BaseGrafanaTemplateVariableQuery struct { RawQuery *string `json:"rawQuery,omitempty"` } +func (resource BaseGrafanaTemplateVariableQuery) Equals(other BaseGrafanaTemplateVariableQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + + return true +} + type UnknownQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` } +func (resource UnknownQuery) Equals(other UnknownQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + + return true +} + type AppInsightsMetricNameQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` } +func (resource AppInsightsMetricNameQuery) Equals(other AppInsightsMetricNameQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + + return true +} + type AppInsightsGroupByQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` MetricName string `json:"metricName"` } +func (resource AppInsightsGroupByQuery) Equals(other AppInsightsGroupByQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + if resource.MetricName != other.MetricName { + return false + } + + return true +} + type SubscriptionsQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` } +func (resource SubscriptionsQuery) Equals(other SubscriptionsQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + + return true +} + type ResourceGroupsQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` Subscription string `json:"subscription"` } +func (resource ResourceGroupsQuery) Equals(other ResourceGroupsQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + if resource.Subscription != other.Subscription { + return false + } + + return true +} + type ResourceNamesQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` @@ -260,6 +973,32 @@ type ResourceNamesQuery struct { MetricNamespace string `json:"metricNamespace"` } +func (resource ResourceNamesQuery) Equals(other ResourceNamesQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + if resource.Subscription != other.Subscription { + return false + } + if resource.ResourceGroup != other.ResourceGroup { + return false + } + if resource.MetricNamespace != other.MetricNamespace { + return false + } + + return true +} + type MetricNamespaceQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` @@ -269,6 +1008,47 @@ type MetricNamespaceQuery struct { ResourceName *string `json:"resourceName,omitempty"` } +func (resource MetricNamespaceQuery) Equals(other MetricNamespaceQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + if resource.Subscription != other.Subscription { + return false + } + if resource.ResourceGroup != other.ResourceGroup { + return false + } + if resource.MetricNamespace == nil && other.MetricNamespace != nil || resource.MetricNamespace != nil && other.MetricNamespace == nil { + return false + } + + if resource.MetricNamespace != nil { + if *resource.MetricNamespace != *other.MetricNamespace { + return false + } + } + if resource.ResourceName == nil && other.ResourceName != nil || resource.ResourceName != nil && other.ResourceName == nil { + return false + } + + if resource.ResourceName != nil { + if *resource.ResourceName != *other.ResourceName { + return false + } + } + + return true +} + // @deprecated Use MetricNamespaceQuery instead type MetricDefinitionsQuery struct { RawQuery *string `json:"rawQuery,omitempty"` @@ -279,6 +1059,47 @@ type MetricDefinitionsQuery struct { ResourceName *string `json:"resourceName,omitempty"` } +func (resource MetricDefinitionsQuery) Equals(other MetricDefinitionsQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + if resource.Subscription != other.Subscription { + return false + } + if resource.ResourceGroup != other.ResourceGroup { + return false + } + if resource.MetricNamespace == nil && other.MetricNamespace != nil || resource.MetricNamespace != nil && other.MetricNamespace == nil { + return false + } + + if resource.MetricNamespace != nil { + if *resource.MetricNamespace != *other.MetricNamespace { + return false + } + } + if resource.ResourceName == nil && other.ResourceName != nil || resource.ResourceName != nil && other.ResourceName == nil { + return false + } + + if resource.ResourceName != nil { + if *resource.ResourceName != *other.ResourceName { + return false + } + } + + return true +} + type MetricNamesQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` @@ -288,12 +1109,61 @@ type MetricNamesQuery struct { MetricNamespace string `json:"metricNamespace"` } +func (resource MetricNamesQuery) Equals(other MetricNamesQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + if resource.Subscription != other.Subscription { + return false + } + if resource.ResourceGroup != other.ResourceGroup { + return false + } + if resource.ResourceName != other.ResourceName { + return false + } + if resource.MetricNamespace != other.MetricNamespace { + return false + } + + return true +} + type WorkspacesQuery struct { RawQuery *string `json:"rawQuery,omitempty"` Kind string `json:"kind"` Subscription string `json:"subscription"` } +func (resource WorkspacesQuery) Equals(other WorkspacesQuery) bool { + if resource.RawQuery == nil && other.RawQuery != nil || resource.RawQuery != nil && other.RawQuery == nil { + return false + } + + if resource.RawQuery != nil { + if *resource.RawQuery != *other.RawQuery { + return false + } + } + if resource.Kind != other.Kind { + return false + } + if resource.Subscription != other.Subscription { + return false + } + + return true +} + type GrafanaTemplateVariableQuery = AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery type AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery struct { @@ -445,3 +1315,98 @@ func (resource *AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptio return fmt.Errorf("could not unmarshal resource with `kind = %v`", discriminator) } + +func (resource AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery) Equals(other AppInsightsMetricNameQueryOrAppInsightsGroupByQueryOrSubscriptionsQueryOrResourceGroupsQueryOrResourceNamesQueryOrMetricNamespaceQueryOrMetricDefinitionsQueryOrMetricNamesQueryOrWorkspacesQueryOrUnknownQuery) bool { + if resource.AppInsightsMetricNameQuery == nil && other.AppInsightsMetricNameQuery != nil || resource.AppInsightsMetricNameQuery != nil && other.AppInsightsMetricNameQuery == nil { + return false + } + + if resource.AppInsightsMetricNameQuery != nil { + if !resource.AppInsightsMetricNameQuery.Equals(*other.AppInsightsMetricNameQuery) { + return false + } + } + if resource.AppInsightsGroupByQuery == nil && other.AppInsightsGroupByQuery != nil || resource.AppInsightsGroupByQuery != nil && other.AppInsightsGroupByQuery == nil { + return false + } + + if resource.AppInsightsGroupByQuery != nil { + if !resource.AppInsightsGroupByQuery.Equals(*other.AppInsightsGroupByQuery) { + return false + } + } + if resource.SubscriptionsQuery == nil && other.SubscriptionsQuery != nil || resource.SubscriptionsQuery != nil && other.SubscriptionsQuery == nil { + return false + } + + if resource.SubscriptionsQuery != nil { + if !resource.SubscriptionsQuery.Equals(*other.SubscriptionsQuery) { + return false + } + } + if resource.ResourceGroupsQuery == nil && other.ResourceGroupsQuery != nil || resource.ResourceGroupsQuery != nil && other.ResourceGroupsQuery == nil { + return false + } + + if resource.ResourceGroupsQuery != nil { + if !resource.ResourceGroupsQuery.Equals(*other.ResourceGroupsQuery) { + return false + } + } + if resource.ResourceNamesQuery == nil && other.ResourceNamesQuery != nil || resource.ResourceNamesQuery != nil && other.ResourceNamesQuery == nil { + return false + } + + if resource.ResourceNamesQuery != nil { + if !resource.ResourceNamesQuery.Equals(*other.ResourceNamesQuery) { + return false + } + } + if resource.MetricNamespaceQuery == nil && other.MetricNamespaceQuery != nil || resource.MetricNamespaceQuery != nil && other.MetricNamespaceQuery == nil { + return false + } + + if resource.MetricNamespaceQuery != nil { + if !resource.MetricNamespaceQuery.Equals(*other.MetricNamespaceQuery) { + return false + } + } + if resource.MetricDefinitionsQuery == nil && other.MetricDefinitionsQuery != nil || resource.MetricDefinitionsQuery != nil && other.MetricDefinitionsQuery == nil { + return false + } + + if resource.MetricDefinitionsQuery != nil { + if !resource.MetricDefinitionsQuery.Equals(*other.MetricDefinitionsQuery) { + return false + } + } + if resource.MetricNamesQuery == nil && other.MetricNamesQuery != nil || resource.MetricNamesQuery != nil && other.MetricNamesQuery == nil { + return false + } + + if resource.MetricNamesQuery != nil { + if !resource.MetricNamesQuery.Equals(*other.MetricNamesQuery) { + return false + } + } + if resource.WorkspacesQuery == nil && other.WorkspacesQuery != nil || resource.WorkspacesQuery != nil && other.WorkspacesQuery == nil { + return false + } + + if resource.WorkspacesQuery != nil { + if !resource.WorkspacesQuery.Equals(*other.WorkspacesQuery) { + return false + } + } + if resource.UnknownQuery == nil && other.UnknownQuery != nil || resource.UnknownQuery != nil && other.UnknownQuery == nil { + return false + } + + if resource.UnknownQuery != nil { + if !resource.UnknownQuery.Equals(*other.UnknownQuery) { + return false + } + } + + return true +} diff --git a/go/barchart/types_gen.go b/go/barchart/types_gen.go index 02315f2..277d0cb 100644 --- a/go/barchart/types_gen.go +++ b/go/barchart/types_gen.go @@ -41,6 +41,86 @@ type Options struct { FullHighlight bool `json:"fullHighlight"` } +func (resource Options) Equals(other Options) bool { + if resource.XField == nil && other.XField != nil || resource.XField != nil && other.XField == nil { + return false + } + + if resource.XField != nil { + if *resource.XField != *other.XField { + return false + } + } + if resource.ColorByField == nil && other.ColorByField != nil || resource.ColorByField != nil && other.ColorByField == nil { + return false + } + + if resource.ColorByField != nil { + if *resource.ColorByField != *other.ColorByField { + return false + } + } + if resource.Orientation != other.Orientation { + return false + } + if resource.BarRadius == nil && other.BarRadius != nil || resource.BarRadius != nil && other.BarRadius == nil { + return false + } + + if resource.BarRadius != nil { + if *resource.BarRadius != *other.BarRadius { + return false + } + } + if resource.XTickLabelRotation != other.XTickLabelRotation { + return false + } + if resource.XTickLabelMaxLength != other.XTickLabelMaxLength { + return false + } + if resource.XTickLabelSpacing == nil && other.XTickLabelSpacing != nil || resource.XTickLabelSpacing != nil && other.XTickLabelSpacing == nil { + return false + } + + if resource.XTickLabelSpacing != nil { + if *resource.XTickLabelSpacing != *other.XTickLabelSpacing { + return false + } + } + if resource.Stacking != other.Stacking { + return false + } + if resource.ShowValue != other.ShowValue { + return false + } + if resource.BarWidth != other.BarWidth { + return false + } + if resource.GroupWidth != other.GroupWidth { + return false + } + if !resource.Legend.Equals(other.Legend) { + return false + } + if !resource.Tooltip.Equals(other.Tooltip) { + return false + } + if resource.Text == nil && other.Text != nil || resource.Text != nil && other.Text == nil { + return false + } + + if resource.Text != nil { + if !resource.Text.Equals(*other.Text) { + return false + } + } + if resource.FullHighlight != other.FullHighlight { + return false + } + + return true +} + type FieldConfig struct { // Controls line width of the bars. LineWidth *int32 `json:"lineWidth,omitempty"` @@ -64,6 +144,146 @@ type FieldConfig struct { AxisBorderShow *bool `json:"axisBorderShow,omitempty"` } +func (resource FieldConfig) Equals(other FieldConfig) bool { + if resource.LineWidth == nil && other.LineWidth != nil || resource.LineWidth != nil && other.LineWidth == nil { + return false + } + + if resource.LineWidth != nil { + if *resource.LineWidth != *other.LineWidth { + return false + } + } + if resource.FillOpacity == nil && other.FillOpacity != nil || resource.FillOpacity != nil && other.FillOpacity == nil { + return false + } + + if resource.FillOpacity != nil { + if *resource.FillOpacity != *other.FillOpacity { + return false + } + } + if resource.GradientMode == nil && other.GradientMode != nil || resource.GradientMode != nil && other.GradientMode == nil { + return false + } + + if resource.GradientMode != nil { + if *resource.GradientMode != *other.GradientMode { + return false + } + } + if resource.AxisPlacement == nil && other.AxisPlacement != nil || resource.AxisPlacement != nil && other.AxisPlacement == nil { + return false + } + + if resource.AxisPlacement != nil { + if *resource.AxisPlacement != *other.AxisPlacement { + return false + } + } + if resource.AxisColorMode == nil && other.AxisColorMode != nil || resource.AxisColorMode != nil && other.AxisColorMode == nil { + return false + } + + if resource.AxisColorMode != nil { + if *resource.AxisColorMode != *other.AxisColorMode { + return false + } + } + if resource.AxisLabel == nil && other.AxisLabel != nil || resource.AxisLabel != nil && other.AxisLabel == nil { + return false + } + + if resource.AxisLabel != nil { + if *resource.AxisLabel != *other.AxisLabel { + return false + } + } + if resource.AxisWidth == nil && other.AxisWidth != nil || resource.AxisWidth != nil && other.AxisWidth == nil { + return false + } + + if resource.AxisWidth != nil { + if *resource.AxisWidth != *other.AxisWidth { + return false + } + } + if resource.AxisSoftMin == nil && other.AxisSoftMin != nil || resource.AxisSoftMin != nil && other.AxisSoftMin == nil { + return false + } + + if resource.AxisSoftMin != nil { + if *resource.AxisSoftMin != *other.AxisSoftMin { + return false + } + } + if resource.AxisSoftMax == nil && other.AxisSoftMax != nil || resource.AxisSoftMax != nil && other.AxisSoftMax == nil { + return false + } + + if resource.AxisSoftMax != nil { + if *resource.AxisSoftMax != *other.AxisSoftMax { + return false + } + } + if resource.AxisGridShow == nil && other.AxisGridShow != nil || resource.AxisGridShow != nil && other.AxisGridShow == nil { + return false + } + + if resource.AxisGridShow != nil { + if *resource.AxisGridShow != *other.AxisGridShow { + return false + } + } + if resource.ScaleDistribution == nil && other.ScaleDistribution != nil || resource.ScaleDistribution != nil && other.ScaleDistribution == nil { + return false + } + + if resource.ScaleDistribution != nil { + if !resource.ScaleDistribution.Equals(*other.ScaleDistribution) { + return false + } + } + if resource.AxisCenteredZero == nil && other.AxisCenteredZero != nil || resource.AxisCenteredZero != nil && other.AxisCenteredZero == nil { + return false + } + + if resource.AxisCenteredZero != nil { + if *resource.AxisCenteredZero != *other.AxisCenteredZero { + return false + } + } + if resource.HideFrom == nil && other.HideFrom != nil || resource.HideFrom != nil && other.HideFrom == nil { + return false + } + + if resource.HideFrom != nil { + if !resource.HideFrom.Equals(*other.HideFrom) { + return false + } + } + if resource.ThresholdsStyle == nil && other.ThresholdsStyle != nil || resource.ThresholdsStyle != nil && other.ThresholdsStyle == nil { + return false + } + + if resource.ThresholdsStyle != nil { + if !resource.ThresholdsStyle.Equals(*other.ThresholdsStyle) { + return false + } + } + if resource.AxisBorderShow == nil && other.AxisBorderShow != nil || resource.AxisBorderShow != nil && other.AxisBorderShow == nil { + return false + } + + if resource.AxisBorderShow != nil { + if *resource.AxisBorderShow != *other.AxisBorderShow { + return false + } + } + + return true +} + func VariantConfig() variants.PanelcfgConfig { return variants.PanelcfgConfig{ Identifier: "barchart", diff --git a/go/bargauge/types_gen.go b/go/bargauge/types_gen.go index 4dfcd63..e795714 100644 --- a/go/bargauge/types_gen.go +++ b/go/bargauge/types_gen.go @@ -24,6 +24,53 @@ type Options struct { Orientation common.VizOrientation `json:"orientation"` } +func (resource Options) Equals(other Options) bool { + if resource.DisplayMode != other.DisplayMode { + return false + } + if resource.ValueMode != other.ValueMode { + return false + } + if resource.NamePlacement != other.NamePlacement { + return false + } + if resource.ShowUnfilled != other.ShowUnfilled { + return false + } + if resource.Sizing != other.Sizing { + return false + } + if resource.MinVizWidth != other.MinVizWidth { + return false + } + if resource.MinVizHeight != other.MinVizHeight { + return false + } + if !resource.Legend.Equals(other.Legend) { + return false + } + if !resource.ReduceOptions.Equals(other.ReduceOptions) { + return false + } + if resource.Text == nil && other.Text != nil || resource.Text != nil && other.Text == nil { + return false + } + + if resource.Text != nil { + if !resource.Text.Equals(*other.Text) { + return false + } + } + if resource.MaxVizHeight != other.MaxVizHeight { + return false + } + if resource.Orientation != other.Orientation { + return false + } + + return true +} + func VariantConfig() variants.PanelcfgConfig { return variants.PanelcfgConfig{ Identifier: "bargauge", diff --git a/go/candlestick/types_gen.go b/go/candlestick/types_gen.go index de5c9a0..de5d42b 100644 --- a/go/candlestick/types_gen.go +++ b/go/candlestick/types_gen.go @@ -44,12 +44,76 @@ type CandlestickFieldMap struct { Volume *string `json:"volume,omitempty"` } +func (resource CandlestickFieldMap) Equals(other CandlestickFieldMap) bool { + if resource.Open == nil && other.Open != nil || resource.Open != nil && other.Open == nil { + return false + } + + if resource.Open != nil { + if *resource.Open != *other.Open { + return false + } + } + if resource.High == nil && other.High != nil || resource.High != nil && other.High == nil { + return false + } + + if resource.High != nil { + if *resource.High != *other.High { + return false + } + } + if resource.Low == nil && other.Low != nil || resource.Low != nil && other.Low == nil { + return false + } + + if resource.Low != nil { + if *resource.Low != *other.Low { + return false + } + } + if resource.Close == nil && other.Close != nil || resource.Close != nil && other.Close == nil { + return false + } + + if resource.Close != ni...*[Comment body truncated]*