rob05c commented on a change in pull request #3758: Rewrote deliveryservice_stats to Go URL: https://github.com/apache/trafficcontrol/pull/3758#discussion_r328795803
########## File path: traffic_ops/traffic_ops_golang/trafficstats/trafficstats.go ########## @@ -0,0 +1,691 @@ +package trafficstats + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import "database/sql" +import "encoding/json" +import "errors" +import "fmt" +import "net/http" +import "strconv" +import "strings" +import "time" + +import "github.com/apache/trafficcontrol/lib/go-tc" +import "github.com/apache/trafficcontrol/lib/go-rfc" +import "github.com/apache/trafficcontrol/lib/go-log" +import "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/api" +import "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/tenant" + +import influx "github.com/influxdata/influxdb1-client/v2" + +const DEFAULT_INTERVAL = tc.TrafficStatsDuration("1m") + +var metricTypes = map[string]interface{}{ + "kbps": struct{}{}, + "tps_total": struct{}{}, + "tps_2xx": struct{}{}, + "tps_3xx": struct{}{}, + "tps_4xx": struct{}{}, + "tps_5xx": struct{}{}, +} + +var jsonWithRFCTimestamps = rfc.MimeType{ + "application/json", + map[string]string{"timestamp": "rfc"}, +} + +var jsonWithUnixTimestamps = rfc.MimeType{ + "application/json", + map[string]string{"timestamp": "unix"}, +} + +type APIResponse struct { Review comment: Two other options to consider: I think we started leaning toward anonymous structs for responses, in the Client. It's just so repetitive to define them everywhere, for everything. ``` resp := struct{Response tc.TrafficStatsResponse `json:"response"`}{ tc.TrafficStatsResponse{ Source: tc.TRAFFIC_STATS_SOURCE, Version: tc.TRAFFIC_STATS_VERSION, Series: nil, Summary: nil, }, } ``` Or, I'm not sure if we already have one, but a helper func in `lib/go-tc` might be good, that we could then use everywhere: ``` func MakeResponse(v interface{}) interface{} { return struct{Response tc.TrafficStatsResponse `json:"response"`}{v} } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
