Add Zygostates hardware qualification runner
This commit is contained in:
commit
65541dc8eb
26 changed files with 2889 additions and 0 deletions
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/zygostates
|
||||
/bin/
|
||||
/zygostates.yaml
|
||||
docs/journal
|
||||
scratchpad
|
||||
1
.mdformat.toml
Normal file
1
.mdformat.toml
Normal file
|
|
@ -0,0 +1 @@
|
|||
wrap = "no"
|
||||
202
LICENSE
Normal file
202
LICENSE
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
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.
|
||||
216
NOTICE
Normal file
216
NOTICE
Normal file
|
|
@ -0,0 +1,216 @@
|
|||
Zygostates
|
||||
Copyright 2026 ms2k
|
||||
|
||||
Licensed under the Apache License, Version 2.0; see LICENSE.
|
||||
|
||||
Third-party components included in the binary retain their respective licenses and notices.
|
||||
|
||||
|
||||
github.com/aws/aws-sdk-go-v2 — NOTICE.txt
|
||||
=========================================
|
||||
|
||||
AWS SDK for Go
|
||||
Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
Copyright 2014-2015 Stripe, Inc.
|
||||
|
||||
|
||||
github.com/aws/smithy-go — NOTICE
|
||||
=================================
|
||||
|
||||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
|
||||
|
||||
gopkg.in/yaml.v3 — LICENSE
|
||||
==========================
|
||||
|
||||
|
||||
This project is covered by two different licenses: MIT and Apache.
|
||||
|
||||
#### MIT License ####
|
||||
|
||||
The following files were ported to Go from C files of libyaml, and thus
|
||||
are still covered by their original MIT license, with the additional
|
||||
copyright staring in 2011 when the project was ported over:
|
||||
|
||||
apic.go emitterc.go parserc.go readerc.go scannerc.go
|
||||
writerc.go yamlh.go yamlprivateh.go
|
||||
|
||||
Copyright (c) 2006-2010 Kirill Simonov
|
||||
Copyright (c) 2006-2011 Kirill Simonov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
### Apache License ###
|
||||
|
||||
All the remaining project files are covered by the Apache license:
|
||||
|
||||
Copyright (c) 2011-2019 Canonical Ltd
|
||||
|
||||
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.
|
||||
|
||||
|
||||
gopkg.in/yaml.v3 — NOTICE
|
||||
=========================
|
||||
|
||||
Copyright 2011-2016 Canonical Ltd.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
golang.org/x/sys — LICENSE
|
||||
==========================
|
||||
|
||||
Copyright 2009 The Go Authors.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
gonum.org/v1/gonum — LICENSE
|
||||
============================
|
||||
|
||||
Copyright ©2013 The Gonum Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Gonum project nor the names of its authors and
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Go standard library and runtime — LICENSE
|
||||
=========================================
|
||||
|
||||
Copyright 2009 The Go Authors.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
AWS SDK and Smithy singleflight implementations — LICENSE
|
||||
=========================================================
|
||||
|
||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
9
README.md
Normal file
9
README.md
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# Zygostates
|
||||
|
||||
Linux CPU and memory qualification with telemetry and optional S3 upload.
|
||||
|
||||
Edit `example.yaml`, then run `sudo zygostates -config example.yaml`.
|
||||
|
||||
Toolchain: Go 1.26.7.
|
||||
|
||||
[Apache 2.0](LICENSE) · [Third-party notices](NOTICE)
|
||||
23
cmd/zygostates/main.go
Normal file
23
cmd/zygostates/main.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"zygostates/internal/zygostates"
|
||||
)
|
||||
|
||||
func main() {
|
||||
configPath := flag.String("config", "zygostates.yaml", "configuration file")
|
||||
flag.Parse()
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
if err := zygostates.Run(ctx, *configPath); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
16
example.yaml
Normal file
16
example.yaml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
version: 1
|
||||
repeat: 16
|
||||
sequence:
|
||||
- [mixed, 300]
|
||||
- [idle, 180]
|
||||
- [fft, 120]
|
||||
- [idle, 300]
|
||||
- [per-core, 60]
|
||||
- [idle, 420]
|
||||
artifacts:
|
||||
directory: /var/lib/zygostates/runs
|
||||
sample_interval_seconds: 15
|
||||
workloads:
|
||||
memory_fraction: 0.5
|
||||
fft_size: 65536
|
||||
matrix_size: 256
|
||||
31
go.mod
Normal file
31
go.mod
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
module zygostates
|
||||
|
||||
go 1.26.4
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go-v2 v1.41.1
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.7
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.1
|
||||
golang.org/x/sys v0.46.0
|
||||
gonum.org/v1/gonum v0.16.0
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.17 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.16 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.7 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.17 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.16 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.5 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.9 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.13 // indirect
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 // indirect
|
||||
github.com/aws/smithy-go v1.24.0 // indirect
|
||||
)
|
||||
46
go.sum
Normal file
46
go.sum
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
github.com/aws/aws-sdk-go-v2 v1.41.1 h1:ABlyEARCDLN034NhxlRUSZr4l71mh+T5KAeGh6cerhU=
|
||||
github.com/aws/aws-sdk-go-v2 v1.41.1/go.mod h1:MayyLB8y+buD9hZqkCW3kX1AKq07Y5pXxtgB+rRFhz0=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4 h1:489krEF9xIGkOaaX3CE/Be2uWjiXrkCH6gUX+bZA/BU=
|
||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.4/go.mod h1:IOAPF6oT9KCsceNTvvYMNHy0+kMF8akOjeDvPENWxp4=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.7 h1:vxUyWGUwmkQ2g19n7JY/9YL8MfAIl7bTesIUykECXmY=
|
||||
github.com/aws/aws-sdk-go-v2/config v1.32.7/go.mod h1:2/Qm5vKUU/r7Y+zUk/Ptt2MDAEKAfUtKc1+3U1Mo3oY=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.7 h1:tHK47VqqtJxOymRrNtUXN5SP/zUTvZKeLx4tH6PGQc8=
|
||||
github.com/aws/aws-sdk-go-v2/credentials v1.19.7/go.mod h1:qOZk8sPDrxhf+4Wf4oT2urYJrYt3RejHSzgAquYeppw=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.17 h1:I0GyV8wiYrP8XpA70g1HBcQO1JlQxCMTW9npl5UbDHY=
|
||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.17/go.mod h1:tyw7BOl5bBe/oqvoIeECFJjMdzXoa/dfVz3QQ5lgHGA=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17 h1:xOLELNKGp2vsiteLsvLPwxC+mYmO6OZ8PYgiuPJzF8U=
|
||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.17/go.mod h1:5M5CI3D12dNOtH3/mk6minaRwI2/37ifCURZISxA/IQ=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17 h1:WWLqlh79iO48yLkj1v3ISRNiv+3KdQoZ6JWyfcsyQik=
|
||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.17/go.mod h1:EhG22vHRrvF8oXSTYStZhJc1aUgKtnJe+aOiFEV90cM=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk=
|
||||
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.16 h1:CjMzUs78RDDv4ROu3JnJn/Ig1r6ZD7/T2DXLLRpejic=
|
||||
github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.16/go.mod h1:uVW4OLBqbJXSHJYA9svT9BluSvvwbzLQ2Crf6UPzR3c=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4 h1:0ryTNEdJbzUCEWkVXEXoqlXV72J5keC1GvILMOuD00E=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.4/go.mod h1:HQ4qwNZh32C3CBeO6iJLQlgtMzqeG17ziAA/3KDJFow=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.7 h1:DIBqIrJ7hv+e4CmIk2z3pyKT+3B6qVMgRsawHiR3qso=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.7/go.mod h1:vLm00xmBke75UmpNvOcZQ/Q30ZFjbczeLFqGx5urmGo=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.17 h1:RuNSMoozM8oXlgLG/n6WLaFGoea7/CddrCfIiSA+xdY=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.17/go.mod h1:F2xxQ9TZz5gDWsclCtPQscGpP0VUOc8RqgFM3vDENmU=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.16 h1:NSbvS17MlI2lurYgXnCOLvCFX38sBW4eiVER7+kkgsU=
|
||||
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.16/go.mod h1:SwT8Tmqd4sA6G1qaGdzWCJN99bUmPGHfRwwq3G5Qb+A=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.1 h1:5FhzzN6JmlGQF6c04kDIb5KNGm6KnNdLISNrfivIhHg=
|
||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.93.1/go.mod h1:79S2BdqCJpScXZA2y+cpZuocWsjGjJINyXnOsf5DTz8=
|
||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.5 h1:VrhDvQib/i0lxvr3zqlUwLwJP4fpmpyD9wYG1vfSu+Y=
|
||||
github.com/aws/aws-sdk-go-v2/service/signin v1.0.5/go.mod h1:k029+U8SY30/3/ras4G/Fnv/b88N4mAfliNn08Dem4M=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.9 h1:v6EiMvhEYBoHABfbGB4alOYmCIrcgyPPiBE1wZAEbqk=
|
||||
github.com/aws/aws-sdk-go-v2/service/sso v1.30.9/go.mod h1:yifAsgBxgJWn3ggx70A3urX2AN49Y5sJTD1UQFlfqBw=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.13 h1:gd84Omyu9JLriJVCbGApcLzVR3XtmC4ZDPcAI6Ftvds=
|
||||
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.13/go.mod h1:sTGThjphYE4Ohw8vJiRStAcu3rbjtXRsdNB0TvZ5wwo=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6 h1:5fFjR/ToSOzB2OQ/XqWpZBmNvmP/pJ1jOWYlFDJTjRQ=
|
||||
github.com/aws/aws-sdk-go-v2/service/sts v1.41.6/go.mod h1:qgFDZQSD/Kys7nJnVqYlWKnh0SSdMjAi0uSwON4wgYQ=
|
||||
github.com/aws/smithy-go v1.24.0 h1:LpilSUItNPFr1eY85RYgTIg5eIEPtvFbskaFcmmIUnk=
|
||||
github.com/aws/smithy-go v1.24.0/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
|
||||
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
||||
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
117
internal/zygostates/app.go
Normal file
117
internal/zygostates/app.go
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Run(ctx context.Context, configPath string) error {
|
||||
config, configContents, err := loadConfig(configPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load config: %w", err)
|
||||
}
|
||||
identity, err := readHardwareIdentity("/sys/class/dmi/id")
|
||||
if err != nil {
|
||||
return fmt.Errorf("read hardware identity: %w", err)
|
||||
}
|
||||
workloads, err := buildWorkloads(config.Workloads)
|
||||
if err != nil {
|
||||
return fmt.Errorf("prepare workloads: %w", err)
|
||||
}
|
||||
started := time.Now().UTC()
|
||||
runID := started.Format("20060102T150405.000000000Z")
|
||||
artifacts, err := newArtifactStore(config.Artifacts.Directory, runID, configContents, systemMetadata(identity))
|
||||
if err != nil {
|
||||
return fmt.Errorf("create artifacts: %w", err)
|
||||
}
|
||||
defer func() { _ = artifacts.Close() }()
|
||||
if err := artifacts.AppendEvent(Event{Timestamp: started, Type: "run-start", Fields: map[string]any{"run_id": runID, "identity": identity.Key}}); err != nil {
|
||||
return err
|
||||
}
|
||||
var phase atomic.Value
|
||||
phase.Store("preflight")
|
||||
telemetryContext, stopTelemetry := context.WithCancel(context.Background())
|
||||
telemetry := startTelemetry(telemetryContext, artifacts, &phase, time.Duration(config.Artifacts.SampleIntervalSeconds)*time.Second, &TelemetryCollector{procRoot: "/proc", sysRoot: "/sys"})
|
||||
|
||||
var uploader *Uploader
|
||||
var stopPeriodic context.CancelFunc
|
||||
var periodicWait interface{ Wait() }
|
||||
if config.Upload.Bucket != "" {
|
||||
objectStore, err := newS3ObjectStore(ctx, config.Upload)
|
||||
if err != nil {
|
||||
stopTelemetry()
|
||||
telemetry.Wait()
|
||||
result := RunResult{RunID: runID, Identity: identity.Key, StartedAt: started, CompletedAt: time.Now().UTC(), Status: "failed", Error: err.Error()}
|
||||
if writeErr := artifacts.WriteResult(result); writeErr != nil {
|
||||
return writeErr
|
||||
}
|
||||
return err
|
||||
}
|
||||
uploader = newUploader(objectStore, artifacts, config.Upload, identity.Key, runID)
|
||||
preflightContext, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
_, err = uploader.Upload(preflightContext)
|
||||
cancel()
|
||||
if err != nil {
|
||||
stopTelemetry()
|
||||
telemetry.Wait()
|
||||
result := RunResult{RunID: runID, Identity: identity.Key, StartedAt: started, CompletedAt: time.Now().UTC(), Status: "failed", Error: "S3 preflight: " + err.Error(), UploadError: err.Error()}
|
||||
_ = artifacts.WriteResult(result)
|
||||
return fmt.Errorf("S3 preflight: %w", err)
|
||||
}
|
||||
periodicContext, cancelPeriodic := context.WithCancel(context.Background())
|
||||
stopPeriodic = cancelPeriodic
|
||||
periodic := &PeriodicUploader{uploader: uploader, interval: time.Duration(config.Upload.IntervalSeconds) * time.Second, store: artifacts}
|
||||
periodicWait = periodic.Start(periodicContext)
|
||||
}
|
||||
|
||||
runner := Runner{config: config, workloads: workloads, store: artifacts, phase: &phase, now: func() time.Time { return time.Now().UTC() }}
|
||||
runErr := runner.Run(ctx)
|
||||
if stopPeriodic != nil {
|
||||
stopPeriodic()
|
||||
periodicWait.Wait()
|
||||
}
|
||||
stopTelemetry()
|
||||
telemetry.Wait()
|
||||
completed := time.Now().UTC()
|
||||
status := "passed"
|
||||
if runErr != nil {
|
||||
status = "failed"
|
||||
if errors.Is(runErr, context.Canceled) {
|
||||
status = "interrupted"
|
||||
}
|
||||
}
|
||||
result := RunResult{RunID: runID, Identity: identity.Key, StartedAt: started, CompletedAt: completed, Status: status}
|
||||
if runErr != nil {
|
||||
result.Error = runErr.Error()
|
||||
}
|
||||
fields := map[string]any{"status": status, "elapsed_seconds": completed.Sub(started).Seconds()}
|
||||
if runErr != nil {
|
||||
fields["error"] = runErr.Error()
|
||||
}
|
||||
if err := artifacts.AppendEvent(Event{Timestamp: completed, Type: "run-complete", Fields: fields}); err != nil && runErr == nil {
|
||||
runErr = err
|
||||
result.Status = "failed"
|
||||
result.Error = err.Error()
|
||||
}
|
||||
if err := artifacts.WriteResult(result); err != nil {
|
||||
return err
|
||||
}
|
||||
if uploader != nil {
|
||||
finalContext, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second)
|
||||
_, uploadErr := uploader.Upload(finalContext)
|
||||
cancel()
|
||||
if uploadErr != nil {
|
||||
result.UploadError = uploadErr.Error()
|
||||
if err := artifacts.WriteResult(result); err != nil {
|
||||
return err
|
||||
}
|
||||
if runErr == nil {
|
||||
runErr = fmt.Errorf("final upload: %w", uploadErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
return runErr
|
||||
}
|
||||
165
internal/zygostates/artifacts.go
Normal file
165
internal/zygostates/artifacts.go
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Type string `json:"type"`
|
||||
Fields map[string]any `json:"fields,omitempty"`
|
||||
}
|
||||
|
||||
type RunResult struct {
|
||||
RunID string `json:"run_id"`
|
||||
Identity string `json:"identity"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
CompletedAt time.Time `json:"completed_at"`
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
UploadError string `json:"upload_error,omitempty"`
|
||||
}
|
||||
|
||||
type FileSnapshot struct {
|
||||
Name string
|
||||
Contents []byte
|
||||
}
|
||||
|
||||
type ArtifactStore struct {
|
||||
directory string
|
||||
events *os.File
|
||||
telemetry *os.File
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func newArtifactStore(root, runID string, configContents []byte, metadata SystemMetadata) (*ArtifactStore, error) {
|
||||
directory := filepath.Join(root, runID)
|
||||
if err := os.MkdirAll(directory, 0o750); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(directory, "config.yaml"), configContents, 0o640); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := writeJSONAtomic(filepath.Join(directory, "metadata.json"), metadata); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
events, err := os.OpenFile(filepath.Join(directory, "events.ndjson"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o640)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
telemetry, err := os.OpenFile(filepath.Join(directory, "telemetry.ndjson"), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o640)
|
||||
if err != nil {
|
||||
_ = events.Close()
|
||||
return nil, err
|
||||
}
|
||||
return &ArtifactStore{directory: directory, events: events, telemetry: telemetry}, nil
|
||||
}
|
||||
|
||||
func (s *ArtifactStore) Directory() string {
|
||||
return s.directory
|
||||
}
|
||||
|
||||
func (s *ArtifactStore) AppendEvent(event Event) error {
|
||||
return s.appendJSON(s.events, event)
|
||||
}
|
||||
|
||||
func (s *ArtifactStore) AppendTelemetry(sample TelemetrySample) error {
|
||||
return s.appendJSON(s.telemetry, sample)
|
||||
}
|
||||
|
||||
func (s *ArtifactStore) appendJSON(file *os.File, value any) error {
|
||||
contents, err := json.Marshal(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
contents = append(contents, '\n')
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
_, err = file.Write(contents)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *ArtifactStore) WriteResult(result RunResult) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return writeJSONAtomic(filepath.Join(s.directory, "result.json"), result)
|
||||
}
|
||||
|
||||
func (s *ArtifactStore) Snapshots() ([]FileSnapshot, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if err := s.events.Sync(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := s.telemetry.Sync(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
entries, err := os.ReadDir(s.directory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
snapshots := make([]FileSnapshot, 0, len(entries))
|
||||
for _, entry := range entries {
|
||||
if !entry.Type().IsRegular() {
|
||||
continue
|
||||
}
|
||||
contents, err := os.ReadFile(filepath.Join(s.directory, entry.Name()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read %s: %w", entry.Name(), err)
|
||||
}
|
||||
snapshots = append(snapshots, FileSnapshot{Name: entry.Name(), Contents: contents})
|
||||
}
|
||||
sort.Slice(snapshots, func(left, right int) bool { return snapshots[left].Name < snapshots[right].Name })
|
||||
return snapshots, nil
|
||||
}
|
||||
|
||||
func (s *ArtifactStore) Close() error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
var first error
|
||||
for _, file := range []*os.File{s.events, s.telemetry} {
|
||||
if err := file.Sync(); err != nil && first == nil {
|
||||
first = err
|
||||
}
|
||||
if err := file.Close(); err != nil && first == nil {
|
||||
first = err
|
||||
}
|
||||
}
|
||||
return first
|
||||
}
|
||||
|
||||
func writeJSONAtomic(path string, value any) error {
|
||||
contents, err := json.MarshalIndent(value, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
contents = append(contents, '\n')
|
||||
temporary, err := os.CreateTemp(filepath.Dir(path), ".zygostates-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
temporaryPath := temporary.Name()
|
||||
defer func() { _ = os.Remove(temporaryPath) }()
|
||||
if err := temporary.Chmod(0o640); err != nil {
|
||||
_ = temporary.Close()
|
||||
return err
|
||||
}
|
||||
if _, err := temporary.Write(contents); err != nil {
|
||||
_ = temporary.Close()
|
||||
return err
|
||||
}
|
||||
if err := temporary.Sync(); err != nil {
|
||||
_ = temporary.Close()
|
||||
return err
|
||||
}
|
||||
if err := temporary.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(temporaryPath, path)
|
||||
}
|
||||
43
internal/zygostates/artifacts_test.go
Normal file
43
internal/zygostates/artifacts_test.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestArtifactStoreProducesParseableDurableFiles(t *testing.T) {
|
||||
store := testArtifactStore(t)
|
||||
if err := store.AppendEvent(Event{Timestamp: time.Unix(1, 0), Type: "test", Fields: map[string]any{"value": 1}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.AppendTelemetry(TelemetrySample{Timestamp: time.Unix(2, 0), Phase: "test"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := RunResult{RunID: "run", Identity: "system", Status: "passed"}
|
||||
if err := store.WriteResult(result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
snapshots, err := store.Snapshots()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
files := make(map[string][]byte)
|
||||
for _, snapshot := range snapshots {
|
||||
files[snapshot.Name] = snapshot.Contents
|
||||
}
|
||||
for _, name := range []string{"config.yaml", "events.ndjson", "metadata.json", "result.json", "telemetry.ndjson"} {
|
||||
if _, found := files[name]; !found {
|
||||
t.Fatalf("missing %s", name)
|
||||
}
|
||||
}
|
||||
var decoded RunResult
|
||||
if err := json.Unmarshal(files["result.json"], &decoded); err != nil || decoded.Status != "passed" {
|
||||
t.Fatalf("result=%#v err=%v", decoded, err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(store.Directory(), "result.json")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
158
internal/zygostates/config.go
Normal file
158
internal/zygostates/config.go
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Step struct {
|
||||
Workload string
|
||||
Seconds int
|
||||
}
|
||||
|
||||
func (s *Step) UnmarshalYAML(node *yaml.Node) error {
|
||||
if node.Kind != yaml.SequenceNode || len(node.Content) != 2 {
|
||||
return fmt.Errorf("step must be [workload, seconds]")
|
||||
}
|
||||
if err := node.Content[0].Decode(&s.Workload); err != nil {
|
||||
return fmt.Errorf("decode workload: %w", err)
|
||||
}
|
||||
if err := node.Content[1].Decode(&s.Seconds); err != nil {
|
||||
return fmt.Errorf("decode seconds: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type ArtifactConfig struct {
|
||||
Directory string `yaml:"directory"`
|
||||
SampleIntervalSeconds int `yaml:"sample_interval_seconds"`
|
||||
}
|
||||
|
||||
type UploadConfig struct {
|
||||
Endpoint string `yaml:"endpoint"`
|
||||
Region string `yaml:"region"`
|
||||
Bucket string `yaml:"bucket"`
|
||||
Prefix string `yaml:"prefix"`
|
||||
IntervalSeconds int `yaml:"interval_seconds"`
|
||||
}
|
||||
|
||||
type WorkloadConfig struct {
|
||||
MemoryFraction float64 `yaml:"memory_fraction"`
|
||||
FFTSize int `yaml:"fft_size"`
|
||||
MatrixSize int `yaml:"matrix_size"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Version int `yaml:"version"`
|
||||
Repeat int `yaml:"repeat"`
|
||||
Sequence []Step `yaml:"sequence"`
|
||||
Artifacts ArtifactConfig `yaml:"artifacts"`
|
||||
Upload UploadConfig `yaml:"upload"`
|
||||
Workloads WorkloadConfig `yaml:"workloads"`
|
||||
}
|
||||
|
||||
var workloadNames = map[string]struct{}{
|
||||
"cpu": {},
|
||||
"fft": {},
|
||||
"idle": {},
|
||||
"matrix": {},
|
||||
"memory": {},
|
||||
"mixed": {},
|
||||
"per-core": {},
|
||||
}
|
||||
|
||||
func loadConfig(path string) (Config, []byte, error) {
|
||||
contents, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return Config{}, nil, err
|
||||
}
|
||||
var config Config
|
||||
decoder := yaml.NewDecoder(bytes.NewReader(contents))
|
||||
decoder.KnownFields(true)
|
||||
if err := decoder.Decode(&config); err != nil {
|
||||
return Config{}, nil, err
|
||||
}
|
||||
if err := config.applyDefaultsAndValidate(); err != nil {
|
||||
return Config{}, nil, err
|
||||
}
|
||||
return config, contents, nil
|
||||
}
|
||||
|
||||
func (c *Config) applyDefaultsAndValidate() error {
|
||||
if c.Version != 1 {
|
||||
return fmt.Errorf("version must be 1")
|
||||
}
|
||||
if c.Repeat < 1 {
|
||||
return fmt.Errorf("repeat must be positive")
|
||||
}
|
||||
if len(c.Sequence) == 0 {
|
||||
return fmt.Errorf("sequence must not be empty")
|
||||
}
|
||||
for index, step := range c.Sequence {
|
||||
if _, found := workloadNames[step.Workload]; !found {
|
||||
return fmt.Errorf("sequence[%d]: unknown workload %q", index, step.Workload)
|
||||
}
|
||||
if step.Seconds < 1 {
|
||||
return fmt.Errorf("sequence[%d]: seconds must be positive", index)
|
||||
}
|
||||
}
|
||||
if c.Artifacts.Directory == "" {
|
||||
c.Artifacts.Directory = "/var/lib/zygostates/runs"
|
||||
}
|
||||
if !filepath.IsAbs(c.Artifacts.Directory) {
|
||||
return fmt.Errorf("artifacts.directory must be absolute")
|
||||
}
|
||||
if c.Artifacts.SampleIntervalSeconds == 0 {
|
||||
c.Artifacts.SampleIntervalSeconds = 15
|
||||
}
|
||||
if c.Artifacts.SampleIntervalSeconds < 1 {
|
||||
return fmt.Errorf("artifacts.sample_interval_seconds must be positive")
|
||||
}
|
||||
if c.Workloads.MemoryFraction == 0 {
|
||||
c.Workloads.MemoryFraction = 0.5
|
||||
}
|
||||
if c.Workloads.MemoryFraction <= 0 || c.Workloads.MemoryFraction > 0.9 {
|
||||
return fmt.Errorf("workloads.memory_fraction must be greater than 0 and at most 0.9")
|
||||
}
|
||||
if c.Workloads.FFTSize == 0 {
|
||||
c.Workloads.FFTSize = 65536
|
||||
}
|
||||
if c.Workloads.FFTSize < 2 {
|
||||
return fmt.Errorf("workloads.fft_size must be at least 2")
|
||||
}
|
||||
if c.Workloads.MatrixSize == 0 {
|
||||
c.Workloads.MatrixSize = 256
|
||||
}
|
||||
if c.Workloads.MatrixSize < 2 {
|
||||
return fmt.Errorf("workloads.matrix_size must be at least 2")
|
||||
}
|
||||
uploadConfigured := c.Upload.Endpoint != "" || c.Upload.Region != "" || c.Upload.Bucket != "" || c.Upload.Prefix != "" || c.Upload.IntervalSeconds != 0
|
||||
if !uploadConfigured {
|
||||
return nil
|
||||
}
|
||||
if c.Upload.Bucket == "" {
|
||||
return fmt.Errorf("upload.bucket is required when upload is configured")
|
||||
}
|
||||
if c.Upload.Region == "" {
|
||||
c.Upload.Region = "us-east-1"
|
||||
}
|
||||
if c.Upload.Prefix == "" {
|
||||
c.Upload.Prefix = "zygostates"
|
||||
}
|
||||
c.Upload.Prefix = strings.Trim(c.Upload.Prefix, "/")
|
||||
if c.Upload.Prefix == "" {
|
||||
return fmt.Errorf("upload.prefix must not resolve to empty")
|
||||
}
|
||||
if c.Upload.IntervalSeconds == 0 {
|
||||
c.Upload.IntervalSeconds = 15
|
||||
}
|
||||
if c.Upload.IntervalSeconds < 1 {
|
||||
return fmt.Errorf("upload.interval_seconds must be positive")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
80
internal/zygostates/config_test.go
Normal file
80
internal/zygostates/config_test.go
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func writeTestFile(t *testing.T, name, contents string) string {
|
||||
t.Helper()
|
||||
path := filepath.Join(t.TempDir(), name)
|
||||
if err := os.WriteFile(path, []byte(contents), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func TestLoadConfigDecodesTupleSequenceAndDefaults(t *testing.T) {
|
||||
path := writeTestFile(t, "config.yaml", `
|
||||
version: 1
|
||||
repeat: 2
|
||||
sequence:
|
||||
- [mixed, 300]
|
||||
- [idle, 30]
|
||||
artifacts:
|
||||
directory: /tmp/zygostates
|
||||
upload:
|
||||
endpoint: https://s3.example.test
|
||||
bucket: dump
|
||||
`)
|
||||
config, _, err := loadConfig(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(config.Sequence) != 2 || config.Sequence[0] != (Step{Workload: "mixed", Seconds: 300}) {
|
||||
t.Fatalf("unexpected sequence: %#v", config.Sequence)
|
||||
}
|
||||
if config.Artifacts.SampleIntervalSeconds != 15 || config.Upload.IntervalSeconds != 15 || config.Upload.Region != "us-east-1" || config.Upload.Prefix != "zygostates" {
|
||||
t.Fatalf("defaults not applied: %#v", config)
|
||||
}
|
||||
if config.Workloads.MemoryFraction != 0.5 || config.Workloads.FFTSize != 65536 || config.Workloads.MatrixSize != 256 {
|
||||
t.Fatalf("workload defaults not applied: %#v", config.Workloads)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfigRejectsUnknownFieldsAndWorkloads(t *testing.T) {
|
||||
for _, contents := range []string{
|
||||
"version: 1\nrepeat: 1\nsequence: [[idle, 1]]\nunknown: true\n",
|
||||
"version: 1\nrepeat: 1\nsequence: [[unbounded, 1]]\n",
|
||||
"version: 1\nrepeat: 1\nsequence: [[idle, 0]]\n",
|
||||
"version: 1\nrepeat: 1\nsequence: [idle]\n",
|
||||
} {
|
||||
path := writeTestFile(t, "config.yaml", contents)
|
||||
if _, _, err := loadConfig(path); err == nil {
|
||||
t.Fatalf("accepted invalid config %q", contents)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUploadConfigurationContainsNoCredentialFields(t *testing.T) {
|
||||
typeName := strings.ToLower(strings.Join([]string{
|
||||
fmtFieldNames(UploadConfig{}),
|
||||
}, " "))
|
||||
for _, forbidden := range []string{"credential", "accesskey", "secret", "token"} {
|
||||
if strings.Contains(typeName, forbidden) {
|
||||
t.Fatalf("upload config exposes %q: %s", forbidden, typeName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fmtFieldNames(value any) string {
|
||||
typeOf := reflect.TypeOf(value)
|
||||
var names []string
|
||||
for index := 0; index < typeOf.NumField(); index++ {
|
||||
names = append(names, typeOf.Field(index).Name)
|
||||
}
|
||||
return strings.Join(names, " ")
|
||||
}
|
||||
107
internal/zygostates/identity.go
Normal file
107
internal/zygostates/identity.go
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type HardwareIdentity struct {
|
||||
Key string `json:"key"`
|
||||
BoardVendor string `json:"board_vendor,omitempty"`
|
||||
BoardName string `json:"board_name,omitempty"`
|
||||
BoardVersion string `json:"board_version,omitempty"`
|
||||
BoardSerial string `json:"board_serial,omitempty"`
|
||||
ProductName string `json:"product_name,omitempty"`
|
||||
ProductSerial string `json:"product_serial,omitempty"`
|
||||
ProductUUID string `json:"product_uuid,omitempty"`
|
||||
}
|
||||
|
||||
var uuidPattern = regexp.MustCompile(`(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
|
||||
|
||||
func readHardwareIdentity(root string) (HardwareIdentity, error) {
|
||||
read := func(name string) string {
|
||||
contents, err := os.ReadFile(filepath.Join(root, name))
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(string(contents))
|
||||
}
|
||||
identity := HardwareIdentity{
|
||||
BoardVendor: read("board_vendor"),
|
||||
BoardName: read("board_name"),
|
||||
BoardVersion: read("board_version"),
|
||||
BoardSerial: read("board_serial"),
|
||||
ProductName: read("product_name"),
|
||||
ProductSerial: read("product_serial"),
|
||||
ProductUUID: strings.ToLower(read("product_uuid")),
|
||||
}
|
||||
if validUUID(identity.ProductUUID) {
|
||||
identity.Key = identity.ProductUUID
|
||||
return identity, nil
|
||||
}
|
||||
if validIdentifier(identity.BoardSerial) {
|
||||
identity.Key = sanitizeIdentifier(identity.BoardSerial)
|
||||
return identity, nil
|
||||
}
|
||||
return HardwareIdentity{}, fmt.Errorf("no valid SMBIOS product UUID or board serial")
|
||||
}
|
||||
|
||||
func validUUID(value string) bool {
|
||||
if !uuidPattern.MatchString(value) {
|
||||
return false
|
||||
}
|
||||
compact := strings.ReplaceAll(strings.ToLower(value), "-", "")
|
||||
return compact != strings.Repeat("0", 32) && compact != strings.Repeat("f", 32)
|
||||
}
|
||||
|
||||
func validIdentifier(value string) bool {
|
||||
normalized := strings.ToLower(strings.TrimSpace(value))
|
||||
if normalized == "" {
|
||||
return false
|
||||
}
|
||||
for _, placeholder := range []string{"default string", "none", "not specified", "system serial number", "to be filled by o.e.m.", "unknown"} {
|
||||
if normalized == placeholder {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return sanitizeIdentifier(value) != ""
|
||||
}
|
||||
|
||||
func sanitizeIdentifier(value string) string {
|
||||
var result strings.Builder
|
||||
for _, character := range strings.ToLower(strings.TrimSpace(value)) {
|
||||
switch {
|
||||
case character >= 'a' && character <= 'z', character >= '0' && character <= '9', character == '-', character == '_', character == '.':
|
||||
result.WriteRune(character)
|
||||
default:
|
||||
result.WriteByte('-')
|
||||
}
|
||||
}
|
||||
return strings.Trim(result.String(), "-.")
|
||||
}
|
||||
|
||||
type SystemMetadata struct {
|
||||
Identity HardwareIdentity `json:"identity"`
|
||||
Hostname string `json:"hostname"`
|
||||
Kernel string `json:"kernel"`
|
||||
Architecture string `json:"architecture"`
|
||||
LogicalCPUs int `json:"logical_cpus"`
|
||||
GoVersion string `json:"go_version"`
|
||||
}
|
||||
|
||||
func systemMetadata(identity HardwareIdentity) SystemMetadata {
|
||||
hostname, _ := os.Hostname()
|
||||
kernel, _ := os.ReadFile("/proc/sys/kernel/osrelease")
|
||||
return SystemMetadata{
|
||||
Identity: identity,
|
||||
Hostname: hostname,
|
||||
Kernel: strings.TrimSpace(string(kernel)),
|
||||
Architecture: runtime.GOARCH,
|
||||
LogicalCPUs: runtime.NumCPU(),
|
||||
GoVersion: runtime.Version(),
|
||||
}
|
||||
}
|
||||
54
internal/zygostates/identity_test.go
Normal file
54
internal/zygostates/identity_test.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func writeDMI(t *testing.T, values map[string]string) string {
|
||||
t.Helper()
|
||||
root := t.TempDir()
|
||||
for name, value := range values {
|
||||
if err := os.WriteFile(filepath.Join(root, name), []byte(value+"\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return root
|
||||
}
|
||||
|
||||
func TestHardwareIdentityUsesNormalizedProductUUID(t *testing.T) {
|
||||
identity, err := readHardwareIdentity(writeDMI(t, map[string]string{
|
||||
"product_uuid": "D5B6EC3A-DC36-4AA0-B6AE-5AF3D13D1280",
|
||||
"board_serial": "board-9",
|
||||
}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if identity.Key != "d5b6ec3a-dc36-4aa0-b6ae-5af3d13d1280" {
|
||||
t.Fatalf("key=%q", identity.Key)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHardwareIdentityFallsBackToBoardSerial(t *testing.T) {
|
||||
identity, err := readHardwareIdentity(writeDMI(t, map[string]string{
|
||||
"product_uuid": "00000000-0000-0000-0000-000000000000",
|
||||
"board_serial": "MB 12/34",
|
||||
}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if identity.Key != "mb-12-34" {
|
||||
t.Fatalf("key=%q", identity.Key)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHardwareIdentityRejectsPlaceholders(t *testing.T) {
|
||||
_, err := readHardwareIdentity(writeDMI(t, map[string]string{
|
||||
"product_uuid": "ffffffff-ffff-ffff-ffff-ffffffffffff",
|
||||
"board_serial": "To Be Filled By O.E.M.",
|
||||
}))
|
||||
if err == nil {
|
||||
t.Fatal("expected invalid identity")
|
||||
}
|
||||
}
|
||||
70
internal/zygostates/runner.go
Normal file
70
internal/zygostates/runner.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Workload interface {
|
||||
Run(context.Context, time.Duration) (map[string]any, error)
|
||||
}
|
||||
|
||||
type Runner struct {
|
||||
config Config
|
||||
workloads map[string]Workload
|
||||
store *ArtifactStore
|
||||
phase *atomic.Value
|
||||
now func() time.Time
|
||||
}
|
||||
|
||||
func (r *Runner) Run(ctx context.Context) error {
|
||||
for cycle := 1; cycle <= r.config.Repeat; cycle++ {
|
||||
for index, step := range r.config.Sequence {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
workload := r.workloads[step.Workload]
|
||||
phase := fmt.Sprintf("cycle-%d/%s", cycle, step.Workload)
|
||||
r.phase.Store(phase)
|
||||
started := r.now()
|
||||
if err := r.store.AppendEvent(Event{Timestamp: started, Type: "step-start", Fields: map[string]any{
|
||||
"cycle": cycle, "index": index, "workload": step.Workload, "seconds": step.Seconds,
|
||||
}}); err != nil {
|
||||
return err
|
||||
}
|
||||
metrics, stepError := workload.Run(ctx, time.Duration(step.Seconds)*time.Second)
|
||||
fields := map[string]any{
|
||||
"cycle": cycle, "index": index, "workload": step.Workload, "elapsed_seconds": r.now().Sub(started).Seconds(),
|
||||
}
|
||||
for key, value := range metrics {
|
||||
fields[key] = value
|
||||
}
|
||||
if stepError != nil {
|
||||
fields["error"] = stepError.Error()
|
||||
}
|
||||
if appendErr := r.store.AppendEvent(Event{Timestamp: r.now(), Type: "step-complete", Fields: fields}); appendErr != nil {
|
||||
return appendErr
|
||||
}
|
||||
if stepError != nil {
|
||||
return fmt.Errorf("cycle %d %s: %w", cycle, step.Workload, stepError)
|
||||
}
|
||||
}
|
||||
}
|
||||
r.phase.Store("complete")
|
||||
return nil
|
||||
}
|
||||
|
||||
type idleWorkload struct{}
|
||||
|
||||
func (idleWorkload) Run(ctx context.Context, duration time.Duration) (map[string]any, error) {
|
||||
timer := time.NewTimer(duration)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-timer.C:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
70
internal/zygostates/runner_test.go
Normal file
70
internal/zygostates/runner_test.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type fakeWorkload struct {
|
||||
calls atomic.Int64
|
||||
err error
|
||||
}
|
||||
|
||||
func (w *fakeWorkload) Run(context.Context, time.Duration) (map[string]any, error) {
|
||||
w.calls.Add(1)
|
||||
return map[string]any{"value": 7}, w.err
|
||||
}
|
||||
|
||||
func testArtifactStore(t *testing.T) *ArtifactStore {
|
||||
t.Helper()
|
||||
store, err := newArtifactStore(t.TempDir(), "run", []byte("version: 1\n"), SystemMetadata{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := store.Close(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
return store
|
||||
}
|
||||
|
||||
func TestRunnerRepeatsSequence(t *testing.T) {
|
||||
first := &fakeWorkload{}
|
||||
second := &fakeWorkload{}
|
||||
store := testArtifactStore(t)
|
||||
var phase atomic.Value
|
||||
phase.Store("start")
|
||||
now := time.Unix(1_700_000_000, 0)
|
||||
runner := Runner{
|
||||
config: Config{Repeat: 3, Sequence: []Step{{Workload: "first", Seconds: 1}, {Workload: "second", Seconds: 2}}},
|
||||
workloads: map[string]Workload{"first": first, "second": second}, store: store, phase: &phase,
|
||||
now: func() time.Time { now = now.Add(time.Second); return now },
|
||||
}
|
||||
if err := runner.Run(context.Background()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if first.calls.Load() != 3 || second.calls.Load() != 3 || phase.Load() != "complete" {
|
||||
t.Fatalf("calls=%d,%d phase=%v", first.calls.Load(), second.calls.Load(), phase.Load())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunnerStopsOnWorkloadFailure(t *testing.T) {
|
||||
failure := errors.New("verification failed")
|
||||
failed := &fakeWorkload{err: failure}
|
||||
after := &fakeWorkload{}
|
||||
store := testArtifactStore(t)
|
||||
var phase atomic.Value
|
||||
phase.Store("start")
|
||||
runner := Runner{
|
||||
config: Config{Repeat: 2, Sequence: []Step{{Workload: "failed", Seconds: 1}, {Workload: "after", Seconds: 1}}},
|
||||
workloads: map[string]Workload{"failed": failed, "after": after}, store: store, phase: &phase, now: time.Now,
|
||||
}
|
||||
err := runner.Run(context.Background())
|
||||
if !errors.Is(err, failure) || failed.calls.Load() != 1 || after.calls.Load() != 0 {
|
||||
t.Fatalf("err=%v calls=%d,%d", err, failed.calls.Load(), after.calls.Load())
|
||||
}
|
||||
}
|
||||
51
internal/zygostates/s3.go
Normal file
51
internal/zygostates/s3.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
awsconfig "github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
type s3PutClient interface {
|
||||
PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error)
|
||||
}
|
||||
|
||||
type S3ObjectStore struct {
|
||||
client s3PutClient
|
||||
}
|
||||
|
||||
func newS3ObjectStore(ctx context.Context, config UploadConfig) (*S3ObjectStore, error) {
|
||||
return newS3ObjectStoreWithOptions(ctx, config)
|
||||
}
|
||||
|
||||
func newS3ObjectStoreWithOptions(ctx context.Context, config UploadConfig, options ...func(*awsconfig.LoadOptions) error) (*S3ObjectStore, error) {
|
||||
options = append([]func(*awsconfig.LoadOptions) error{awsconfig.WithRegion(config.Region)}, options...)
|
||||
loaded, err := awsconfig.LoadDefaultConfig(ctx, options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client := s3.NewFromConfig(loaded, func(options *s3.Options) {
|
||||
options.UsePathStyle = config.Endpoint != ""
|
||||
if config.Endpoint != "" {
|
||||
options.BaseEndpoint = aws.String(config.Endpoint)
|
||||
}
|
||||
})
|
||||
return &S3ObjectStore{client: client}, nil
|
||||
}
|
||||
|
||||
func (s *S3ObjectStore) Put(ctx context.Context, request PutRequest) error {
|
||||
input := &s3.PutObjectInput{
|
||||
Bucket: aws.String(request.Bucket), Key: aws.String(request.Key), Body: bytes.NewReader(request.Body), Metadata: request.Metadata,
|
||||
}
|
||||
if request.ContentType != "" {
|
||||
input.ContentType = aws.String(request.ContentType)
|
||||
}
|
||||
if request.ContentEncoding != "" {
|
||||
input.ContentEncoding = aws.String(request.ContentEncoding)
|
||||
}
|
||||
_, err := s.client.PutObject(ctx, input)
|
||||
return err
|
||||
}
|
||||
59
internal/zygostates/s3_test.go
Normal file
59
internal/zygostates/s3_test.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package zygostates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
awsconfig "github.com/aws/aws-sdk-go-v2/config"
|
||||
)
|
||||
|
||||
type recordingHTTPClient struct {
|
||||
mu sync.Mutex
|
||||
request *http.Request
|
||||
body []byte
|
||||
}
|
||||
|
||||
func (c *recordingHTTPClient) Do(request *http.Request) (*http.Response, error) {
|
||||
body, err := io.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.request = request
|
||||
c.body = body
|
||||
c.mu.Unlock()
|
||||
return &http.Response{StatusCode: http.StatusOK, Status: "200 OK", Header: make(http.Header), Body: io.NopCloser(strings.NewReader("")), Request: request}, nil
|
||||
}
|
||||
|
||||
func TestS3ObjectStoreUsesSDKCredentialsAndPathStyleEndpoint(t *testing.T) {
|
||||
client := &recordingHTTPClient{}
|
||||
t.Setenv("AWS_ACCESS_KEY_ID", "test-access-key")
|
||||
t.Setenv("AWS_SECRET_ACCESS_KEY", "test-secret-key")
|
||||
t.Setenv("AWS_EC2_METADATA_DISABLED", "true")
|
||||
store, err := newS3ObjectStoreWithOptions(context.Background(), UploadConfig{Endpoint: "https://s3.example.test", Region: "us-east-1"}, awsconfig.WithHTTPClient(client))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = store.Put(context.Background(), PutRequest{Bucket: "dump", Key: "prefix/file", Body: []byte("contents"), ContentType: "application/octet-stream"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
client.mu.Lock()
|
||||
request := client.request
|
||||
body := client.body
|
||||
client.mu.Unlock()
|
||||
if request.Method != http.MethodPut || request.URL.Path != "/dump/prefix/file" {
|
||||
t.Fatalf("request=%s %s", request.Method, request.URL.Path)
|
||||
}
|
||||
if request.Header.Get("Authorization") == "" {
|
||||
t.Fatal("request was not signed")
|
||||
}
|
||||
if !bytes.Contains(body, []byte("contents")) {
|
||||
t.Fatalf("body=%q", body)
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue