diff --git a/output/pganalyze_collector/server_message.pb.go b/output/pganalyze_collector/server_message.pb.go index 972001fe8..60b3b0646 100644 --- a/output/pganalyze_collector/server_message.pb.go +++ b/output/pganalyze_collector/server_message.pb.go @@ -327,21 +327,79 @@ func (x *ServerMessage_Pause) GetPause() bool { return false } +type ServerMessage_QueryRunPostgresSetting struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *ServerMessage_QueryRunPostgresSetting) Reset() { + *x = ServerMessage_QueryRunPostgresSetting{} + if protoimpl.UnsafeEnabled { + mi := &file_server_message_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ServerMessage_QueryRunPostgresSetting) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ServerMessage_QueryRunPostgresSetting) ProtoMessage() {} + +func (x *ServerMessage_QueryRunPostgresSetting) ProtoReflect() protoreflect.Message { + mi := &file_server_message_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ServerMessage_QueryRunPostgresSetting.ProtoReflect.Descriptor instead. +func (*ServerMessage_QueryRunPostgresSetting) Descriptor() ([]byte, []int) { + return file_server_message_proto_rawDescGZIP(), []int{0, 3} +} + +func (x *ServerMessage_QueryRunPostgresSetting) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ServerMessage_QueryRunPostgresSetting) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + type ServerMessage_QueryRun struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` - Type QueryRunType `protobuf:"varint,2,opt,name=type,proto3,enum=pganalyze.collector.QueryRunType" json:"type,omitempty"` - DatabaseName string `protobuf:"bytes,3,opt,name=database_name,json=databaseName,proto3" json:"database_name,omitempty"` - QueryText string `protobuf:"bytes,4,opt,name=query_text,json=queryText,proto3" json:"query_text,omitempty"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Type QueryRunType `protobuf:"varint,2,opt,name=type,proto3,enum=pganalyze.collector.QueryRunType" json:"type,omitempty"` + DatabaseName string `protobuf:"bytes,3,opt,name=database_name,json=databaseName,proto3" json:"database_name,omitempty"` + QueryText string `protobuf:"bytes,4,opt,name=query_text,json=queryText,proto3" json:"query_text,omitempty"` + QueryParameters []*NullString `protobuf:"bytes,5,rep,name=query_parameters,json=queryParameters,proto3" json:"query_parameters,omitempty"` + QueryParameterTypes []string `protobuf:"bytes,6,rep,name=query_parameter_types,json=queryParameterTypes,proto3" json:"query_parameter_types,omitempty"` + PostgresSettings []*ServerMessage_QueryRunPostgresSetting `protobuf:"bytes,7,rep,name=postgres_settings,json=postgresSettings,proto3" json:"postgres_settings,omitempty"` } func (x *ServerMessage_QueryRun) Reset() { *x = ServerMessage_QueryRun{} if protoimpl.UnsafeEnabled { - mi := &file_server_message_proto_msgTypes[4] + mi := &file_server_message_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -354,7 +412,7 @@ func (x *ServerMessage_QueryRun) String() string { func (*ServerMessage_QueryRun) ProtoMessage() {} func (x *ServerMessage_QueryRun) ProtoReflect() protoreflect.Message { - mi := &file_server_message_proto_msgTypes[4] + mi := &file_server_message_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -367,7 +425,7 @@ func (x *ServerMessage_QueryRun) ProtoReflect() protoreflect.Message { // Deprecated: Use ServerMessage_QueryRun.ProtoReflect.Descriptor instead. func (*ServerMessage_QueryRun) Descriptor() ([]byte, []int) { - return file_server_message_proto_rawDescGZIP(), []int{0, 3} + return file_server_message_proto_rawDescGZIP(), []int{0, 4} } func (x *ServerMessage_QueryRun) GetId() int64 { @@ -398,13 +456,34 @@ func (x *ServerMessage_QueryRun) GetQueryText() string { return "" } +func (x *ServerMessage_QueryRun) GetQueryParameters() []*NullString { + if x != nil { + return x.QueryParameters + } + return nil +} + +func (x *ServerMessage_QueryRun) GetQueryParameterTypes() []string { + if x != nil { + return x.QueryParameterTypes + } + return nil +} + +func (x *ServerMessage_QueryRun) GetPostgresSettings() []*ServerMessage_QueryRunPostgresSetting { + if x != nil { + return x.PostgresSettings + } + return nil +} + var File_server_message_proto protoreflect.FileDescriptor var file_server_message_proto_rawDesc = []byte{ 0x0a, 0x14, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x1a, 0x0c, 0x73, 0x68, 0x61, - 0x72, 0x65, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8c, 0x07, 0x0a, 0x0d, 0x53, 0x65, + 0x72, 0x65, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xba, 0x09, 0x0a, 0x0d, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x43, 0x0a, 0x06, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, @@ -451,21 +530,40 @@ var file_server_message_proto_rawDesc = []byte{ 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x4d, 0x73, 0x51, 0x75, 0x65, 0x72, 0x79, 0x54, 0x65, 0x78, 0x74, 0x1a, 0x1d, 0x0a, 0x05, 0x50, 0x61, 0x75, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x61, 0x75, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, - 0x70, 0x61, 0x75, 0x73, 0x65, 0x1a, 0x95, 0x01, 0x0a, 0x08, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, - 0x75, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, - 0x69, 0x64, 0x12, 0x35, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, - 0x32, 0x21, 0x2e, 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x2e, 0x63, 0x6f, 0x6c, - 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x75, 0x6e, 0x54, - 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x64, 0x61, 0x74, - 0x61, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0c, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1d, - 0x0a, 0x0a, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, 0x74, 0x65, 0x78, 0x74, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x71, 0x75, 0x65, 0x72, 0x79, 0x54, 0x65, 0x78, 0x74, 0x42, 0x09, 0x0a, - 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x3b, 0x5a, 0x39, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, - 0x2f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2f, 0x6f, 0x75, 0x74, 0x70, 0x75, - 0x74, 0x2f, 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x5f, 0x63, 0x6f, 0x6c, 0x6c, - 0x65, 0x63, 0x74, 0x6f, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x61, 0x75, 0x73, 0x65, 0x1a, 0x43, 0x0a, 0x17, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x75, + 0x6e, 0x50, 0x6f, 0x73, 0x74, 0x67, 0x72, 0x65, 0x73, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, + 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x1a, 0xfe, 0x02, 0x0a, 0x08, 0x51, + 0x75, 0x65, 0x72, 0x79, 0x52, 0x75, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x35, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x21, 0x2e, 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, + 0x65, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x52, 0x75, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x23, + 0x0a, 0x0d, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x4e, + 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, 0x74, 0x65, 0x78, + 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x71, 0x75, 0x65, 0x72, 0x79, 0x54, 0x65, + 0x78, 0x74, 0x12, 0x4a, 0x0a, 0x10, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, 0x70, 0x61, 0x72, 0x61, + 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e, 0x70, + 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, + 0x6f, 0x72, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x52, 0x0f, 0x71, + 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x12, 0x32, + 0x0a, 0x15, 0x71, 0x75, 0x65, 0x72, 0x79, 0x5f, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, + 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, 0x13, 0x71, + 0x75, 0x65, 0x72, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x54, 0x79, 0x70, + 0x65, 0x73, 0x12, 0x67, 0x0a, 0x11, 0x70, 0x6f, 0x73, 0x74, 0x67, 0x72, 0x65, 0x73, 0x5f, 0x73, + 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x3a, 0x2e, + 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x2e, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, + 0x74, 0x6f, 0x72, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x75, 0x6e, 0x50, 0x6f, 0x73, 0x74, 0x67, 0x72, + 0x65, 0x73, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x10, 0x70, 0x6f, 0x73, 0x74, 0x67, + 0x72, 0x65, 0x73, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x42, 0x09, 0x0a, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x42, 0x3b, 0x5a, 0x39, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x2f, 0x63, + 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x2f, 0x6f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2f, + 0x70, 0x67, 0x61, 0x6e, 0x61, 0x6c, 0x79, 0x7a, 0x65, 0x5f, 0x63, 0x6f, 0x6c, 0x6c, 0x65, 0x63, + 0x74, 0x6f, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -480,26 +578,30 @@ func file_server_message_proto_rawDescGZIP() []byte { return file_server_message_proto_rawDescData } -var file_server_message_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_server_message_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_server_message_proto_goTypes = []interface{}{ - (*ServerMessage)(nil), // 0: pganalyze.collector.ServerMessage - (*ServerMessage_Config)(nil), // 1: pganalyze.collector.ServerMessage.Config - (*ServerMessage_Features)(nil), // 2: pganalyze.collector.ServerMessage.Features - (*ServerMessage_Pause)(nil), // 3: pganalyze.collector.ServerMessage.Pause - (*ServerMessage_QueryRun)(nil), // 4: pganalyze.collector.ServerMessage.QueryRun - (QueryRunType)(0), // 5: pganalyze.collector.QueryRunType + (*ServerMessage)(nil), // 0: pganalyze.collector.ServerMessage + (*ServerMessage_Config)(nil), // 1: pganalyze.collector.ServerMessage.Config + (*ServerMessage_Features)(nil), // 2: pganalyze.collector.ServerMessage.Features + (*ServerMessage_Pause)(nil), // 3: pganalyze.collector.ServerMessage.Pause + (*ServerMessage_QueryRunPostgresSetting)(nil), // 4: pganalyze.collector.ServerMessage.QueryRunPostgresSetting + (*ServerMessage_QueryRun)(nil), // 5: pganalyze.collector.ServerMessage.QueryRun + (QueryRunType)(0), // 6: pganalyze.collector.QueryRunType + (*NullString)(nil), // 7: pganalyze.collector.NullString } var file_server_message_proto_depIdxs = []int32{ 1, // 0: pganalyze.collector.ServerMessage.config:type_name -> pganalyze.collector.ServerMessage.Config 3, // 1: pganalyze.collector.ServerMessage.pause:type_name -> pganalyze.collector.ServerMessage.Pause - 4, // 2: pganalyze.collector.ServerMessage.query_run:type_name -> pganalyze.collector.ServerMessage.QueryRun + 5, // 2: pganalyze.collector.ServerMessage.query_run:type_name -> pganalyze.collector.ServerMessage.QueryRun 2, // 3: pganalyze.collector.ServerMessage.Config.features:type_name -> pganalyze.collector.ServerMessage.Features - 5, // 4: pganalyze.collector.ServerMessage.QueryRun.type:type_name -> pganalyze.collector.QueryRunType - 5, // [5:5] is the sub-list for method output_type - 5, // [5:5] is the sub-list for method input_type - 5, // [5:5] is the sub-list for extension type_name - 5, // [5:5] is the sub-list for extension extendee - 0, // [0:5] is the sub-list for field type_name + 6, // 4: pganalyze.collector.ServerMessage.QueryRun.type:type_name -> pganalyze.collector.QueryRunType + 7, // 5: pganalyze.collector.ServerMessage.QueryRun.query_parameters:type_name -> pganalyze.collector.NullString + 4, // 6: pganalyze.collector.ServerMessage.QueryRun.postgres_settings:type_name -> pganalyze.collector.ServerMessage.QueryRunPostgresSetting + 7, // [7:7] is the sub-list for method output_type + 7, // [7:7] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name } func init() { file_server_message_proto_init() } @@ -558,6 +660,18 @@ func file_server_message_proto_init() { } } file_server_message_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ServerMessage_QueryRunPostgresSetting); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_server_message_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ServerMessage_QueryRun); i { case 0: return &v.state @@ -581,7 +695,7 @@ func file_server_message_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_server_message_proto_rawDesc, NumEnums: 0, - NumMessages: 5, + NumMessages: 6, NumExtensions: 0, NumServices: 0, }, diff --git a/protobuf/server_message.proto b/protobuf/server_message.proto index 3c5fd2ece..073b012ae 100644 --- a/protobuf/server_message.proto +++ b/protobuf/server_message.proto @@ -39,10 +39,18 @@ message ServerMessage { bool pause = 1; } + message QueryRunPostgresSetting { + string name = 1; + string value = 2; + } + message QueryRun { int64 id = 1; QueryRunType type = 2; string database_name = 3; string query_text = 4; + repeated NullString query_parameters = 5; + repeated string query_parameter_types = 6; + repeated QueryRunPostgresSetting postgres_settings = 7; } } diff --git a/runner/query_run.go b/runner/query_run.go index b1a3f152c..131da9ed1 100644 --- a/runner/query_run.go +++ b/runner/query_run.go @@ -6,6 +6,7 @@ import ( "fmt" "time" + "github.com/lib/pq" "github.com/pganalyze/collector/input/postgres" "github.com/pganalyze/collector/output" "github.com/pganalyze/collector/output/pganalyze_collector" @@ -65,11 +66,18 @@ func runQueryOnDatabase(ctx context.Context, server *state.Server, collectionOpt server.QueryRuns[id].BackendPid = pid server.QueryRunsMutex.Unlock() + for _, setting := range query.PostgresSettings { + _, err = db.ExecContext(ctx, postgres.QueryMarkerSQL+"SET %s = %s", pq.QuoteIdentifier(setting.Name), pq.QuoteLiteral(setting.Value)) + if err != nil { + return "", err + } + } + // We don't include QueryMarkerSQL so query runs are reported separately in pganalyze marker := fmt.Sprintf("/* pganalyze:no-alert,pganalyze-query-run:%d */ ", query.Id) if query.Type == pganalyze_collector.QueryRunType_EXPLAIN { - return postgres.RunExplainAnalyzeForQueryRun(ctx, db, query.QueryText, nil, nil, marker) + return postgres.RunExplainAnalyzeForQueryRun(ctx, db, query.QueryText, query.QueryParameters, query.QueryParameterTypes, marker) } else { logger.PrintVerbose("Unhandled query run type %d for %d", query.Type, query.Id) return "", errors.New("Unhandled query run type") diff --git a/runner/websocket.go b/runner/websocket.go index ebb1a0a17..32ab3ba47 100644 --- a/runner/websocket.go +++ b/runner/websocket.go @@ -11,6 +11,7 @@ import ( "time" "github.com/gorilla/websocket" + "github.com/guregu/null" "github.com/pganalyze/collector/output/pganalyze_collector" "github.com/pganalyze/collector/state" "github.com/pganalyze/collector/util" @@ -140,12 +141,23 @@ func connect(ctx context.Context, server *state.Server, globalCollectionOpts sta } else if message.GetQueryRun() != nil { q := message.GetQueryRun() logger.PrintVerbose("Query run %d received: %s", q.Id, q.QueryText) + parameters := []null.String{} + for _, p := range q.QueryParameters { + parameters = append(parameters, null.NewString(p.Value, p.Valid)) + } + settings := []state.QueryRunPostgresSetting{} + for _, s := range q.PostgresSettings { + settings = append(settings, state.QueryRunPostgresSetting{Name: s.Name, Value: s.Value}) + } server.QueryRunsMutex.Lock() server.QueryRuns[q.Id] = &state.QueryRun{ - Id: q.Id, - Type: q.Type, - DatabaseName: q.DatabaseName, - QueryText: q.QueryText, + Id: q.Id, + Type: q.Type, + DatabaseName: q.DatabaseName, + QueryText: q.QueryText, + QueryParameters: parameters, + QueryParameterTypes: q.QueryParameterTypes, + PostgresSettings: settings, } server.QueryRunsMutex.Unlock() } diff --git a/state/state.go b/state/state.go index f0003e225..90b3cf5a6 100644 --- a/state/state.go +++ b/state/state.go @@ -8,6 +8,7 @@ import ( raven "github.com/getsentry/raven-go" "github.com/gorilla/websocket" + "github.com/guregu/null" "github.com/pganalyze/collector/config" "github.com/pganalyze/collector/output/pganalyze_collector" ) @@ -253,16 +254,24 @@ type CollectionStatus struct { LogSnapshotDisabledReason string } +type QueryRunPostgresSetting struct { + Name string + Value string +} + type QueryRun struct { - Id int64 - Type pganalyze_collector.QueryRunType - DatabaseName string - QueryText string - Result string - Error string - StartedAt time.Time - FinishedAt time.Time - BackendPid int + Id int64 + Type pganalyze_collector.QueryRunType + DatabaseName string + QueryText string + QueryParameters []null.String + QueryParameterTypes []string + PostgresSettings []QueryRunPostgresSetting + Result string + Error string + StartedAt time.Time + FinishedAt time.Time + BackendPid int } type Server struct {