diff --git a/db/migrations/000018_add_protocols_to_requests_dnf_table.down.sql b/db/migrations/000018_add_protocols_to_requests_dnf_table.down.sql new file mode 100644 index 0000000..8654232 --- /dev/null +++ b/db/migrations/000018_add_protocols_to_requests_dnf_table.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE requests_denormalized + DROP COLUMN IF EXISTS protocols; diff --git a/db/migrations/000018_add_protocols_to_requests_dnf_table.up.sql b/db/migrations/000018_add_protocols_to_requests_dnf_table.up.sql new file mode 100644 index 0000000..b947dd9 --- /dev/null +++ b/db/migrations/000018_add_protocols_to_requests_dnf_table.up.sql @@ -0,0 +1,5 @@ +BEGIN; + +ALTER TABLE requests_denormalized ADD COLUMN protocols TEXT[]; + +COMMIT; diff --git a/db/models/requests_denormalized.go b/db/models/requests_denormalized.go index c94f4aa..7c0424f 100644 --- a/db/models/requests_denormalized.go +++ b/db/models/requests_denormalized.go @@ -34,6 +34,7 @@ type RequestsDenormalized struct { MultiAddresses types.StringArray `boil:"multi_addresses" json:"multi_addresses,omitempty" toml:"multi_addresses" yaml:"multi_addresses,omitempty"` AgentVersion null.String `boil:"agent_version" json:"agent_version,omitempty" toml:"agent_version" yaml:"agent_version,omitempty"` NormalizedAt null.Time `boil:"normalized_at" json:"normalized_at,omitempty" toml:"normalized_at" yaml:"normalized_at,omitempty"` + Protocols types.StringArray `boil:"protocols" json:"protocols,omitempty" toml:"protocols" yaml:"protocols,omitempty"` R *requestsDenormalizedR `boil:"-" json:"-" toml:"-" yaml:"-"` L requestsDenormalizedL `boil:"-" json:"-" toml:"-" yaml:"-"` @@ -49,6 +50,7 @@ var RequestsDenormalizedColumns = struct { MultiAddresses string AgentVersion string NormalizedAt string + Protocols string }{ ID: "id", RequestStartedAt: "request_started_at", @@ -59,6 +61,7 @@ var RequestsDenormalizedColumns = struct { MultiAddresses: "multi_addresses", AgentVersion: "agent_version", NormalizedAt: "normalized_at", + Protocols: "protocols", } var RequestsDenormalizedTableColumns = struct { @@ -71,6 +74,7 @@ var RequestsDenormalizedTableColumns = struct { MultiAddresses string AgentVersion string NormalizedAt string + Protocols string }{ ID: "requests_denormalized.id", RequestStartedAt: "requests_denormalized.request_started_at", @@ -81,6 +85,7 @@ var RequestsDenormalizedTableColumns = struct { MultiAddresses: "requests_denormalized.multi_addresses", AgentVersion: "requests_denormalized.agent_version", NormalizedAt: "requests_denormalized.normalized_at", + Protocols: "requests_denormalized.protocols", } // Generated where @@ -145,6 +150,7 @@ var RequestsDenormalizedWhere = struct { MultiAddresses whereHelpertypes_StringArray AgentVersion whereHelpernull_String NormalizedAt whereHelpernull_Time + Protocols whereHelpertypes_StringArray }{ ID: whereHelperint64{field: "\"requests_denormalized\".\"id\""}, RequestStartedAt: whereHelpertime_Time{field: "\"requests_denormalized\".\"request_started_at\""}, @@ -155,6 +161,7 @@ var RequestsDenormalizedWhere = struct { MultiAddresses: whereHelpertypes_StringArray{field: "\"requests_denormalized\".\"multi_addresses\""}, AgentVersion: whereHelpernull_String{field: "\"requests_denormalized\".\"agent_version\""}, NormalizedAt: whereHelpernull_Time{field: "\"requests_denormalized\".\"normalized_at\""}, + Protocols: whereHelpertypes_StringArray{field: "\"requests_denormalized\".\"protocols\""}, } // RequestsDenormalizedRels is where relationship names are stored. @@ -174,9 +181,9 @@ func (*requestsDenormalizedR) NewStruct() *requestsDenormalizedR { type requestsDenormalizedL struct{} var ( - requestsDenormalizedAllColumns = []string{"id", "request_started_at", "request_type", "ant_multihash", "peer_multihash", "key_multihash", "multi_addresses", "agent_version", "normalized_at"} + requestsDenormalizedAllColumns = []string{"id", "request_started_at", "request_type", "ant_multihash", "peer_multihash", "key_multihash", "multi_addresses", "agent_version", "normalized_at", "protocols"} requestsDenormalizedColumnsWithoutDefault = []string{"request_started_at", "request_type", "ant_multihash", "peer_multihash", "key_multihash"} - requestsDenormalizedColumnsWithDefault = []string{"id", "multi_addresses", "agent_version", "normalized_at"} + requestsDenormalizedColumnsWithDefault = []string{"id", "multi_addresses", "agent_version", "normalized_at", "protocols"} requestsDenormalizedPrimaryKeyColumns = []string{"id", "request_started_at"} requestsDenormalizedGeneratedColumns = []string{"id"} ) diff --git a/queen.go b/queen.go index b5e91ee..3d99b49 100644 --- a/queen.go +++ b/queen.go @@ -218,7 +218,12 @@ func (q *Queen) consumeAntsLogs(ctx context.Context) { } else { agent = peerstoreAgent.(string) } + // TODO: uncomment when we need to track protocols // protocols, _ := q.peerstore.GetProtocols(log.Requester) + // protocolsStr := make([]string, len(protocols)) + // for i, p := range protocols { + // protocolsStr[i] = string(p) + // } request := models.RequestsDenormalized{ RequestStartedAt: log.Timestamp, @@ -228,6 +233,7 @@ func (q *Queen) consumeAntsLogs(ctx context.Context) { KeyMultihash: log.Target.B58String(), MultiAddresses: db.MaddrsToAddrs(maddrs), AgentVersion: null.StringFrom(agent), + // Protocols: protocolsStr, } requests = append(requests, request) if len(requests) >= q.resolveBatchSize {