mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
common/schema: generate bimap for column names
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
/test/
|
||||
/orchestrator/clickhouse/data/asns.csv
|
||||
/console/filter/parser.go
|
||||
/common/schema/definition_gen.go
|
||||
mock_*.go
|
||||
|
||||
/console/data/frontend/
|
||||
|
||||
9
Makefile
9
Makefile
@@ -18,6 +18,7 @@ GENERATED_JS = \
|
||||
console/frontend/node_modules
|
||||
GENERATED_GO = \
|
||||
common/clickhousedb/mocks/mock_driver.go \
|
||||
common/schema/definition_gen.go \
|
||||
conntrackfixer/mocks/mock_conntrackfixer.go \
|
||||
orchestrator/clickhouse/data/asns.csv \
|
||||
console/filter/parser.go
|
||||
@@ -68,16 +69,20 @@ $(BIN)/wwhrd: PACKAGE=github.com/frapposelli/wwhrd@latest
|
||||
|
||||
.DELETE_ON_ERROR:
|
||||
|
||||
common/clickhousedb/mocks/mock_driver.go: $(MOCKGEN) ; $(info $(M) generate mocks for ClickHouse driver…)
|
||||
common/clickhousedb/mocks/mock_driver.go: | $(MOCKGEN) ; $(info $(M) generate mocks for ClickHouse driver…)
|
||||
$Q echo '//go:build !release' > $@
|
||||
$Q $(MOCKGEN) -package mocks \
|
||||
github.com/ClickHouse/clickhouse-go/v2/lib/driver Conn,Row,Rows,ColumnType >> $@
|
||||
conntrackfixer/mocks/mock_conntrackfixer.go: $(MOCKGEN) ; $(info $(M) generate mocks for conntrack-fixer…)
|
||||
conntrackfixer/mocks/mock_conntrackfixer.go: | $(MOCKGEN) ; $(info $(M) generate mocks for conntrack-fixer…)
|
||||
$Q if [ `$(GO) env GOOS` = "linux" ]; then \
|
||||
echo '//go:build !release' > $@ ; \
|
||||
$(MOCKGEN) -package mocks akvorado/conntrackfixer ConntrackConn,DockerClient >> $@ ; \
|
||||
fi
|
||||
|
||||
common/schema/definition_gen.go: common/schema/definition.go common/schema/definition_gen.sh ; $(info $(M) generate column definitions…)
|
||||
$Q ./common/schema/definition_gen.sh > $@
|
||||
$Q $(GOIMPORTS) -w $@
|
||||
|
||||
console/filter/parser.go: console/filter/parser.peg | $(PIGEON) ; $(info $(M) generate PEG parser for filters…)
|
||||
$Q $(PIGEON) -optimize-basic-latin $< > $@
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"akvorado/common/helpers/bimap"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
@@ -81,68 +79,6 @@ const (
|
||||
|
||||
// revive:enable
|
||||
|
||||
var columnNameMap = bimap.New(map[ColumnKey]string{
|
||||
ColumnTimeReceived: "TimeReceived",
|
||||
ColumnSamplingRate: "SamplingRate",
|
||||
ColumnExporterAddress: "ExporterAddress",
|
||||
ColumnExporterName: "ExporterName",
|
||||
ColumnExporterGroup: "ExporterGroup",
|
||||
ColumnExporterRole: "ExporterRole",
|
||||
ColumnExporterSite: "ExporterSite",
|
||||
ColumnExporterRegion: "ExporterRegion",
|
||||
ColumnExporterTenant: "ExporterTenant",
|
||||
ColumnSrcAddr: "SrcAddr",
|
||||
ColumnDstAddr: "DstAddr",
|
||||
ColumnSrcNetMask: "SrcNetMask",
|
||||
ColumnDstNetMask: "DstNetMask",
|
||||
ColumnSrcNetPrefix: "SrcNetPrefix",
|
||||
ColumnDstNetPrefix: "DstNetPrefix",
|
||||
ColumnSrcAS: "SrcAS",
|
||||
ColumnDstAS: "DstAS",
|
||||
ColumnSrcNetName: "SrcNetName",
|
||||
ColumnDstNetName: "DstNetName",
|
||||
ColumnSrcNetRole: "SrcNetRole",
|
||||
ColumnDstNetRole: "DstNetRole",
|
||||
ColumnSrcNetSite: "SrcNetSite",
|
||||
ColumnDstNetSite: "DstNetSite",
|
||||
ColumnSrcNetRegion: "SrcNetRegion",
|
||||
ColumnDstNetRegion: "DstNetRegion",
|
||||
ColumnSrcNetTenant: "SrcNetTenant",
|
||||
ColumnDstNetTenant: "DstNetTenant",
|
||||
ColumnSrcCountry: "SrcCountry",
|
||||
ColumnDstCountry: "DstCountry",
|
||||
ColumnDstASPath: "DstASPath",
|
||||
ColumnDst1stAS: "Dst1stAS",
|
||||
ColumnDst2ndAS: "Dst2ndAS",
|
||||
ColumnDst3rdAS: "Dst3rdAS",
|
||||
ColumnDstCommunities: "DstCommunities",
|
||||
ColumnDstLargeCommunities: "DstLargeCommunities",
|
||||
ColumnDstLargeCommunitiesASN: "DstLargeCommunitiesASN",
|
||||
ColumnDstLargeCommunitiesLocalData1: "DstLargeCommunitiesLocalData1",
|
||||
ColumnDstLargeCommunitiesLocalData2: "DstLargeCommunitiesLocalData2",
|
||||
ColumnInIfName: "InIfName",
|
||||
ColumnOutIfName: "OutIfName",
|
||||
ColumnInIfDescription: "InIfDescription",
|
||||
ColumnOutIfDescription: "OutIfDescription",
|
||||
ColumnInIfSpeed: "InIfSpeed",
|
||||
ColumnOutIfSpeed: "OutIfSpeed",
|
||||
ColumnInIfProvider: "InIfProvider",
|
||||
ColumnOutIfProvider: "OutIfProvider",
|
||||
ColumnInIfConnectivity: "InIfConnectivity",
|
||||
ColumnOutIfConnectivity: "OutIfConnectivity",
|
||||
ColumnInIfBoundary: "InIfBoundary",
|
||||
ColumnOutIfBoundary: "OutIfBoundary",
|
||||
ColumnEType: "EType",
|
||||
ColumnProto: "Proto",
|
||||
ColumnSrcPort: "SrcPort",
|
||||
ColumnDstPort: "DstPort",
|
||||
ColumnBytes: "Bytes",
|
||||
ColumnPackets: "Packets",
|
||||
ColumnPacketSize: "PacketSize",
|
||||
ColumnPacketSizeBucket: "PacketSizeBucket",
|
||||
ColumnForwardingStatus: "ForwardingStatus",
|
||||
})
|
||||
|
||||
func (c ColumnKey) String() string {
|
||||
name, _ := columnNameMap.LoadValue(c)
|
||||
return name
|
||||
|
||||
22
common/schema/definition_gen.sh
Executable file
22
common/schema/definition_gen.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Generate definition_gen.go from definition.go.
|
||||
|
||||
set -e
|
||||
|
||||
cat <<EOF
|
||||
// Code generated by definition_gen.sh. DO NOT EDIT.
|
||||
|
||||
package schema
|
||||
|
||||
import "akvorado/common/helpers/bimap"
|
||||
|
||||
var columnNameMap = bimap.New(map[ColumnKey]string{
|
||||
$(grep -oEw 'Column[a-zA-Z0-9]+' common/schema/definition.go \
|
||||
| sed 's/^Column//' \
|
||||
| grep -vFx Last \
|
||||
| grep -vFx Key \
|
||||
| sort | uniq \
|
||||
| awk '{ print "Column"$1": \""$1"\","}')
|
||||
})
|
||||
EOF
|
||||
Reference in New Issue
Block a user