Skip to content

Commit

Permalink
Remove scale factor for auction/counter (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyiliev authored Mar 18, 2024
1 parent 8e17ed2 commit b118152
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 35 deletions.
9 changes: 4 additions & 5 deletions docs/resources/source_load_generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ resource "materialize_source_load_generator" "example_source_load_generator" {
counter_options {
tick_interval = "500ms"
scale_factor = 0.01
}
}
# CREATE SOURCE schema.source_load_generator
# FROM LOAD GENERATOR COUNTER
# (TICK INTERVAL '500ms' SCALE FACTOR 0.01);
# (TICK INTERVAL '500ms');
```

<!-- schema generated by tfplugindocs -->
Expand Down Expand Up @@ -65,7 +64,7 @@ resource "materialize_source_load_generator" "example_source_load_generator" {

Optional:

- `scale_factor` (Number) The scale factor for the generator. Defaults to 0.01 (~ 10MB).
- `scale_factor` (Number, Deprecated) (Deprecated) The scale factor for the generator. Defaults to 0.01 (~ 10MB).
- `tick_interval` (String) The interval at which the next datum should be emitted. Defaults to one second.


Expand All @@ -75,7 +74,7 @@ Optional:
Optional:

- `max_cardinality` (Number) Causes the generator to delete old values to keep the collection at most a given size. Defaults to unlimited.
- `scale_factor` (Number) The scale factor for the generator. Defaults to 0.01 (~ 10MB).
- `scale_factor` (Number, Deprecated) (Deprecated) The scale factor for the generator. Defaults to 0.01 (~ 10MB).
- `tick_interval` (String) The interval at which the next datum should be emitted. Defaults to one second.


Expand All @@ -97,7 +96,7 @@ Optional:

Optional:

- `scale_factor` (Number) The scale factor for the generator. Defaults to 0.01 (~ 10MB).
- `scale_factor` (Number, Deprecated) (Deprecated) The scale factor for the generator. Defaults to 0.01 (~ 10MB).
- `tick_interval` (String) The interval at which the next datum should be emitted. Defaults to one second.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ resource "materialize_source_load_generator" "example_source_load_generator" {

counter_options {
tick_interval = "500ms"
scale_factor = 0.01
}
}

# CREATE SOURCE schema.source_load_generator
# FROM LOAD GENERATOR COUNTER
# (TICK INTERVAL '500ms' SCALE FACTOR 0.01);
# (TICK INTERVAL '500ms');
15 changes: 1 addition & 14 deletions pkg/materialize/source_load_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

type CounterOptions struct {
TickInterval string
ScaleFactor float64
MaxCardinality int
}

Expand All @@ -20,10 +19,6 @@ func GetCounterOptionsStruct(v interface{}) CounterOptions {
o.TickInterval = v.(string)
}

if v, ok := u["scale_factor"]; ok {
o.ScaleFactor = v.(float64)
}

if v, ok := u["max_cardinality"]; ok {
o.MaxCardinality = v.(int)
}
Expand All @@ -32,7 +27,6 @@ func GetCounterOptionsStruct(v interface{}) CounterOptions {

type AuctionOptions struct {
TickInterval string
ScaleFactor float64
}

func GetAuctionOptionsStruct(v interface{}) AuctionOptions {
Expand All @@ -42,15 +36,11 @@ func GetAuctionOptionsStruct(v interface{}) AuctionOptions {
o.TickInterval = v.(string)
}

if v, ok := u["scale_factor"]; ok {
o.ScaleFactor = v.(float64)
}
return o
}

type MarketingOptions struct {
TickInterval string
ScaleFactor float64
}

func GetMarketingOptionsStruct(v interface{}) MarketingOptions {
Expand All @@ -60,9 +50,6 @@ func GetMarketingOptionsStruct(v interface{}) MarketingOptions {
o.TickInterval = v.(string)
}

if v, ok := u["scale_factor"]; ok {
o.ScaleFactor = v.(float64)
}
return o
}

Expand Down Expand Up @@ -162,7 +149,7 @@ func (b *SourceLoadgenBuilder) Create() error {
}
}

for _, t := range []float64{b.counterOptions.ScaleFactor, b.auctionOptions.ScaleFactor, b.marketingOptions.ScaleFactor, b.tpchOptions.ScaleFactor} {
for _, t := range []float64{b.tpchOptions.ScaleFactor} {
if t != 0 {
p = append(p, fmt.Sprintf(`SCALE FACTOR %.2f`, t))
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/materialize/source_load_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ func TestSourceLoadgenAuctionCreate(t *testing.T) {
mock.ExpectExec(
`CREATE SOURCE "database"."schema"."source"
FROM LOAD GENERATOR AUCTION
\(TICK INTERVAL '1s', SCALE FACTOR 0.01\)
\(TICK INTERVAL '1s'\)
FOR ALL TABLES;`,
).WillReturnResult(sqlmock.NewResult(1, 1))

b := NewSourceLoadgenBuilder(db, sourceLoadgen)
b.LoadGeneratorType("AUCTION")
b.AuctionOptions(AuctionOptions{
TickInterval: "1s",
ScaleFactor: 0.01,
})

if err := b.Create(); err != nil {
Expand All @@ -60,15 +59,14 @@ func TestSourceLoadgenMarketingCreate(t *testing.T) {
mock.ExpectExec(
`CREATE SOURCE "database"."schema"."source"
FROM LOAD GENERATOR MARKETING
\(TICK INTERVAL '1s', SCALE FACTOR 0.01\)
\(TICK INTERVAL '1s'\)
FOR ALL TABLES;`,
).WillReturnResult(sqlmock.NewResult(1, 1))

b := NewSourceLoadgenBuilder(db, sourceLoadgen)
b.LoadGeneratorType("MARKETING")
b.MarketingOptions(MarketingOptions{
TickInterval: "1s",
ScaleFactor: 0.01,
})

if err := b.Create(); err != nil {
Expand Down
7 changes: 0 additions & 7 deletions pkg/provider/acceptance_source_load_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestAccSourceLoadGeneratorCounter_basic(t *testing.T) {
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "cluster_name", roleName+"_cluster"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "load_generator_type", "COUNTER"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "counter_options.0.tick_interval", "1000ms"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "counter_options.0.scale_factor", "0.1"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "counter_options.0.max_cardinality", "8"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "ownership_role", "mz_system"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "subsources.#", "0"),
Expand Down Expand Up @@ -71,7 +70,6 @@ func TestAccSourceLoadGeneratorAuction_basic(t *testing.T) {
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "size", "3xsmall"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "load_generator_type", "AUCTION"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "auction_options.0.tick_interval", "1000ms"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "auction_options.0.scale_factor", "0.1"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "subsource.#", "6"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "subsource.0.schema_name", "auction"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "subsource.0.database_name", "materialize"),
Expand Down Expand Up @@ -104,7 +102,6 @@ func TestAccSourceLoadGeneratorMarketing_basic(t *testing.T) {
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "size", "3xsmall"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "load_generator_type", "MARKETING"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "marketing_options.0.tick_interval", "1000ms"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "marketing_options.0.scale_factor", "0.1"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "subsource.#", "7"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "subsource.0.schema_name", "marketing"),
resource.TestCheckResourceAttr("materialize_source_load_generator.test", "subsource.0.database_name", "materialize"),
Expand Down Expand Up @@ -231,7 +228,6 @@ func testAccSourceLoadGeneratorResource(roleName, sourceName, source2Name, size,
load_generator_type = "COUNTER"
counter_options {
tick_interval = "1000ms"
scale_factor = 0.1
max_cardinality = 8
}
}
Expand All @@ -243,7 +239,6 @@ func testAccSourceLoadGeneratorResource(roleName, sourceName, source2Name, size,
load_generator_type = "COUNTER"
counter_options {
tick_interval = "1000ms"
scale_factor = 0.1
}
ownership_role = "%[5]s"
comment = "%[6]s"
Expand Down Expand Up @@ -272,7 +267,6 @@ func testAccSourceLoadGeneratorAuctionResource(sourceName string) string {
load_generator_type = "AUCTION"
auction_options {
tick_interval = "1000ms"
scale_factor = 0.1
}
}
`, sourceName)
Expand All @@ -296,7 +290,6 @@ func testAccSourceLoadGeneratorMarketingResource(sourceName string) string {
load_generator_type = "MARKETING"
marketing_options {
tick_interval = "1000ms"
scale_factor = 0.1
}
}
`, sourceName)
Expand Down
15 changes: 12 additions & 3 deletions pkg/resources/resource_source_load_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ var scale_factor = &schema.Schema{
ForceNew: true,
}

var scale_factor_deprecated = &schema.Schema{
Description: "(Deprecated) The scale factor for the generator. Defaults to 0.01 (~ 10MB).",
Deprecated: "Scale factor is deprecated and will be removed in a future release.",
Type: schema.TypeFloat,
Optional: true,
Default: 0.01,
ForceNew: true,
}

var sourceLoadgenSchema = map[string]*schema.Schema{
"name": ObjectNameSchema("source", true, false),
"schema_name": SchemaNameSchema("source", false),
Expand All @@ -49,7 +58,7 @@ var sourceLoadgenSchema = map[string]*schema.Schema{
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tick_interval": tick_interval,
"scale_factor": scale_factor,
"scale_factor": scale_factor_deprecated,
"max_cardinality": {
Description: "Causes the generator to delete old values to keep the collection at most a given size. Defaults to unlimited.",
Type: schema.TypeInt,
Expand All @@ -70,7 +79,7 @@ var sourceLoadgenSchema = map[string]*schema.Schema{
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tick_interval": tick_interval,
"scale_factor": scale_factor,
"scale_factor": scale_factor_deprecated,
},
},
Optional: true,
Expand All @@ -85,7 +94,7 @@ var sourceLoadgenSchema = map[string]*schema.Schema{
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"tick_interval": tick_interval,
"scale_factor": scale_factor,
"scale_factor": scale_factor_deprecated,
},
},
Optional: true,
Expand Down

0 comments on commit b118152

Please sign in to comment.