Skip to content

Commit

Permalink
MINOR: structured: add tables to structured peers
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaticevic committed Oct 16, 2024
1 parent d4c73a1 commit 56e4556
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 2 deletions.
16 changes: 16 additions & 0 deletions configuration/structured_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ func parsePeerSection(name string, p parser.Parser) (*models.PeerSection, error)
return nil, errsa
}
ps.Servers = serversa

// tables
tables, err := ParseTables(name, p)
if err != nil {
return nil, err
}
tablesa, errsa := namedResourceArrayToMap(tables)
if errsa != nil {
return nil, errsa
}
ps.Tables = tablesa
return ps, nil
}

Expand Down Expand Up @@ -233,5 +244,10 @@ func serializePeerSection(a StructuredToParserArgs, ps *models.PeerSection) erro
return a.HandleError(strconv.FormatInt(int64(i), 10), PeersParentName, ps.Name, a.TID, a.TID == "", err)
}
}
for _, table := range ps.Tables {
if err = p.Insert(parser.Peers, ps.Name, "table", SerializeTable(table), -1); err != nil {
return a.HandleError(table.Name, PeersParentName, ps.Name, a.TID, a.TID == "", err)
}
}
return nil
}
61 changes: 61 additions & 0 deletions models/peer_section.go

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

20 changes: 20 additions & 0 deletions models/peer_section_compare.go

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

4 changes: 2 additions & 2 deletions models/peer_section_compare_test.go

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

3 changes: 3 additions & 0 deletions specification/build/haproxy_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4054,6 +4054,9 @@ definitions:
servers:
additionalProperties:
$ref: '#/definitions/server'
tables:
additionalProperties:
$ref: '#/definitions/table'
type: object
description: Peer Section with all it's children resources
type: object
Expand Down
3 changes: 3 additions & 0 deletions specification/models/configuration/peers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ peer_section:
servers:
additionalProperties:
$ref: "#/definitions/server"
tables:
additionalProperties:
$ref: "#/definitions/table"
peer_section_base:
title: Peer Section Base
description: HAProxy peer_section configuration
Expand Down
30 changes: 30 additions & 0 deletions test/expected/structured.json
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,36 @@
"port": 1023,
"shard": 1
}
},
"tables": {
"t1": {
"expire": "5m",
"name": "t1",
"no_purge": true,
"size": "200k",
"store": "gpc0,conn_rate(30s)",
"type": "string",
"type_len": 1000
},
"t2": {
"expire": "5m",
"name": "t2",
"no_purge": true,
"size": "200k",
"store": "gpc0,gpc1,conn_rate(30s)",
"type": "string",
"type_len": 1000
},
"t9": {
"expire": "5m",
"name": "t9",
"no_purge": true,
"size": "200k",
"store": "gpc0,conn_rate(30s)",
"type": "string",
"type_len": 1000,
"write_to": "t2"
}
}
}
},
Expand Down

0 comments on commit 56e4556

Please sign in to comment.