Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release 4.6] Bug 1942457: Adds metadata to the IO archive #382

Merged
merged 1 commit into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 180 additions & 0 deletions docs/insights-archive-sample/insights-operator/gathers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"status_reports": [
{
"name": "clusterconfig.GatherPodDisruptionBudgets",
"duration_in_ms": 123,
"records_count": 2,
"errors": null
},
{
"name": "clusterconfig.GatherMostRecentMetrics",
"duration_in_ms": 0,
"records_count": 0,
"errors": null
},
{
"name": "clusterconfig.GatherClusterOperators",
"duration_in_ms": 3365,
"records_count": 50,
"errors": null
},
{
"name": "clusterconfig.GatherContainerImages",
"duration_in_ms": 368,
"records_count": 13,
"errors": null
},
{
"name": "clusterconfig.GatherNodes",
"duration_in_ms": 154,
"records_count": 6,
"errors": null
},
{
"name": "clusterconfig.GatherConfigMaps",
"duration_in_ms": 260,
"records_count": 11,
"errors": null
},
{
"name": "clusterconfig.GatherClusterVersion",
"duration_in_ms": 130,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterID",
"duration_in_ms": 0,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterInfrastructure",
"duration_in_ms": 125,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterNetwork",
"duration_in_ms": 125,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterAuthentication",
"duration_in_ms": 140,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterImageRegistry",
"duration_in_ms": 131,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterImagePruner",
"duration_in_ms": 128,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterFeatureGates",
"duration_in_ms": 136,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterOAuth",
"duration_in_ms": 124,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterIngress",
"duration_in_ms": 128,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherClusterProxy",
"duration_in_ms": 125,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherCertificateSigningRequests",
"duration_in_ms": 124,
"records_count": 0,
"errors": null
},
{
"name": "clusterconfig.GatherCRD",
"duration_in_ms": 268,
"records_count": 2,
"errors": null
},
{
"name": "clusterconfig.GatherHostSubnet",
"duration_in_ms": 130,
"records_count": 6,
"errors": null
},
{
"name": "clusterconfig.GatherMachineSet",
"duration_in_ms": 137,
"records_count": 3,
"errors": null
},
{
"name": "clusterconfig.GatherMachineConfigPool",
"duration_in_ms": 130,
"records_count": 2,
"errors": null
},
{
"name": "clusterconfig.GatherInstallPlans",
"duration_in_ms": 10278,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherContainerRuntimeConfig",
"duration_in_ms": 129,
"records_count": 0,
"errors": null
},
{
"name": "clusterconfig.GatherOpenshiftSDNLogs",
"duration_in_ms": 6843,
"records_count": 0,
"errors": null
},
{
"name": "clusterconfig.GatherNetNamespace",
"duration_in_ms": 255,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherServiceAccounts",
"duration_in_ms": 11544,
"records_count": 1,
"errors": null
},
{
"name": "clusterconfig.GatherSAPConfig",
"duration_in_ms": 121,
"records_count": 0,
"errors": null
},
{
"name": "clusterconfig.GatherOpenshiftSDNControllerLogs",
"duration_in_ms": 549,
"records_count": 0,
"errors": null
}
],
"memory_alloc_bytes": 11303784,
"uptime_seconds": 36.113
}
51 changes: 50 additions & 1 deletion pkg/record/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,41 @@ func (m JSONMarshaller) GetExtension() string {
return "json"
}

type gatherMetadata struct {
StatusReports []gatherStatusReport `json:"status_reports"`
MemoryAlloc uint64 `json:"memory_alloc_bytes"`
Uptime float64 `json:"uptime_seconds"`
}

type gatherStatusReport struct {
Name string `json:"name"`
Duration time.Duration `json:"duration_in_ms"`
RecordsCount int `json:"records_count"`
Errors []string `json:"errors"`
}

var startTime time.Time

// Collect is a helper for gathering a large set of records from generic functions.
func Collect(ctx context.Context, recorder Interface, bulkFns ...func() ([]Record, []error)) error {
var errors []string
var statusReports []gatherStatusReport

if startTime.IsZero() {
startTime = time.Now()
}

for _, bulkFn := range bulkFns {
klog.V(5).Infof("Gathering %s", runtime.FuncForPC(reflect.ValueOf(bulkFn).Pointer()).Name())
gatherName := runtime.FuncForPC(reflect.ValueOf(bulkFn).Pointer()).Name()
klog.V(5).Infof("Gathering %s", gatherName)
start := time.Now()
records, errs := bulkFn()

shortName := strings.Replace(gatherName, "github.com/openshift/insights-operator/pkg/gather/", "", 1)
shortName = strings.Replace(shortName, ".func1", "", 1)
elapsed := time.Since(start).Truncate(time.Millisecond)
statusReport := gatherStatusReport{shortName, time.Duration(elapsed.Milliseconds()), len(records), extractErrors(errs)}
statusReports = append(statusReports, statusReport)
for _, err := range errs {
errors = append(errors, err.Error())
}
Expand All @@ -67,6 +96,10 @@ func Collect(ctx context.Context, recorder Interface, bulkFns ...func() ([]Recor
return err
}
}
// Creates the gathering performance report
if err := recordGatherReport(recorder, statusReports); err != nil {
errors = append(errors, fmt.Sprintf("unable to record io status reports: %v", err))
}
if len(errors) > 0 {
sort.Strings(errors)
errors = uniqueStrings(errors)
Expand All @@ -75,6 +108,14 @@ func Collect(ctx context.Context, recorder Interface, bulkFns ...func() ([]Recor
return nil
}

func recordGatherReport(recorder Interface, report []gatherStatusReport) error {
var m runtime.MemStats
runtime.ReadMemStats(&m)
metadata := gatherMetadata{report, m.HeapAlloc, time.Since(startTime).Truncate(time.Millisecond).Seconds()}
r := Record{Name: "insights-operator/gathers", Item: JSONMarshaller{Object: metadata}}
return recorder.Record(r)
}

func uniqueStrings(arr []string) []string {
var last int
for i := 1; i < len(arr); i++ {
Expand All @@ -91,3 +132,11 @@ func uniqueStrings(arr []string) []string {
}
return arr[:last]
}

func extractErrors(errors []error) []string {
var errStrings []string
for _, err := range errors {
errStrings = append(errStrings, err.Error())
}
return errStrings
}