Skip to content

Commit

Permalink
OB-37347: Update terraform API to handle acceleration disabled source (
Browse files Browse the repository at this point in the history
  • Loading branch information
obs-gh-waltercai authored Nov 1, 2024
1 parent 33aab61 commit 4a5bb52
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 21 deletions.
3 changes: 3 additions & 0 deletions client/internal/meta/operation/dataset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ fragment Dataset on Dataset {
description
iconUrl
accelerationDisabled
accelerationDisabledSource
version
updatedDate
pathCost
Expand Down Expand Up @@ -78,6 +79,7 @@ fragment DatasetIdName on Dataset {

# @genqlient(for: "DatasetInput.deleted", omitempty: true)
# @genqlient(for: "DatasetInput.accelerationDisabled", omitempty: true)
# @genqlient(for: "DatasetInput.accelerationDisabledSource", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageID", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.stageID", omitempty: true)
Expand Down Expand Up @@ -147,6 +149,7 @@ query listDatasetsIdNameOnly {
# @genqlient(for: "DatasetFieldTypeInput.nullable", omitempty: true)
# @genqlient(for: "DatasetInput.deleted", omitempty: true)
# @genqlient(for: "DatasetInput.accelerationDisabled", omitempty: true)
# @genqlient(for: "DatasetInput.accelerationDisabledSource", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageID", omitempty: true)
# @genqlient(for: "InputDefinitionInput.stageId", omitempty: true)
# @genqlient(for: "StageQueryInput.stageID", omitempty: true)
Expand Down
18 changes: 18 additions & 0 deletions client/internal/meta/schema/dataset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ type DatasetInputDataset @goModel(model: "observe/meta/metatypes.DatasetInputDat
inputRole: InputRole!,
}

enum AccelerationDisabledSource @goModel(model:"observe/meta/metatypes.DatasetMaterializationDisabledSource") {
Empty
Monitor
View
}

type Dataset implements WorkspaceObject & FolderObject & AuditedObject & AccelerableObject @goModel(model: "observe/meta/metatypes.Dataset") {
id: ObjectId!
version: Time!
Expand Down Expand Up @@ -379,6 +385,7 @@ type Dataset implements WorkspaceObject & FolderObject & AuditedObject & Acceler
accelerable: Boolean!
accelerationInfo: AccelerationInfo! @goField(forceResolver:true)
accelerationDisabled: Boolean! @goField(name:materializationDisabled)
accelerationDisabledSource: AccelerationDisabledSource! @goField(name:materializationDisabledSource)

"""
If the dataset is not hibernated, this field will be set to null.
Expand Down Expand Up @@ -591,7 +598,18 @@ input DatasetInput @goModel(model: "observe/meta/metatypes.DatasetInput") {
"""
overwriteSource: Boolean
deleted: Boolean
"""
Specifies if dataset acceleration should be disabled. Set to true if
dataset materialization is not desired. Defaults to false.
"""
accelerationDisabled: Boolean @goField(name:materializationDisabled)
"""
Optional reason given for why a dataset is not accelerated. For example,
when creating a dataset view, user must set accelerationDisabled to true
and set accelerationDisabledSource to 'View'. Options include: 'Empty',
'Monitor', and 'View'. Defaults to 'Empty'.
"""
accelerationDisabledSource: AccelerationDisabledSource @goField(name:materializationDisabledSource)
latencyDesired: Int64
freshnessDesired: Int64
iconUrl: String
Expand Down
73 changes: 52 additions & 21 deletions client/meta/genqlient.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions client/meta/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ var AllMonitorV2HttpTypes = []MonitorV2HttpType{
MonitorV2HttpTypePut,
}

var AllAccelerationDisabledSource = []AccelerationDisabledSource{
AccelerationDisabledSourceEmpty,
AccelerationDisabledSourceMonitor,
AccelerationDisabledSourceView,
}

const (
ErrNotFound = "NOT_FOUND"
)
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ One of `name` or `id` must be set. If `name` is provided, `workspace` must be se
### Read-Only

- `acceleration_disabled` (Boolean)
- `acceleration_disabled_source` (String)
- `correlation_tag` (Block List) Correlation tags associated with this dataset. (see [below for nested schema](#nestedblock--correlation_tag))
- `data_table_view_state` (String) JSON representation of state used for dataset formatting in the UI
- `description` (String) Dataset description.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ its predecessor. (see [below for nested schema](#nestedblock--stage))
### Optional

- `acceleration_disabled` (Boolean) Disables periodic materialization of the dataset
- `acceleration_disabled_source` (String) Source of disabled materialization
- `data_table_view_state` (String) JSON representation of state used for dataset formatting in the UI
- `description` (String) Dataset description.
- `freshness` (String) Target freshness for results. Tighten the freshness to increase the
Expand Down
4 changes: 4 additions & 0 deletions observe/data_source_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func dataSourceDataset() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"acceleration_disabled_source": {
Type: schema.TypeString,
Computed: true,
},
"path_cost": {
Type: schema.TypeInt,
Computed: true,
Expand Down
2 changes: 2 additions & 0 deletions observe/descriptions/dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ schema:
The maximum on-demand materialization length for the dataset.
acceleration_disabled: |
Disables periodic materialization of the dataset
acceleration_disabled_source: |
Source of disabled materialization
data_table_view_state: |
JSON representation of state used for dataset formatting in the UI
correlation_tag:
Expand Down
15 changes: 15 additions & 0 deletions observe/resource_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ func resourceDataset() *schema.Resource {
Default: false,
Description: descriptions.Get("dataset", "schema", "acceleration_disabled"),
},
"acceleration_disabled_source": {
Type: schema.TypeString,
Optional: true,
ValidateDiagFunc: validateEnums(gql.AllAccelerationDisabledSource),
Description: descriptions.Get("dataset", "schema", "acceleration_disabled_source"),
},
"inputs": {
Type: schema.TypeMap,
Required: true,
Expand Down Expand Up @@ -192,6 +198,11 @@ func newDatasetConfig(data *schema.ResourceData) (*gql.DatasetInput, *gql.MultiS
b := data.Get("acceleration_disabled").(bool)
input.AccelerationDisabled = &b

if v, ok := data.GetOk("acceleration_disabled_source"); ok {
c := gql.AccelerationDisabledSource(toCamel(v.(string)))
input.AccelerationDisabledSource = &c
}

if v, ok := data.GetOk("path_cost"); ok {
input.PathCost = types.Int64Scalar(v.(int)).Ptr()
} else {
Expand Down Expand Up @@ -243,6 +254,10 @@ func datasetToResourceData(d *gql.Dataset, data *schema.ResourceData) (diags dia
diags = append(diags, diag.FromErr(err)...)
}

if err := data.Set("acceleration_disabled_source", toSnake(string(d.AccelerationDisabledSource))); err != nil {
diags = append(diags, diag.FromErr(err)...)
}

var currentCost int
if v, ok := data.GetOk("path_cost"); ok {
currentCost = v.(int)
Expand Down
3 changes: 3 additions & 0 deletions observe/resource_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func TestAccObserveDatasetUpdate(t *testing.T) {
resource.TestCheckResourceAttr("observe_dataset.first", "stage.0.input", ""),
resource.TestCheckResourceAttr("observe_dataset.first", "stage.0.pipeline", ""),
resource.TestCheckResourceAttr("observe_dataset.first", "acceleration_disabled", "false"),
resource.TestCheckResourceAttr("observe_dataset.first", "acceleration_disabled_source", ""),
),
},
{
Expand All @@ -125,6 +126,7 @@ func TestAccObserveDatasetUpdate(t *testing.T) {
}
acceleration_disabled = true
acceleration_disabled_source = "view"
data_table_view_state = jsonencode({viewType = "Auto"})
stage {
Expand All @@ -143,6 +145,7 @@ func TestAccObserveDatasetUpdate(t *testing.T) {
resource.TestCheckResourceAttr("observe_dataset.first", "stage.0.input", ""),
resource.TestCheckResourceAttr("observe_dataset.first", "acceleration_disabled", "true"),
resource.TestCheckResourceAttr("observe_dataset.first", "data_table_view_state", "{\"viewType\":\"Auto\"}"),
resource.TestCheckResourceAttr("observe_dataset.first", "acceleration_disabled_source", "view"),
),
},
{
Expand Down

0 comments on commit 4a5bb52

Please sign in to comment.