func CreateStaticHttpCluster(config StaticHttpCluster) *rpcx.Cluster { services := make([]*rpcx.Supervisor, len(config.Hosts)) top := &rpcx.Cluster{ Name: config.Name, Services: services, Retries: config.Retries, Reporter: NewHttpStatsReporter(gostrich.AdminServer().GetStats().Scoped(config.Name)), } for i, h := range config.Hosts { httpService := &HttpService{&http.Transport{}, h, config.CacheResponseBody} withTimeout := &rpcx.RobustService{Service: httpService, Timeout: config.Timeout} var reporter rpcx.ServiceReporter if config.PerHostStats { reporter = NewHttpStatsReporter(gostrich.AdminServer().GetStats().Scoped(config.Name).Scoped(h)) } services[i] = rpcx.NewSupervisor( h, withTimeout, func() float64 { return top.LatencyAvg() }, reporter, config.ProberReq, nil, // no need to recreate client since http.Transport does those alrady ) } return top }
func init() { ok := tfe.AddRules("test", func() map[string]tfe.Rules { return map[string]tfe.Rules{ ":8888": tfe.Rules{ &tfe.PrefixRewriteRule{ Name: "tco", SourcePathPrefix: "/tco/", ProxiedPathPrefix: "/", Service: tfe.CreateStaticHttpCluster( tfe.StaticHttpCluster{ Name: "tco", Hosts: []string{ "t.co", }, Timeout: 1 * time.Second, Retries: 1, ProberReq: rpcx.ProberReqLastFail, }), Reporter: tfe.NewHttpStatsReporter(gostrich.AdminServer().GetStats().Scoped("tfe-tco")), }, &tfe.PrefixRewriteRule{ Name: "tweetbutton", SourcePathPrefix: "/urls-real/", ProxiedPathPrefix: "/1/urls/", ProxiedAttachHeaders: map[string][]string{ "True-Client-Ip": []string{"127.0.0.1"}, }, Service: tfe.CreateStaticHttpCluster( tfe.StaticHttpCluster{ Name: "tbapi", Hosts: []string{ "urls-real.api.twitter.com", }, Timeout: 1 * time.Second, Retries: 1, ProberReq: rpcx.ProberReqLastFail, }), Reporter: tfe.NewHttpStatsReporter(gostrich.AdminServer().GetStats().Scoped("tfe-tbapi")), }, &tfe.PrefixRewriteRule{ Name: "dead", SourcePathPrefix: "/dead/", ProxiedPathPrefix: "/dead/", }, }, } }) if !ok { log.Println("Rule set named test already exists") } }
func main() { flag.Parse() portOffset := *gostrich.PortOffset newBinding := gostrich.UpdatePort(*binding, portOffset) conf := rpcx.ReliableServiceConf{ Name: "tweetbutton", Makers: makeAll(*cassandras, *cassandraTimeout), Retries: *retries, Concurrency: *concurrency, Stats: gostrich.AdminServer().GetStats().Scoped("tbapi"), Prober: rpcx.ProberReqLastFail, } cas := rpcx.NewReliableService(conf) state := ServerState{cas} server := http.Server{ newBinding, &state, *readTimeout, *writeTimeout, 0, nil, } logger.LogInfo("Tweetbutton starting up...\n") go func() { logger.LogInfo(server.ListenAndServe()) }() gostrich.StartToLive(nil) }
func init() { ok := tfe.AddRules("tweetbutton-smf1", func() map[string]tfe.Rules { return map[string]tfe.Rules{ ":8888": tfe.Rules{ &tfe.PrefixRewriteRule{ Name: "tweetbutton-smf1-plaintext", SourcePathPrefix: "/1/urls/", ProxiedPathPrefix: "/1/urls/", ProxiedAttachHeaders: map[string][]string{ "True-Client-Ip": []string{"127.0.0.1"}, }, Service: tfe.CreateStaticHttpCluster( tfe.StaticHttpCluster{ Name: "tweetbutton", Hosts: []string{ /*"smf1-aea-35-sr2:8000",*/ /*"smf1-adz-03-sr3:8000",*/ "smf1-adj-27-sr4:8000", "smf1-afo-35-sr4:8000", "smf1-adz-19-sr2:8000", "smf1-adb-23-sr3:8000", "smf1-adz-27-sr1:8000", "smf1-afe-15-sr3:8000", "smf1-aer-19-sr4:8000", }, Timeout: 2 * time.Second, Retries: 1, ProberReq: rpcx.ProberReqLastFail, CacheResponseBody: true, MaxIdleConnsPerHost: 20, }), Reporter: tfe.NewHttpStatsReporter(gostrich.AdminServer().GetStats().Scoped("tfe-tbapi-smf1-plaintext")), }, }, } }) if !ok { log.Println("Rule set named tweetbutton-smf1 already exists") } }
func init() { ok := tfe.AddRules("tweetbutton-tunnels", func() map[string]tfe.Rules { return map[string]tfe.Rules{ ":8888": tfe.Rules{ &tfe.PrefixRewriteRule{ Name: "tweetbutton-tunnels", SourcePathPrefix: "/1/urls/", ProxiedPathPrefix: "/1/urls/", ProxiedAttachHeaders: map[string][]string{ "True-Client-Ip": []string{"127.0.0.1"}, }, Service: tfe.CreateStaticHttpCluster( tfe.StaticHttpCluster{ Name: "tweetbutton-tunnels", Hosts: []string{ "localhost:8000", // self "localhost:8001", "localhost:8002", "localhost:8003", "localhost:8004", "localhost:8005", "localhost:8006", "localhost:8007", "localhost:8008", }, Timeout: 2 * time.Second, Retries: 1, ProberReq: rpcx.ProberReqLastFail, }), Reporter: tfe.NewHttpStatsReporter(gostrich.AdminServer().GetStats().Scoped("tweetbutton-tunneled")), }, }, } }) if !ok { log.Println("Rule set named tweetbutton-tunnels already exists") } }