-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Craig O'Donnell
committed
Oct 25, 2023
1 parent
b766b23
commit dc017d6
Showing
6 changed files
with
333 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package reporting | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
var instanceReportMtx = sync.Mutex{} | ||
|
||
type InstanceReport struct { | ||
Events []InstanceReportEvent `json:"events"` | ||
} | ||
|
||
type InstanceReportEvent struct { | ||
ReportedAt int64 `json:"reported_at"` | ||
LicenseID string `json:"license_id"` | ||
InstanceID string `json:"instance_id"` | ||
ClusterID string `json:"cluster_id"` | ||
AppStatus string `json:"app_status"` | ||
IsKurl bool `json:"is_kurl"` | ||
KurlNodeCountTotal int `json:"kurl_node_count_total"` | ||
KurlNodeCountReady int `json:"kurl_node_count_ready"` | ||
K8sVersion string `json:"k8s_version"` | ||
K8sDistribution string `json:"k8s_distribution,omitempty"` | ||
KotsVersion string `json:"kots_version"` | ||
KotsInstallID string `json:"kots_install_id,omitempty"` | ||
KurlInstallID string `json:"kurl_install_id,omitempty"` | ||
IsGitOpsEnabled bool `json:"is_gitops_enabled"` | ||
GitOpsProvider string `json:"gitops_provider"` | ||
DownstreamChannelID string `json:"downstream_channel_id,omitempty"` | ||
DownstreamChannelSequence uint64 `json:"downstream_channel_sequence,omitempty"` | ||
DownstreamChannelName string `json:"downstream_channel_name,omitempty"` | ||
DownstreamSequence *int64 `json:"downstream_sequence,omitempty"` | ||
DownstreamSource string `json:"downstream_source,omitempty"` | ||
InstallStatus string `json:"install_status,omitempty"` | ||
PreflightState string `json:"preflight_state,omitempty"` | ||
SkipPreflights bool `json:"skip_preflights"` | ||
ReplHelmInstalls int `json:"repl_helm_installs"` | ||
NativeHelmInstalls int `json:"native_helm_installs"` | ||
} | ||
|
||
func (r *InstanceReport) GetType() ReportType { | ||
return ReportTypeInstance | ||
} | ||
|
||
func (r *InstanceReport) GetSecretName(appSlug string) string { | ||
return fmt.Sprintf(ReportSecretNameFormat, fmt.Sprintf("%s-%s", appSlug, r.GetType())) | ||
} | ||
|
||
func (r *InstanceReport) GetSecretKey() string { | ||
return ReportSecretKey | ||
} | ||
|
||
func (r *InstanceReport) AppendEvents(report Report) error { | ||
reportToAppend, ok := report.(*InstanceReport) | ||
if !ok { | ||
return errors.Errorf("report is not an instance report") | ||
} | ||
|
||
r.Events = append(r.Events, reportToAppend.Events...) | ||
if len(r.Events) > r.GetEventLimit() { | ||
r.Events = r.Events[len(r.Events)-r.GetEventLimit():] | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *InstanceReport) GetEventLimit() int { | ||
return ReportEventLimit | ||
} | ||
|
||
func (r *InstanceReport) GetMtx() *sync.Mutex { | ||
return &instanceReportMtx | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package reporting | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
var preflightReportMtx = sync.Mutex{} | ||
|
||
type PreflightReport struct { | ||
Events []PreflightReportEvent `json:"events"` | ||
} | ||
|
||
type PreflightReportEvent struct { | ||
ReportedAt int64 `json:"reported_at"` | ||
LicenseID string `json:"license_id"` | ||
InstanceID string `json:"instance_id"` | ||
ClusterID string `json:"cluster_id"` | ||
Sequence int64 `json:"sequence"` | ||
SkipPreflights bool `json:"skip_preflights"` | ||
InstallStatus string `json:"install_status"` | ||
IsCLI bool `json:"is_cli"` | ||
PreflightStatus string `json:"preflight_status"` | ||
AppStatus string `json:"app_status"` | ||
KotsVersion string `json:"kots_version"` | ||
} | ||
|
||
func (r *PreflightReport) GetType() ReportType { | ||
return ReportTypePreflight | ||
} | ||
|
||
func (r *PreflightReport) GetSecretName(appSlug string) string { | ||
return fmt.Sprintf(ReportSecretNameFormat, fmt.Sprintf("%s-%s", appSlug, r.GetType())) | ||
} | ||
|
||
func (r *PreflightReport) GetSecretKey() string { | ||
return ReportSecretKey | ||
} | ||
|
||
func (r *PreflightReport) AppendEvents(report Report) error { | ||
reportToAppend, ok := report.(*PreflightReport) | ||
if !ok { | ||
return errors.Errorf("report is not a preflight report") | ||
} | ||
|
||
r.Events = append(r.Events, reportToAppend.Events...) | ||
if len(r.Events) > r.GetEventLimit() { | ||
r.Events = r.Events[len(r.Events)-r.GetEventLimit():] | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *PreflightReport) GetEventLimit() int { | ||
return ReportEventLimit | ||
} | ||
|
||
func (r *PreflightReport) GetMtx() *sync.Mutex { | ||
return &preflightReportMtx | ||
} |
Oops, something went wrong.