-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_project.go
87 lines (77 loc) · 3.92 KB
/
report_project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
*
* Copyright 2018-2020 SAP SE
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You should have received a copy of the License along with this
* program. If not, 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.
*
*******************************************************************************/
package limesresources
import (
"encoding/json"
"github.com/sapcc/go-api-declarations/limes"
)
// ProjectReport contains all data about resource usage in a project.
type ProjectReport struct {
limes.ProjectInfo
Services ProjectServiceReports `json:"services"`
}
// ProjectServiceReport is a substructure of ProjectReport containing data for
// a single backend service.
type ProjectServiceReport struct {
limes.ServiceInfo
Resources ProjectResourceReports `json:"resources"`
ScrapedAt *limes.UnixEncodedTime `json:"scraped_at,omitempty"`
}
// ProjectResourceReport is a substructure of ProjectReport containing data for
// a single resource.
type ProjectResourceReport struct {
// Several fields are pointers to values to enable precise control over which fields are rendered in output.
ResourceInfo
QuotaDistributionModel QuotaDistributionModel `json:"quota_distribution_model,omitempty"`
CommitmentConfig *CommitmentConfiguration `json:"commitment_config,omitempty"`
// PerAZ is only rendered by Limes when the v2 API feature preview is enabled.
PerAZ ProjectAZResourceReports `json:"per_az,omitempty"`
Quota *uint64 `json:"quota,omitempty"`
UsableQuota *uint64 `json:"usable_quota,omitempty"`
MaxQuota *uint64 `json:"max_quota,omitempty"` // refers to max_quota constraint maintained via API
Usage uint64 `json:"usage"`
PhysicalUsage *uint64 `json:"physical_usage,omitempty"`
BackendQuota *int64 `json:"backend_quota,omitempty"`
Subresources json.RawMessage `json:"subresources,omitempty"`
}
// ProjectAZResourceReport is a substructure of ProjectResourceReport containing
// quota and usage data for a single resource in an availability zone.
//
// This type is part of the v2 API feature preview.
type ProjectAZResourceReport struct {
Quota *uint64 `json:"quota,omitempty"`
// The keys for these maps must be commitment durations as accepted
// by func ParseCommitmentDuration. We cannot use type CommitmentDuration
// directly here because Go does not allow struct types as map keys.
Committed map[string]uint64 `json:"committed,omitempty"`
PendingCommitments map[string]uint64 `json:"pending_commitments,omitempty"`
PlannedCommitments map[string]uint64 `json:"planned_commitments,omitempty"`
Usage uint64 `json:"usage"`
PhysicalUsage *uint64 `json:"physical_usage,omitempty"`
Subresources json.RawMessage `json:"subresources,omitempty"`
}
// ProjectServiceReports provides fast lookup of services using a map, but serializes
// to JSON as a list.
type ProjectServiceReports map[limes.ServiceType]*ProjectServiceReport
// ProjectResourceReports provides fast lookup of resources using a map, but serializes
// to JSON as a list.
type ProjectResourceReports map[ResourceName]*ProjectResourceReport
// ProjectAZResourceReport is a substructure of ProjectResourceReport that breaks
// down quota and usage data for a single resource by availability zone.
type ProjectAZResourceReports map[limes.AvailabilityZone]*ProjectAZResourceReport