forked from vmware-tanzu/sonobuoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial stab at changing snapshot layout
This shifts some of the layout based on the doc changes in vmware-tanzu#43. Also adds some docs explaining the auto-extraction of plugin tar files Changes: - Pod logs moved to `/podlogs` inside the tarball - Query times moved to `/meta/query-time.json` instead of dispersed throughout `/resources/**/results.json` - `/resources/non-ns` is now `/resources/cluster` - `/config.json` is now `/meta/config.json` Signed-off-by: Ken Simon <ninkendo@gmail.com> Signed-off-by: Jesse Hamilton jesse.hamilton@heptio.com Signed-off-by: Jesse Hamilton jesse.hamilton@heptio.com
- Loading branch information
Ken Simon
committed
Aug 24, 2017
1 parent
2141781
commit 3c8feeb
Showing
5 changed files
with
124 additions
and
97 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
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
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,78 @@ | ||
/* | ||
Copyright 2017 Heptio Inc. | ||
Licensed 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. | ||
*/ | ||
|
||
package discovery | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path" | ||
"time" | ||
) | ||
|
||
type QueryRecorder struct { | ||
queries []*queryData | ||
} | ||
|
||
func NewQueryRecorder() *QueryRecorder { | ||
return &QueryRecorder{ | ||
queries: make([]*queryData, 0), | ||
} | ||
} | ||
|
||
// queryData captures the results of the run for post-processing | ||
type queryData struct { | ||
QueryObj string `json:"queryobj,omitempty"` | ||
Namespace string `json:"namespace,omitempty"` | ||
ElapsedTime string `json:"time,omitempty"` | ||
Error error `json:"error,omitempty"` | ||
} | ||
|
||
func (q *QueryRecorder) RecordQuery(name string, namespace string, duration time.Duration, recerr error) { | ||
summary := &queryData{ | ||
QueryObj: name, | ||
Namespace: namespace, | ||
ElapsedTime: duration.String(), | ||
Error: recerr, | ||
} | ||
|
||
q.queries = append(q.queries, summary) | ||
} | ||
|
||
func (q *QueryRecorder) DumpQueryData(filepath string) error { | ||
// Ensure the leading path is created | ||
err := os.MkdirAll(path.Dir(filepath), 0755) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Format the query data as JSON | ||
data, err := json.Marshal(q.queries) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Create the file | ||
f, err := os.Create(filepath) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
|
||
// Write the data | ||
_, err = f.Write(data) | ||
return err | ||
} |