You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/05/03 20:22:17 UTC

[GitHub] [trafficcontrol] srijeet0406 commented on a diff in pull request #6774: CDNi Capacity Update With Scope

srijeet0406 commented on code in PR #6774:
URL: https://github.com/apache/trafficcontrol/pull/6774#discussion_r864163550


##########
traffic_ops/traffic_ops_golang/cdni/capacity.go:
##########
@@ -138,19 +101,27 @@ type CapabilityQueryResponse struct {
 	UCdn string `json:"ucdn" db:"ucdn"`
 }
 
-type TotalLimitsQueryResponse struct {
-	LimitType      string `json:"limit_type" db:"limit_type"`
-	MaximumHard    int64  `json:"maximum_hard" db:"maximum_hard"`
-	MaximumSoft    int64  `json:"maximum_soft" db:"maximum_soft"`
-	TelemetryId    string `json:"telemetry_id" db:"telemetry_id"`
-	TelemetryMetic string `json:"telemetry_metric" db:"telemetry_metric"`
-	UCdn           string `json:"ucdn" db:"ucdn"`
-	Id             string `json:"id" db:"id"`
-	Type           string `json:"type" db:"type"`
-	Name           string `json:"name" db:"name"`
-	CapabilityId   int    `json:"-"`
+type LimitsQueryResponse struct {
+	Scope          *LimitScope `json:"scope,omitempty"`
+	LimitId        string      `json:"limitId" db:"limit_id"`
+	LimitType      string      `json:"limitType" db:"limit_type"`
+	MaximumHard    int64       `json:"maximum_hard" db:"maximum_hard"`
+	MaximumSoft    int64       `json:"maximum_soft" db:"maximum_soft"`
+	TelemetryId    string      `json:"telemetry_id" db:"telemetry_id"`
+	TelemetryMetic string      `json:"telemetry_metric" db:"telemetry_metric"`
+	UCdn           string      `json:"ucdn" db:"ucdn"`
+	Id             string      `json:"id" db:"id"`
+	Type           string      `json:"type" db:"type"`
+	Name           string      `json:"name" db:"name"`
+	CapabilityId   int         `json:"-"`
+}
+
+type LimitScope struct {

Review Comment:
   Could you pls add some GoDocs for this?



##########
traffic_ops/traffic_ops_golang/cdni/capacity.go:
##########
@@ -138,19 +101,27 @@ type CapabilityQueryResponse struct {
 	UCdn string `json:"ucdn" db:"ucdn"`
 }
 
-type TotalLimitsQueryResponse struct {
-	LimitType      string `json:"limit_type" db:"limit_type"`
-	MaximumHard    int64  `json:"maximum_hard" db:"maximum_hard"`
-	MaximumSoft    int64  `json:"maximum_soft" db:"maximum_soft"`
-	TelemetryId    string `json:"telemetry_id" db:"telemetry_id"`
-	TelemetryMetic string `json:"telemetry_metric" db:"telemetry_metric"`
-	UCdn           string `json:"ucdn" db:"ucdn"`
-	Id             string `json:"id" db:"id"`
-	Type           string `json:"type" db:"type"`
-	Name           string `json:"name" db:"name"`
-	CapabilityId   int    `json:"-"`
+type LimitsQueryResponse struct {

Review Comment:
   Could you pls add some GoDocs for this?



##########
traffic_ops/traffic_ops_golang/cdni/shared.go:
##########
@@ -653,9 +629,11 @@ func getTelemetriesMap(tx *sql.Tx) (map[int][]Telemetry, error) {
 	telemetryMap := map[int][]Telemetry{}
 	for rows.Next() {
 		telemetry := Telemetry{}
-		if err := rows.Scan(&telemetry.Id, &telemetry.Type, &telemetry.CapabilityId); err != nil {
+		configUrl := ""
+		if err := rows.Scan(&telemetry.Id, &telemetry.Type, &telemetry.CapabilityId, &configUrl); err != nil {

Review Comment:
   Could we scan it directly into `&telemetry.Configuration.Url` ?



##########
traffic_ops/traffic_ops_golang/cdni/shared.go:
##########
@@ -43,27 +43,19 @@ const (
 	CapabilityQuery   = `SELECT id, type, ucdn FROM cdni_capabilities WHERE type = $1 AND ucdn = $2`
 	AllFootprintQuery = `SELECT footprint_type, footprint_value::text[], capability_id FROM cdni_footprints`
 
-	totalLimitsQuery = `
-SELECT limit_type, maximum_hard, maximum_soft, ctl.telemetry_id, ctl.telemetry_metric, t.id, t.type, tm.name, ctl.capability_id 
-FROM cdni_total_limits AS ctl 
+	limitsQuery = `
+SELECT limit_id, scope_type, scope_value, limit_type, maximum_hard, maximum_soft, ctl.telemetry_id, ctl.telemetry_metric, t.id, t.type, tm.name, ctl.capability_id 
+FROM cdni_limits AS ctl 

Review Comment:
   Should the `AS` be `cl` instead of `ctl` now, since the table name has changed? 



##########
traffic_ops/app/db/migrations/2022041810412200_cdni_capacity_limit_with_scopes.down.sql:
##########
@@ -0,0 +1,51 @@
+/*

Review Comment:
   The timestamps of these migrations need to be changed to be after what we have in master currently.



##########
traffic_ops/traffic_ops_golang/cdni/capacity.go:
##########
@@ -138,19 +101,27 @@ type CapabilityQueryResponse struct {
 	UCdn string `json:"ucdn" db:"ucdn"`
 }
 
-type TotalLimitsQueryResponse struct {
-	LimitType      string `json:"limit_type" db:"limit_type"`
-	MaximumHard    int64  `json:"maximum_hard" db:"maximum_hard"`
-	MaximumSoft    int64  `json:"maximum_soft" db:"maximum_soft"`
-	TelemetryId    string `json:"telemetry_id" db:"telemetry_id"`
-	TelemetryMetic string `json:"telemetry_metric" db:"telemetry_metric"`
-	UCdn           string `json:"ucdn" db:"ucdn"`
-	Id             string `json:"id" db:"id"`
-	Type           string `json:"type" db:"type"`
-	Name           string `json:"name" db:"name"`
-	CapabilityId   int    `json:"-"`
+type LimitsQueryResponse struct {
+	Scope          *LimitScope `json:"scope,omitempty"`
+	LimitId        string      `json:"limitId" db:"limit_id"`
+	LimitType      string      `json:"limitType" db:"limit_type"`
+	MaximumHard    int64       `json:"maximum_hard" db:"maximum_hard"`
+	MaximumSoft    int64       `json:"maximum_soft" db:"maximum_soft"`
+	TelemetryId    string      `json:"telemetry_id" db:"telemetry_id"`
+	TelemetryMetic string      `json:"telemetry_metric" db:"telemetry_metric"`
+	UCdn           string      `json:"ucdn" db:"ucdn"`
+	Id             string      `json:"id" db:"id"`
+	Type           string      `json:"type" db:"type"`
+	Name           string      `json:"name" db:"name"`
+	CapabilityId   int         `json:"-"`
+}
+
+type LimitScope struct {
+	ScopeType  *string  `json:"type" db:"scope_type"`
+	ScopeValue []string `json:"value" db:"scope_value"`
 }
+
 type HostLimitsResponse struct {

Review Comment:
   Could you pls add some GoDocs for this?



##########
traffic_ops/traffic_ops_golang/cdni/shared.go:
##########
@@ -43,27 +43,19 @@ const (
 	CapabilityQuery   = `SELECT id, type, ucdn FROM cdni_capabilities WHERE type = $1 AND ucdn = $2`
 	AllFootprintQuery = `SELECT footprint_type, footprint_value::text[], capability_id FROM cdni_footprints`
 
-	totalLimitsQuery = `
-SELECT limit_type, maximum_hard, maximum_soft, ctl.telemetry_id, ctl.telemetry_metric, t.id, t.type, tm.name, ctl.capability_id 
-FROM cdni_total_limits AS ctl 
+	limitsQuery = `
+SELECT limit_id, scope_type, scope_value, limit_type, maximum_hard, maximum_soft, ctl.telemetry_id, ctl.telemetry_metric, t.id, t.type, tm.name, ctl.capability_id 
+FROM cdni_limits AS ctl 
 LEFT JOIN cdni_telemetry as t ON telemetry_id = t.id 
 LEFT JOIN cdni_telemetry_metrics as tm ON telemetry_metric = tm.name`
 
-	hostLimitsQuery = `
-SELECT limit_type, maximum_hard, maximum_soft, chl.telemetry_id, chl.telemetry_metric, t.id, t.type, tm.name, host, chl.capability_id 
-FROM cdni_host_limits AS chl 
-LEFT JOIN cdni_telemetry as t ON telemetry_id = t.id 
-LEFT JOIN cdni_telemetry_metrics as tm ON telemetry_metric = tm.name 
-ORDER BY host DESC`
-
 	InsertCapabilityUpdateQuery     = `INSERT INTO cdni_capability_updates (ucdn, data, async_status_id, request_type, host) VALUES ($1, $2, $3, $4, $5)`
 	SelectCapabilityUpdateQuery     = `SELECT ucdn, data, async_status_id, request_type, host FROM cdni_capability_updates WHERE id = $1`
 	SelectAllCapabilityUpdatesQuery = `SELECT id, ucdn, data, request_type, host FROM cdni_capability_updates`
 
 	DeleteCapabilityUpdateQuery                    = `DELETE FROM cdni_capability_updates WHERE id = $1`
-	UpdateTotalLimitsByCapabilityAndLimitTypeQuery = `UPDATE cdni_total_limits SET maximum_hard = $1 WHERE capability_id = $2 AND limit_type = $3`
-	UpdateHostLimitsByCapabilityAndLimitTypeQuery  = `UPDATE cdni_host_limits SET maximum_hard = $1 WHERE capability_id = $2 AND limit_type = $3 AND host = $4`
-	hostQuery                                      = `SELECT count(*) FROM cdni_host_limits WHERE host = $1`
+	UpdateTotalLimitsByCapabilityAndLimitTypeQuery = `UPDATE cdni_limits SET maximum_hard = $1 WHERE capability_id = $2 AND limit_type = $3`

Review Comment:
   Should this just be called `UpdateLimitsByCapabilityAndLimitTypeQuery` now?



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org