From 4773e3a1edb02175cde198e8d085a060caee374a Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Wed, 30 Jun 2021 17:47:29 +0100 Subject: [PATCH] add custom probe URL support for observatory --- app/observatory/config.pb.go | 32 +++++++++++++++++++++----------- app/observatory/config.proto | 2 ++ app/observatory/observer.go | 6 +++++- infra/conf/observatory.go | 3 ++- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app/observatory/config.pb.go b/app/observatory/config.pb.go index a28ae76fc..5392296de 100644 --- a/app/observatory/config.pb.go +++ b/app/observatory/config.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.26.0 +// protoc-gen-go v1.27.1 // protoc v3.15.6 // source: app/observatory/config.proto @@ -293,6 +293,7 @@ type Config struct { // @Document The selectors for outbound under observation SubjectSelector []string `protobuf:"bytes,2,rep,name=subject_selector,json=subjectSelector,proto3" json:"subject_selector,omitempty"` + ProbeUrl string `protobuf:"bytes,3,opt,name=probe_url,json=probeUrl,proto3" json:"probe_url,omitempty"` } func (x *Config) Reset() { @@ -334,6 +335,13 @@ func (x *Config) GetSubjectSelector() []string { return nil } +func (x *Config) GetProbeUrl() string { + if x != nil { + return x.ProbeUrl + } + return "" +} + var File_app_observatory_config_proto protoreflect.FileDescriptor var file_app_observatory_config_proto_rawDesc = []byte{ @@ -369,18 +377,20 @@ var file_app_observatory_config_proto_rawDesc = []byte{ 0x6f, 0x6e, 0x22, 0x32, 0x0a, 0x09, 0x49, 0x6e, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x74, 0x79, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x72, 0x6f, 0x62, 0x65, 0x5f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0d, 0x70, 0x72, 0x6f, 0x62, 0x65, 0x49, 0x6e, - 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x22, 0x33, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x22, 0x50, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x29, 0x0a, 0x10, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x5f, 0x73, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0f, 0x73, 0x75, 0x62, 0x6a, - 0x65, 0x63, 0x74, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x42, 0x6f, 0x0a, 0x1e, 0x63, - 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, - 0x70, 0x2e, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x50, 0x01, 0x5a, - 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, - 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x34, 0x2f, - 0x61, 0x70, 0x70, 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0xaa, - 0x02, 0x1a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, - 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x63, 0x74, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x70, + 0x72, 0x6f, 0x62, 0x65, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x70, 0x72, 0x6f, 0x62, 0x65, 0x55, 0x72, 0x6c, 0x42, 0x6f, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, + 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x6f, + 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x50, 0x01, 0x5a, 0x2e, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76, 0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, + 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x76, 0x34, 0x2f, 0x61, 0x70, 0x70, + 0x2f, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0xaa, 0x02, 0x1a, 0x56, + 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e, 0x41, 0x70, 0x70, 0x2e, 0x4f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x6f, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/app/observatory/config.proto b/app/observatory/config.proto index e37d00fd6..7267e4956 100644 --- a/app/observatory/config.proto +++ b/app/observatory/config.proto @@ -64,4 +64,6 @@ message Config { /* @Document The selectors for outbound under observation */ repeated string subject_selector = 2; + + string probe_url = 3; } \ No newline at end of file diff --git a/app/observatory/observer.go b/app/observatory/observer.go index 632d5cecd..02ec5dbec 100644 --- a/app/observatory/observer.go +++ b/app/observatory/observer.go @@ -129,7 +129,11 @@ func (o *Observer) probe(outbound string) ProbeResult { var GETTime time.Duration err := task.Run(o.ctx, func() error { startTime := time.Now() - response, err := httpClient.Get("https://api.v2fly.org/checkConnection.svgz") + probeURL := "https://api.v2fly.org/checkConnection.svgz" + if o.config.ProbeUrl != "" { + probeURL = o.config.ProbeUrl + } + response, err := httpClient.Get(probeURL) if err != nil { return newError("outbound failed to relay connection").Base(err) } diff --git a/infra/conf/observatory.go b/infra/conf/observatory.go index f7356bcbd..0a2813084 100644 --- a/infra/conf/observatory.go +++ b/infra/conf/observatory.go @@ -8,8 +8,9 @@ import ( type ObservatoryConfig struct { SubjectSelector []string `json:"subjectSelector"` + ProbeURL string `json:"probeURL"` } func (o *ObservatoryConfig) Build() (proto.Message, error) { - return &observatory.Config{SubjectSelector: o.SubjectSelector}, nil + return &observatory.Config{SubjectSelector: o.SubjectSelector, ProbeUrl: o.ProbeURL}, nil }