From 841aa14dd1dbd3f7e2af73b3c9e5af2f30660879 Mon Sep 17 00:00:00 2001 From: Andrew Newdigate Date: Fri, 13 Dec 2019 12:58:47 +0200 Subject: [PATCH] Elastic APM support --- compile.sh | 3 +- go.mod | 9 +- go.sum | 44 + test.sh | 2 +- tracing/impl/elastic_tracer.go | 66 + vendor/github.com/armon/go-radix/.gitignore | 22 + vendor/github.com/armon/go-radix/.travis.yml | 3 + vendor/github.com/armon/go-radix/LICENSE | 20 + vendor/github.com/armon/go-radix/README.md | 38 + vendor/github.com/armon/go-radix/go.mod | 1 + vendor/github.com/armon/go-radix/radix.go | 540 ++ vendor/github.com/certifi/gocertifi/gen.go | 74 - .../elastic/go-sysinfo/.appveyor.yml | 61 + .../elastic/go-sysinfo/.editorconfig | 27 + .../elastic/go-sysinfo/.gitattributes | 5 + .../github.com/elastic/go-sysinfo/.gitignore | 11 + .../github.com/elastic/go-sysinfo/.travis.yml | 27 + .../elastic/go-sysinfo/CHANGELOG.md | 49 + .../github.com/elastic/go-sysinfo/LICENSE.txt | 202 + .../github.com/elastic/go-sysinfo/NOTICE.txt | 5 + .../github.com/elastic/go-sysinfo/README.md | 53 + vendor/github.com/elastic/go-sysinfo/go.mod | 11 + vendor/github.com/elastic/go-sysinfo/go.sum | 27 + .../go-sysinfo/internal/registry/registry.go | 58 + .../providers/darwin/arch_darwin_amd64.go | 35 + .../providers/darwin/boottime_darwin_amd64.go | 39 + .../go-sysinfo/providers/darwin/doc.go | 20 + .../providers/darwin/host_darwin_amd64.go | 226 + .../providers/darwin/kernel_darwin_amd64.go | 35 + .../darwin/machineid_darwin_amd64.go | 61 + .../providers/darwin/memory_darwin_amd64.go | 35 + .../elastic/go-sysinfo/providers/darwin/os.go | 93 + .../providers/darwin/process_darwin_amd64.go | 283 + .../providers/darwin/syscall_darwin_amd64.go | 240 + .../providers/darwin/ztypes_darwin_amd64.go | 187 + .../go-sysinfo/providers/linux/arch_linux.go | 41 + .../providers/linux/boottime_linux.go | 47 + .../providers/linux/capabilities_linux.go | 117 + .../go-sysinfo/providers/linux/container.go | 58 + .../elastic/go-sysinfo/providers/linux/doc.go | 20 + .../go-sysinfo/providers/linux/host_linux.go | 210 + .../providers/linux/kernel_linux.go | 41 + .../go-sysinfo/providers/linux/machineid.go | 63 + .../providers/linux/memory_linux.go | 100 + .../elastic/go-sysinfo/providers/linux/os.go | 264 + .../providers/linux/process_linux.go | 259 + .../providers/linux/seccomp_linux.go | 69 + .../go-sysinfo/providers/linux/util.go | 86 + .../go-sysinfo/providers/shared/network.go | 48 + .../providers/windows/arch_windows.go | 31 + .../providers/windows/boottime_windows.go | 39 + .../providers/windows/device_windows.go | 192 + .../go-sysinfo/providers/windows/doc.go | 20 + .../providers/windows/host_windows.go | 175 + .../providers/windows/kernel_windows.go | 43 + .../providers/windows/machineid_windows.go | 46 + .../providers/windows/os_windows.go | 92 + .../providers/windows/process_windows.go | 349 + .../github.com/elastic/go-sysinfo/system.go | 85 + .../elastic/go-sysinfo/types/errors.go | 22 + .../github.com/elastic/go-sysinfo/types/go.go | 25 + .../elastic/go-sysinfo/types/host.go | 78 + .../elastic/go-sysinfo/types/process.go | 138 + .../elastic/go-windows/.appveyor.yml | 61 + .../elastic/go-windows/.gitattributes | 5 + .../github.com/elastic/go-windows/.gitignore | 24 + .../github.com/elastic/go-windows/.travis.yml | 25 + .../elastic/go-windows/CHANGELOG.md | 34 + .../github.com/elastic/go-windows/LICENSE.txt | 202 + .../github.com/elastic/go-windows/NOTICE.txt | 5 + .../github.com/elastic/go-windows/README.md | 18 + .../github.com/elastic/go-windows/Vagrantfile | 30 + .../elastic/go-windows/constants.go | 32 + vendor/github.com/elastic/go-windows/doc.go | 23 + vendor/github.com/elastic/go-windows/go.mod | 6 + vendor/github.com/elastic/go-windows/go.sum | 9 + .../github.com/elastic/go-windows/kernel32.go | 249 + vendor/github.com/elastic/go-windows/ntdll.go | 129 + vendor/github.com/elastic/go-windows/psapi.go | 100 + vendor/github.com/elastic/go-windows/utf16.go | 68 + .../github.com/elastic/go-windows/version.go | 158 + .../elastic/go-windows/zsyscall_windows.go | 248 + vendor/github.com/joeshaw/multierror/LICENSE | 21 + .../github.com/joeshaw/multierror/README.md | 54 + .../joeshaw/multierror/multierror.go | 47 + .../opentracing/opentracing-go/.gitignore | 14 +- .../opentracing/opentracing-go/.travis.yml | 22 +- .../opentracing/opentracing-go/CHANGELOG.md | 38 +- .../opentracing/opentracing-go/LICENSE | 222 +- .../opentracing/opentracing-go/Makefile | 20 +- .../opentracing/opentracing-go/README.md | 32 +- .../opentracing/opentracing-go/ext/tags.go | 16 +- .../opentracing-go/globaltracer.go | 18 +- .../opentracing/opentracing-go/gocontext.go | 19 +- .../opentracing/opentracing-go/log/field.go | 24 + .../opentracing/opentracing-go/propagation.go | 14 +- .../opentracing/opentracing-go/span.go | 4 + .../opentracing/opentracing-go/tracer.go | 5 +- vendor/github.com/pkg/errors/.travis.yml | 12 +- vendor/github.com/pkg/errors/README.md | 4 +- vendor/github.com/pkg/errors/errors.go | 43 +- vendor/github.com/pkg/errors/stack.go | 51 +- .../prometheus/procfs/Makefile.common | 7 +- .../prometheus/procfs/fixtures.ttar | 551 +- vendor/github.com/prometheus/procfs/go.mod | 5 +- vendor/github.com/prometheus/procfs/go.sum | 2 + .../prometheus/procfs/internal/fs/fs.go | 3 + vendor/github.com/prometheus/procfs/mdstat.go | 111 +- .../github.com/prometheus/procfs/mountinfo.go | 178 + vendor/github.com/prometheus/procfs/proc.go | 14 + .../prometheus/procfs/proc_environ.go | 43 + .../github.com/prometheus/procfs/proc_stat.go | 2 +- .../santhosh-tekuri/jsonschema/.travis.yml | 10 + .../santhosh-tekuri/jsonschema/LICENSE | 27 + .../santhosh-tekuri/jsonschema/README.md | 148 + .../santhosh-tekuri/jsonschema/compiler.go | 534 ++ .../jsonschema/decoders/decoders.go | 32 + .../santhosh-tekuri/jsonschema/doc.go | 77 + .../santhosh-tekuri/jsonschema/draft4.go | 172 + .../santhosh-tekuri/jsonschema/draft6.go | 170 + .../santhosh-tekuri/jsonschema/draft7.go | 196 + .../santhosh-tekuri/jsonschema/errors.go | 122 + .../jsonschema/formats/formats.go | 295 + .../santhosh-tekuri/jsonschema/go.mod | 1 + .../santhosh-tekuri/jsonschema/go.test.sh | 12 + .../jsonschema/loader/loader.go | 105 + .../jsonschema/mediatypes/mediatypes.go | 39 + .../santhosh-tekuri/jsonschema/resource.go | 236 + .../santhosh-tekuri/jsonschema/schema.go | 558 ++ vendor/go.elastic.co/apm/.appveyor.yml | 17 + vendor/go.elastic.co/apm/.dockerignore | 2 + vendor/go.elastic.co/apm/.gitignore | 4 + vendor/go.elastic.co/apm/.jenkins-edge.yml | 2 + vendor/go.elastic.co/apm/.jenkins.yml | 8 + vendor/go.elastic.co/apm/.travis.yml | 41 + vendor/go.elastic.co/apm/CHANGELOG.md | 170 + vendor/go.elastic.co/apm/CODE_OF_CONDUCT.md | 3 + vendor/go.elastic.co/apm/CONTRIBUTING.md | 90 + vendor/go.elastic.co/apm/Jenkinsfile | 265 + vendor/go.elastic.co/apm/LICENSE | 201 + vendor/go.elastic.co/apm/Makefile | 81 + vendor/go.elastic.co/apm/NOTICE | 84 + vendor/go.elastic.co/apm/README.md | 41 + vendor/go.elastic.co/apm/apmconfig/doc.go | 20 + vendor/go.elastic.co/apm/apmconfig/watcher.go | 54 + vendor/go.elastic.co/apm/breakdown.go | 353 + vendor/go.elastic.co/apm/builtin_metrics.go | 164 + vendor/go.elastic.co/apm/capturebody.go | 198 + vendor/go.elastic.co/apm/config.go | 448 + vendor/go.elastic.co/apm/context.go | 256 + vendor/go.elastic.co/apm/doc.go | 21 + vendor/go.elastic.co/apm/error.go | 696 ++ vendor/go.elastic.co/apm/error_unix.go | 30 + vendor/go.elastic.co/apm/error_windows.go | 27 + vendor/go.elastic.co/apm/fmt.go | 85 + vendor/go.elastic.co/apm/fnv.go | 42 + vendor/go.elastic.co/apm/go.mod | 16 + vendor/go.elastic.co/apm/go.sum | 44 + vendor/go.elastic.co/apm/gocontext.go | 138 + vendor/go.elastic.co/apm/gofuzz.go | 270 + .../apm/internal/apmcontext/context.go | 78 + .../apm/internal/apmhostutil/container.go | 34 + .../internal/apmhostutil/container_linux.go | 156 + .../apmhostutil/container_nonlinux.go | 36 + .../apm/internal/apmhttputil/forwarded.go | 74 + .../apm/internal/apmhttputil/remoteaddr.go | 28 + .../apm/internal/apmhttputil/url.go | 110 + .../apm/internal/apmlog/logger.go | 173 + .../apm/internal/apmschema/schema.go | 69 + .../apm/internal/apmschema/update.sh | 36 + .../apm/internal/apmstrings/truncate.go | 31 + .../apm/internal/apmversion/version.go | 23 + .../apm/internal/configutil/duration.go | 73 + .../apm/internal/configutil/env.go | 95 + .../apm/internal/configutil/list.go | 34 + .../apm/internal/configutil/size.go | 105 + .../apm/internal/configutil/wildcards.go | 62 + .../go.elastic.co/apm/internal/iochan/doc.go | 19 + .../apm/internal/iochan/reader.go | 110 + .../apm/internal/pkgerrorsutil/pkgerrors.go | 60 + .../apm/internal/ringbuffer/buffer.go | 142 + .../apm/internal/ringbuffer/doc.go | 22 + .../apm/internal/wildcard/doc.go | 19 + .../apm/internal/wildcard/matcher.go | 142 + .../apm/internal/wildcard/matchers.go | 31 + vendor/go.elastic.co/apm/logger.go | 54 + vendor/go.elastic.co/apm/metrics.go | 161 + vendor/go.elastic.co/apm/model/doc.go | 21 + vendor/go.elastic.co/apm/model/generate.sh | 4 + vendor/go.elastic.co/apm/model/gofuzz.go | 82 + vendor/go.elastic.co/apm/model/maps.go | 48 + vendor/go.elastic.co/apm/model/marshal.go | 639 ++ .../apm/model/marshal_fastjson.go | 1198 +++ vendor/go.elastic.co/apm/model/model.go | 636 ++ vendor/go.elastic.co/apm/modelwriter.go | 262 + .../go.elastic.co/apm/module/apmhttp/LICENSE | 201 + .../apm/module/apmhttp/client.go | 199 + .../apm/module/apmhttp/context.go | 40 + .../go.elastic.co/apm/module/apmhttp/doc.go | 20 + .../go.elastic.co/apm/module/apmhttp/go.mod | 13 + .../go.elastic.co/apm/module/apmhttp/go.sum | 53 + .../apm/module/apmhttp/handler.go | 327 + .../apm/module/apmhttp/ignorer.go | 81 + .../apm/module/apmhttp/recovery.go | 60 + .../apm/module/apmhttp/requestname.go | 56 + .../apm/module/apmhttp/requestname_go19.go | 46 + .../apm/module/apmhttp/traceheaders.go | 126 + vendor/go.elastic.co/apm/module/apmot/LICENSE | 201 + .../go.elastic.co/apm/module/apmot/context.go | 86 + vendor/go.elastic.co/apm/module/apmot/doc.go | 24 + vendor/go.elastic.co/apm/module/apmot/go.mod | 14 + vendor/go.elastic.co/apm/module/apmot/go.sum | 55 + vendor/go.elastic.co/apm/module/apmot/log.go | 102 + vendor/go.elastic.co/apm/module/apmot/span.go | 307 + .../go.elastic.co/apm/module/apmot/tracer.go | 207 + .../go.elastic.co/apm/module/apmot/wrapper.go | 238 + vendor/go.elastic.co/apm/profiling.go | 164 + vendor/go.elastic.co/apm/sampler.go | 66 + vendor/go.elastic.co/apm/sanitizer.go | 66 + vendor/go.elastic.co/apm/span.go | 415 + vendor/go.elastic.co/apm/spancontext.go | 118 + vendor/go.elastic.co/apm/stacktrace.go | 52 + .../go.elastic.co/apm/stacktrace/context.go | 100 + vendor/go.elastic.co/apm/stacktrace/doc.go | 20 + vendor/go.elastic.co/apm/stacktrace/frame.go | 34 + .../apm/stacktrace/generate_library.bash | 77 + .../go.elastic.co/apm/stacktrace/library.go | 253 + .../apm/stacktrace/stacktrace.go | 162 + vendor/go.elastic.co/apm/tracecontext.go | 121 + vendor/go.elastic.co/apm/tracer.go | 1170 +++ vendor/go.elastic.co/apm/tracer_stats.go | 52 + vendor/go.elastic.co/apm/transaction.go | 321 + vendor/go.elastic.co/apm/transport/api.go | 33 + vendor/go.elastic.co/apm/transport/default.go | 54 + vendor/go.elastic.co/apm/transport/discard.go | 31 + vendor/go.elastic.co/apm/transport/doc.go | 20 + vendor/go.elastic.co/apm/transport/http.go | 620 ++ vendor/go.elastic.co/apm/utils.go | 242 + vendor/go.elastic.co/apm/utils_linux.go | 40 + vendor/go.elastic.co/apm/utils_other.go | 38 + vendor/go.elastic.co/apm/version.go | 23 + vendor/go.elastic.co/fastjson/.travis.yml | 9 + vendor/go.elastic.co/fastjson/LICENSE | 23 + vendor/go.elastic.co/fastjson/README.md | 134 + vendor/go.elastic.co/fastjson/doc.go | 23 + vendor/go.elastic.co/fastjson/go.mod | 3 + vendor/go.elastic.co/fastjson/go.sum | 2 + vendor/go.elastic.co/fastjson/marshaler.go | 151 + vendor/go.elastic.co/fastjson/writer.go | 181 + vendor/golang.org/x/net/http2/frame.go | 2 +- vendor/golang.org/x/net/http2/hpack/hpack.go | 10 +- vendor/golang.org/x/net/http2/server.go | 50 +- vendor/golang.org/x/net/http2/transport.go | 44 +- .../x/net/idna/{idna.go => idna10.0.0.go} | 8 +- vendor/golang.org/x/net/idna/idna9.0.0.go | 682 ++ .../x/net/idna/{tables.go => tables10.0.0.go} | 6 +- vendor/golang.org/x/net/idna/tables11.0.0.go | 4653 ++++++++++ vendor/golang.org/x/net/idna/tables9.0.0.go | 4486 ++++++++++ vendor/golang.org/x/net/trace/trace.go | 14 +- .../golang.org/x/sys/unix/asm_linux_riscv64.s | 54 + .../golang.org/x/sys/unix/asm_openbsd_arm64.s | 29 + vendor/golang.org/x/sys/unix/dirent.go | 89 +- vendor/golang.org/x/sys/unix/endian_little.go | 2 +- vendor/golang.org/x/sys/unix/mkall.sh | 33 +- vendor/golang.org/x/sys/unix/mkasm_darwin.go | 61 - vendor/golang.org/x/sys/unix/mkerrors.sh | 11 +- vendor/golang.org/x/sys/unix/mkpost.go | 106 - vendor/golang.org/x/sys/unix/mksyscall.go | 402 - .../x/sys/unix/mksyscall_aix_ppc.go | 404 - .../x/sys/unix/mksyscall_aix_ppc64.go | 602 -- .../x/sys/unix/mksyscall_solaris.go | 335 - .../golang.org/x/sys/unix/mksysctl_openbsd.pl | 265 - vendor/golang.org/x/sys/unix/mksysnum.go | 190 - .../{openbsd_pledge.go => pledge_openbsd.go} | 3 - .../x/sys/unix/readdirent_getdents.go | 12 + .../x/sys/unix/readdirent_getdirentries.go | 19 + vendor/golang.org/x/sys/unix/sockcmsg_unix.go | 11 +- vendor/golang.org/x/sys/unix/syscall.go | 1 - vendor/golang.org/x/sys/unix/syscall_aix.go | 48 +- .../golang.org/x/sys/unix/syscall_aix_ppc.go | 16 + .../x/sys/unix/syscall_aix_ppc64.go | 47 + vendor/golang.org/x/sys/unix/syscall_bsd.go | 12 +- .../golang.org/x/sys/unix/syscall_darwin.go | 29 + .../x/sys/unix/syscall_dragonfly.go | 17 + .../golang.org/x/sys/unix/syscall_freebsd.go | 126 +- vendor/golang.org/x/sys/unix/syscall_linux.go | 117 +- .../x/sys/unix/syscall_linux_arm.go | 13 + .../golang.org/x/sys/unix/syscall_netbsd.go | 37 +- .../golang.org/x/sys/unix/syscall_openbsd.go | 54 +- .../x/sys/unix/syscall_openbsd_arm64.go | 37 + .../golang.org/x/sys/unix/syscall_solaris.go | 17 + vendor/golang.org/x/sys/unix/syscall_unix.go | 17 +- vendor/golang.org/x/sys/unix/types_aix.go | 236 - vendor/golang.org/x/sys/unix/types_darwin.go | 277 - .../golang.org/x/sys/unix/types_dragonfly.go | 263 - vendor/golang.org/x/sys/unix/types_freebsd.go | 356 - vendor/golang.org/x/sys/unix/types_netbsd.go | 289 - vendor/golang.org/x/sys/unix/types_openbsd.go | 276 - vendor/golang.org/x/sys/unix/types_solaris.go | 266 - .../{openbsd_unveil.go => unveil_openbsd.go} | 2 - .../golang.org/x/sys/unix/zerrors_aix_ppc.go | 2 + .../x/sys/unix/zerrors_aix_ppc64.go | 4 +- .../x/sys/unix/zerrors_linux_386.go | 183 + .../x/sys/unix/zerrors_linux_amd64.go | 183 + .../x/sys/unix/zerrors_linux_arm.go | 183 + .../x/sys/unix/zerrors_linux_arm64.go | 183 + .../x/sys/unix/zerrors_linux_mips.go | 183 + .../x/sys/unix/zerrors_linux_mips64.go | 183 + .../x/sys/unix/zerrors_linux_mips64le.go | 183 + .../x/sys/unix/zerrors_linux_mipsle.go | 183 + .../x/sys/unix/zerrors_linux_ppc64.go | 183 + .../x/sys/unix/zerrors_linux_ppc64le.go | 183 + .../x/sys/unix/zerrors_linux_riscv64.go | 183 + .../x/sys/unix/zerrors_linux_s390x.go | 183 + .../x/sys/unix/zerrors_linux_sparc64.go | 183 + .../x/sys/unix/zerrors_openbsd_arm64.go | 1789 ++++ .../golang.org/x/sys/unix/zsyscall_aix_ppc.go | 52 +- .../x/sys/unix/zsyscall_aix_ppc64.go | 48 +- .../x/sys/unix/zsyscall_aix_ppc64_gc.go | 54 +- .../x/sys/unix/zsyscall_aix_ppc64_gccgo.go | 44 +- .../x/sys/unix/zsyscall_dragonfly_amd64.go | 17 + .../x/sys/unix/zsyscall_freebsd_386.go | 12 +- .../x/sys/unix/zsyscall_freebsd_amd64.go | 12 +- .../x/sys/unix/zsyscall_freebsd_arm.go | 12 +- .../x/sys/unix/zsyscall_freebsd_arm64.go | 12 +- .../x/sys/unix/zsyscall_linux_386.go | 54 +- .../x/sys/unix/zsyscall_linux_amd64.go | 54 +- .../x/sys/unix/zsyscall_linux_arm.go | 69 +- .../x/sys/unix/zsyscall_linux_arm64.go | 54 +- .../x/sys/unix/zsyscall_linux_mips.go | 54 +- .../x/sys/unix/zsyscall_linux_mips64.go | 54 +- .../x/sys/unix/zsyscall_linux_mips64le.go | 54 +- .../x/sys/unix/zsyscall_linux_mipsle.go | 54 +- .../x/sys/unix/zsyscall_linux_ppc64.go | 54 +- .../x/sys/unix/zsyscall_linux_ppc64le.go | 54 +- .../x/sys/unix/zsyscall_linux_riscv64.go | 54 +- .../x/sys/unix/zsyscall_linux_s390x.go | 54 +- .../x/sys/unix/zsyscall_linux_sparc64.go | 54 +- .../x/sys/unix/zsyscall_netbsd_386.go | 2 +- .../x/sys/unix/zsyscall_netbsd_amd64.go | 2 +- .../x/sys/unix/zsyscall_netbsd_arm.go | 2 +- .../x/sys/unix/zsyscall_netbsd_arm64.go | 2 +- .../x/sys/unix/zsyscall_openbsd_386.go | 2 +- .../x/sys/unix/zsyscall_openbsd_amd64.go | 2 +- .../x/sys/unix/zsyscall_openbsd_arm.go | 2 +- .../x/sys/unix/zsyscall_openbsd_arm64.go | 1692 ++++ .../x/sys/unix/zsysctl_openbsd_386.go | 2 + .../x/sys/unix/zsysctl_openbsd_amd64.go | 2 +- .../x/sys/unix/zsysctl_openbsd_arm.go | 4 +- .../x/sys/unix/zsysctl_openbsd_arm64.go | 275 + .../x/sys/unix/zsysnum_freebsd_386.go | 23 +- .../x/sys/unix/zsysnum_freebsd_amd64.go | 23 +- .../x/sys/unix/zsysnum_freebsd_arm.go | 23 +- .../x/sys/unix/zsysnum_freebsd_arm64.go | 445 +- .../x/sys/unix/zsysnum_linux_386.go | 806 +- .../x/sys/unix/zsysnum_linux_amd64.go | 10 + .../x/sys/unix/zsysnum_linux_arm.go | 742 +- .../x/sys/unix/zsysnum_linux_arm64.go | 10 + .../x/sys/unix/zsysnum_linux_mips.go | 776 +- .../x/sys/unix/zsysnum_linux_mips64.go | 10 + .../x/sys/unix/zsysnum_linux_mips64le.go | 10 + .../x/sys/unix/zsysnum_linux_mipsle.go | 776 +- .../x/sys/unix/zsysnum_linux_ppc64.go | 21 + .../x/sys/unix/zsysnum_linux_ppc64le.go | 21 + .../x/sys/unix/zsysnum_linux_riscv64.go | 10 + .../x/sys/unix/zsysnum_linux_s390x.go | 24 + .../x/sys/unix/zsysnum_linux_sparc64.go | 25 + .../x/sys/unix/zsysnum_openbsd_arm64.go | 217 + .../golang.org/x/sys/unix/ztypes_aix_ppc.go | 45 +- .../golang.org/x/sys/unix/ztypes_aix_ppc64.go | 50 +- .../x/sys/unix/ztypes_darwin_386.go | 46 +- .../x/sys/unix/ztypes_darwin_amd64.go | 48 +- .../x/sys/unix/ztypes_darwin_arm.go | 46 +- .../x/sys/unix/ztypes_darwin_arm64.go | 48 +- .../x/sys/unix/ztypes_dragonfly_amd64.go | 38 +- .../x/sys/unix/ztypes_freebsd_386.go | 185 +- .../x/sys/unix/ztypes_freebsd_amd64.go | 182 +- .../x/sys/unix/ztypes_freebsd_arm.go | 159 +- .../x/sys/unix/ztypes_freebsd_arm64.go | 160 +- .../golang.org/x/sys/unix/ztypes_linux_386.go | 746 +- .../x/sys/unix/ztypes_linux_amd64.go | 747 +- .../golang.org/x/sys/unix/ztypes_linux_arm.go | 746 +- .../x/sys/unix/ztypes_linux_arm64.go | 747 +- .../x/sys/unix/ztypes_linux_mips.go | 746 +- .../x/sys/unix/ztypes_linux_mips64.go | 747 +- .../x/sys/unix/ztypes_linux_mips64le.go | 747 +- .../x/sys/unix/ztypes_linux_mipsle.go | 746 +- .../x/sys/unix/ztypes_linux_ppc64.go | 747 +- .../x/sys/unix/ztypes_linux_ppc64le.go | 747 +- .../x/sys/unix/ztypes_linux_riscv64.go | 747 +- .../x/sys/unix/ztypes_linux_s390x.go | 747 +- .../x/sys/unix/ztypes_linux_sparc64.go | 747 +- .../x/sys/unix/ztypes_netbsd_386.go | 35 +- .../x/sys/unix/ztypes_netbsd_amd64.go | 41 +- .../x/sys/unix/ztypes_netbsd_arm.go | 41 +- .../x/sys/unix/ztypes_netbsd_arm64.go | 41 +- .../x/sys/unix/ztypes_openbsd_386.go | 11 + .../x/sys/unix/ztypes_openbsd_amd64.go | 11 + .../x/sys/unix/ztypes_openbsd_arm.go | 11 + .../x/sys/unix/ztypes_openbsd_arm64.go | 565 ++ .../golang.org/x/sys/windows/dll_windows.go | 8 +- .../golang.org/x/sys/windows/env_windows.go | 34 +- vendor/golang.org/x/sys/windows/mkerrors.bash | 63 + .../x/sys/windows/mkknownfolderids.bash | 27 + vendor/golang.org/x/sys/windows/mksyscall.go | 2 + .../golang.org/x/sys/windows/registry/key.go | 198 + .../x/sys/windows/registry/mksyscall.go | 9 + .../x/sys/windows/registry/syscall.go | 32 + .../x/sys/windows/registry/value.go | 387 + .../sys/windows/registry/zsyscall_windows.go | 120 + .../x/sys/windows/security_windows.go | 400 +- vendor/golang.org/x/sys/windows/service.go | 70 +- .../x/sys/windows/syscall_windows.go | 116 +- .../golang.org/x/sys/windows/types_windows.go | 291 +- .../x/sys/windows/zerrors_windows.go | 6853 +++++++++++++++ .../x/sys/windows/zknownfolderids_windows.go | 149 + .../x/sys/windows/zsyscall_windows.go | 635 +- .../golang.org/x/text/transform/transform.go | 6 +- vendor/golang.org/x/text/unicode/bidi/bidi.go | 2 +- .../golang.org/x/text/unicode/bidi/bracket.go | 4 +- vendor/golang.org/x/text/unicode/bidi/core.go | 2 +- vendor/golang.org/x/text/unicode/bidi/gen.go | 133 - .../x/text/unicode/bidi/gen_ranges.go | 57 - .../x/text/unicode/bidi/gen_trieval.go | 64 - .../x/text/unicode/bidi/tables10.0.0.go | 2 +- .../x/text/unicode/bidi/tables11.0.0.go | 1887 ++++ .../x/text/unicode/norm/composition.go | 8 +- .../x/text/unicode/norm/forminfo.go | 19 + vendor/golang.org/x/text/unicode/norm/iter.go | 3 +- .../x/text/unicode/norm/maketables.go | 976 --- .../x/text/unicode/norm/normalize.go | 4 +- .../x/text/unicode/norm/readwriter.go | 4 +- .../x/text/unicode/norm/tables10.0.0.go | 1892 ++-- .../x/text/unicode/norm/tables11.0.0.go | 7693 +++++++++++++++++ .../x/text/unicode/norm/tables9.0.0.go | 1890 ++-- .../x/text/unicode/norm/transform.go | 10 +- .../golang.org/x/text/unicode/norm/triegen.go | 117 - vendor/howett.net/plist/.gitlab-ci.yml | 39 + vendor/howett.net/plist/LICENSE | 58 + vendor/howett.net/plist/README.md | 21 + vendor/howett.net/plist/bplist.go | 26 + vendor/howett.net/plist/bplist_generator.go | 303 + vendor/howett.net/plist/bplist_parser.go | 353 + vendor/howett.net/plist/decode.go | 119 + vendor/howett.net/plist/doc.go | 5 + vendor/howett.net/plist/encode.go | 126 + vendor/howett.net/plist/fuzz.go | 17 + vendor/howett.net/plist/go.mod | 9 + vendor/howett.net/plist/marshal.go | 186 + vendor/howett.net/plist/must.go | 50 + vendor/howett.net/plist/plist.go | 85 + vendor/howett.net/plist/plist_types.go | 139 + vendor/howett.net/plist/text_generator.go | 226 + vendor/howett.net/plist/text_parser.go | 515 ++ vendor/howett.net/plist/text_tables.go | 43 + vendor/howett.net/plist/typeinfo.go | 170 + vendor/howett.net/plist/unmarshal.go | 317 + vendor/howett.net/plist/util.go | 25 + vendor/howett.net/plist/xml_generator.go | 185 + vendor/howett.net/plist/xml_parser.go | 216 + vendor/howett.net/plist/zerocopy.go | 20 + vendor/howett.net/plist/zerocopy_appengine.go | 7 + vendor/modules.txt | 109 +- vet.sh | 1 + 464 files changed, 80259 insertions(+), 12137 deletions(-) create mode 100644 tracing/impl/elastic_tracer.go create mode 100644 vendor/github.com/armon/go-radix/.gitignore create mode 100644 vendor/github.com/armon/go-radix/.travis.yml create mode 100644 vendor/github.com/armon/go-radix/LICENSE create mode 100644 vendor/github.com/armon/go-radix/README.md create mode 100644 vendor/github.com/armon/go-radix/go.mod create mode 100644 vendor/github.com/armon/go-radix/radix.go delete mode 100644 vendor/github.com/certifi/gocertifi/gen.go create mode 100644 vendor/github.com/elastic/go-sysinfo/.appveyor.yml create mode 100644 vendor/github.com/elastic/go-sysinfo/.editorconfig create mode 100644 vendor/github.com/elastic/go-sysinfo/.gitattributes create mode 100644 vendor/github.com/elastic/go-sysinfo/.gitignore create mode 100644 vendor/github.com/elastic/go-sysinfo/.travis.yml create mode 100644 vendor/github.com/elastic/go-sysinfo/CHANGELOG.md create mode 100644 vendor/github.com/elastic/go-sysinfo/LICENSE.txt create mode 100644 vendor/github.com/elastic/go-sysinfo/NOTICE.txt create mode 100644 vendor/github.com/elastic/go-sysinfo/README.md create mode 100644 vendor/github.com/elastic/go-sysinfo/go.mod create mode 100644 vendor/github.com/elastic/go-sysinfo/go.sum create mode 100644 vendor/github.com/elastic/go-sysinfo/internal/registry/registry.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/arch_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/boottime_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/doc.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/host_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/kernel_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/machineid_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/memory_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/os.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/process_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/syscall_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/darwin/ztypes_darwin_amd64.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/arch_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/boottime_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/capabilities_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/container.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/doc.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/host_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/kernel_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/memory_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/os.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/process_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/seccomp_linux.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/linux/util.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/shared/network.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/arch_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/boottime_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/device_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/doc.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/host_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/kernel_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/machineid_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/os_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/providers/windows/process_windows.go create mode 100644 vendor/github.com/elastic/go-sysinfo/system.go create mode 100644 vendor/github.com/elastic/go-sysinfo/types/errors.go create mode 100644 vendor/github.com/elastic/go-sysinfo/types/go.go create mode 100644 vendor/github.com/elastic/go-sysinfo/types/host.go create mode 100644 vendor/github.com/elastic/go-sysinfo/types/process.go create mode 100644 vendor/github.com/elastic/go-windows/.appveyor.yml create mode 100644 vendor/github.com/elastic/go-windows/.gitattributes create mode 100644 vendor/github.com/elastic/go-windows/.gitignore create mode 100644 vendor/github.com/elastic/go-windows/.travis.yml create mode 100644 vendor/github.com/elastic/go-windows/CHANGELOG.md create mode 100644 vendor/github.com/elastic/go-windows/LICENSE.txt create mode 100644 vendor/github.com/elastic/go-windows/NOTICE.txt create mode 100644 vendor/github.com/elastic/go-windows/README.md create mode 100644 vendor/github.com/elastic/go-windows/Vagrantfile create mode 100644 vendor/github.com/elastic/go-windows/constants.go create mode 100644 vendor/github.com/elastic/go-windows/doc.go create mode 100644 vendor/github.com/elastic/go-windows/go.mod create mode 100644 vendor/github.com/elastic/go-windows/go.sum create mode 100644 vendor/github.com/elastic/go-windows/kernel32.go create mode 100644 vendor/github.com/elastic/go-windows/ntdll.go create mode 100644 vendor/github.com/elastic/go-windows/psapi.go create mode 100644 vendor/github.com/elastic/go-windows/utf16.go create mode 100644 vendor/github.com/elastic/go-windows/version.go create mode 100644 vendor/github.com/elastic/go-windows/zsyscall_windows.go create mode 100644 vendor/github.com/joeshaw/multierror/LICENSE create mode 100644 vendor/github.com/joeshaw/multierror/README.md create mode 100644 vendor/github.com/joeshaw/multierror/multierror.go create mode 100644 vendor/github.com/prometheus/procfs/mountinfo.go create mode 100644 vendor/github.com/prometheus/procfs/proc_environ.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/.travis.yml create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/LICENSE create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/README.md create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/compiler.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/decoders/decoders.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/doc.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/draft4.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/draft6.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/draft7.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/errors.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/formats/formats.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/go.mod create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/go.test.sh create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/loader/loader.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/mediatypes/mediatypes.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/resource.go create mode 100644 vendor/github.com/santhosh-tekuri/jsonschema/schema.go create mode 100644 vendor/go.elastic.co/apm/.appveyor.yml create mode 100644 vendor/go.elastic.co/apm/.dockerignore create mode 100644 vendor/go.elastic.co/apm/.gitignore create mode 100644 vendor/go.elastic.co/apm/.jenkins-edge.yml create mode 100644 vendor/go.elastic.co/apm/.jenkins.yml create mode 100644 vendor/go.elastic.co/apm/.travis.yml create mode 100644 vendor/go.elastic.co/apm/CHANGELOG.md create mode 100644 vendor/go.elastic.co/apm/CODE_OF_CONDUCT.md create mode 100644 vendor/go.elastic.co/apm/CONTRIBUTING.md create mode 100644 vendor/go.elastic.co/apm/Jenkinsfile create mode 100644 vendor/go.elastic.co/apm/LICENSE create mode 100644 vendor/go.elastic.co/apm/Makefile create mode 100644 vendor/go.elastic.co/apm/NOTICE create mode 100644 vendor/go.elastic.co/apm/README.md create mode 100644 vendor/go.elastic.co/apm/apmconfig/doc.go create mode 100644 vendor/go.elastic.co/apm/apmconfig/watcher.go create mode 100644 vendor/go.elastic.co/apm/breakdown.go create mode 100644 vendor/go.elastic.co/apm/builtin_metrics.go create mode 100644 vendor/go.elastic.co/apm/capturebody.go create mode 100644 vendor/go.elastic.co/apm/config.go create mode 100644 vendor/go.elastic.co/apm/context.go create mode 100644 vendor/go.elastic.co/apm/doc.go create mode 100644 vendor/go.elastic.co/apm/error.go create mode 100644 vendor/go.elastic.co/apm/error_unix.go create mode 100644 vendor/go.elastic.co/apm/error_windows.go create mode 100644 vendor/go.elastic.co/apm/fmt.go create mode 100644 vendor/go.elastic.co/apm/fnv.go create mode 100644 vendor/go.elastic.co/apm/go.mod create mode 100644 vendor/go.elastic.co/apm/go.sum create mode 100644 vendor/go.elastic.co/apm/gocontext.go create mode 100644 vendor/go.elastic.co/apm/gofuzz.go create mode 100644 vendor/go.elastic.co/apm/internal/apmcontext/context.go create mode 100644 vendor/go.elastic.co/apm/internal/apmhostutil/container.go create mode 100644 vendor/go.elastic.co/apm/internal/apmhostutil/container_linux.go create mode 100644 vendor/go.elastic.co/apm/internal/apmhostutil/container_nonlinux.go create mode 100644 vendor/go.elastic.co/apm/internal/apmhttputil/forwarded.go create mode 100644 vendor/go.elastic.co/apm/internal/apmhttputil/remoteaddr.go create mode 100644 vendor/go.elastic.co/apm/internal/apmhttputil/url.go create mode 100644 vendor/go.elastic.co/apm/internal/apmlog/logger.go create mode 100644 vendor/go.elastic.co/apm/internal/apmschema/schema.go create mode 100644 vendor/go.elastic.co/apm/internal/apmschema/update.sh create mode 100644 vendor/go.elastic.co/apm/internal/apmstrings/truncate.go create mode 100644 vendor/go.elastic.co/apm/internal/apmversion/version.go create mode 100644 vendor/go.elastic.co/apm/internal/configutil/duration.go create mode 100644 vendor/go.elastic.co/apm/internal/configutil/env.go create mode 100644 vendor/go.elastic.co/apm/internal/configutil/list.go create mode 100644 vendor/go.elastic.co/apm/internal/configutil/size.go create mode 100644 vendor/go.elastic.co/apm/internal/configutil/wildcards.go create mode 100644 vendor/go.elastic.co/apm/internal/iochan/doc.go create mode 100644 vendor/go.elastic.co/apm/internal/iochan/reader.go create mode 100644 vendor/go.elastic.co/apm/internal/pkgerrorsutil/pkgerrors.go create mode 100644 vendor/go.elastic.co/apm/internal/ringbuffer/buffer.go create mode 100644 vendor/go.elastic.co/apm/internal/ringbuffer/doc.go create mode 100644 vendor/go.elastic.co/apm/internal/wildcard/doc.go create mode 100644 vendor/go.elastic.co/apm/internal/wildcard/matcher.go create mode 100644 vendor/go.elastic.co/apm/internal/wildcard/matchers.go create mode 100644 vendor/go.elastic.co/apm/logger.go create mode 100644 vendor/go.elastic.co/apm/metrics.go create mode 100644 vendor/go.elastic.co/apm/model/doc.go create mode 100644 vendor/go.elastic.co/apm/model/generate.sh create mode 100644 vendor/go.elastic.co/apm/model/gofuzz.go create mode 100644 vendor/go.elastic.co/apm/model/maps.go create mode 100644 vendor/go.elastic.co/apm/model/marshal.go create mode 100644 vendor/go.elastic.co/apm/model/marshal_fastjson.go create mode 100644 vendor/go.elastic.co/apm/model/model.go create mode 100644 vendor/go.elastic.co/apm/modelwriter.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/LICENSE create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/client.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/context.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/doc.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/go.mod create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/go.sum create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/handler.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/ignorer.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/recovery.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/requestname.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/requestname_go19.go create mode 100644 vendor/go.elastic.co/apm/module/apmhttp/traceheaders.go create mode 100644 vendor/go.elastic.co/apm/module/apmot/LICENSE create mode 100644 vendor/go.elastic.co/apm/module/apmot/context.go create mode 100644 vendor/go.elastic.co/apm/module/apmot/doc.go create mode 100644 vendor/go.elastic.co/apm/module/apmot/go.mod create mode 100644 vendor/go.elastic.co/apm/module/apmot/go.sum create mode 100644 vendor/go.elastic.co/apm/module/apmot/log.go create mode 100644 vendor/go.elastic.co/apm/module/apmot/span.go create mode 100644 vendor/go.elastic.co/apm/module/apmot/tracer.go create mode 100644 vendor/go.elastic.co/apm/module/apmot/wrapper.go create mode 100644 vendor/go.elastic.co/apm/profiling.go create mode 100644 vendor/go.elastic.co/apm/sampler.go create mode 100644 vendor/go.elastic.co/apm/sanitizer.go create mode 100644 vendor/go.elastic.co/apm/span.go create mode 100644 vendor/go.elastic.co/apm/spancontext.go create mode 100644 vendor/go.elastic.co/apm/stacktrace.go create mode 100644 vendor/go.elastic.co/apm/stacktrace/context.go create mode 100644 vendor/go.elastic.co/apm/stacktrace/doc.go create mode 100644 vendor/go.elastic.co/apm/stacktrace/frame.go create mode 100644 vendor/go.elastic.co/apm/stacktrace/generate_library.bash create mode 100644 vendor/go.elastic.co/apm/stacktrace/library.go create mode 100644 vendor/go.elastic.co/apm/stacktrace/stacktrace.go create mode 100644 vendor/go.elastic.co/apm/tracecontext.go create mode 100644 vendor/go.elastic.co/apm/tracer.go create mode 100644 vendor/go.elastic.co/apm/tracer_stats.go create mode 100644 vendor/go.elastic.co/apm/transaction.go create mode 100644 vendor/go.elastic.co/apm/transport/api.go create mode 100644 vendor/go.elastic.co/apm/transport/default.go create mode 100644 vendor/go.elastic.co/apm/transport/discard.go create mode 100644 vendor/go.elastic.co/apm/transport/doc.go create mode 100644 vendor/go.elastic.co/apm/transport/http.go create mode 100644 vendor/go.elastic.co/apm/utils.go create mode 100644 vendor/go.elastic.co/apm/utils_linux.go create mode 100644 vendor/go.elastic.co/apm/utils_other.go create mode 100644 vendor/go.elastic.co/apm/version.go create mode 100644 vendor/go.elastic.co/fastjson/.travis.yml create mode 100644 vendor/go.elastic.co/fastjson/LICENSE create mode 100644 vendor/go.elastic.co/fastjson/README.md create mode 100644 vendor/go.elastic.co/fastjson/doc.go create mode 100644 vendor/go.elastic.co/fastjson/go.mod create mode 100644 vendor/go.elastic.co/fastjson/go.sum create mode 100644 vendor/go.elastic.co/fastjson/marshaler.go create mode 100644 vendor/go.elastic.co/fastjson/writer.go rename vendor/golang.org/x/net/idna/{idna.go => idna10.0.0.go} (99%) create mode 100644 vendor/golang.org/x/net/idna/idna9.0.0.go rename vendor/golang.org/x/net/idna/{tables.go => tables10.0.0.go} (99%) create mode 100644 vendor/golang.org/x/net/idna/tables11.0.0.go create mode 100644 vendor/golang.org/x/net/idna/tables9.0.0.go create mode 100644 vendor/golang.org/x/sys/unix/asm_linux_riscv64.s create mode 100644 vendor/golang.org/x/sys/unix/asm_openbsd_arm64.s delete mode 100644 vendor/golang.org/x/sys/unix/mkasm_darwin.go delete mode 100644 vendor/golang.org/x/sys/unix/mkpost.go delete mode 100644 vendor/golang.org/x/sys/unix/mksyscall.go delete mode 100644 vendor/golang.org/x/sys/unix/mksyscall_aix_ppc.go delete mode 100644 vendor/golang.org/x/sys/unix/mksyscall_aix_ppc64.go delete mode 100644 vendor/golang.org/x/sys/unix/mksyscall_solaris.go delete mode 100644 vendor/golang.org/x/sys/unix/mksysctl_openbsd.pl delete mode 100644 vendor/golang.org/x/sys/unix/mksysnum.go rename vendor/golang.org/x/sys/unix/{openbsd_pledge.go => pledge_openbsd.go} (98%) create mode 100644 vendor/golang.org/x/sys/unix/readdirent_getdents.go create mode 100644 vendor/golang.org/x/sys/unix/readdirent_getdirentries.go create mode 100644 vendor/golang.org/x/sys/unix/syscall_openbsd_arm64.go delete mode 100644 vendor/golang.org/x/sys/unix/types_aix.go delete mode 100644 vendor/golang.org/x/sys/unix/types_darwin.go delete mode 100644 vendor/golang.org/x/sys/unix/types_dragonfly.go delete mode 100644 vendor/golang.org/x/sys/unix/types_freebsd.go delete mode 100644 vendor/golang.org/x/sys/unix/types_netbsd.go delete mode 100644 vendor/golang.org/x/sys/unix/types_openbsd.go delete mode 100644 vendor/golang.org/x/sys/unix/types_solaris.go rename vendor/golang.org/x/sys/unix/{openbsd_unveil.go => unveil_openbsd.go} (98%) create mode 100644 vendor/golang.org/x/sys/unix/zerrors_openbsd_arm64.go create mode 100644 vendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go create mode 100644 vendor/golang.org/x/sys/unix/zsysctl_openbsd_arm64.go create mode 100644 vendor/golang.org/x/sys/unix/zsysnum_openbsd_arm64.go create mode 100644 vendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go create mode 100644 vendor/golang.org/x/sys/windows/mkerrors.bash create mode 100644 vendor/golang.org/x/sys/windows/mkknownfolderids.bash create mode 100644 vendor/golang.org/x/sys/windows/registry/key.go create mode 100644 vendor/golang.org/x/sys/windows/registry/mksyscall.go create mode 100644 vendor/golang.org/x/sys/windows/registry/syscall.go create mode 100644 vendor/golang.org/x/sys/windows/registry/value.go create mode 100644 vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go create mode 100644 vendor/golang.org/x/sys/windows/zerrors_windows.go create mode 100644 vendor/golang.org/x/sys/windows/zknownfolderids_windows.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/gen.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/gen_ranges.go delete mode 100644 vendor/golang.org/x/text/unicode/bidi/gen_trieval.go create mode 100644 vendor/golang.org/x/text/unicode/bidi/tables11.0.0.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/maketables.go create mode 100644 vendor/golang.org/x/text/unicode/norm/tables11.0.0.go delete mode 100644 vendor/golang.org/x/text/unicode/norm/triegen.go create mode 100644 vendor/howett.net/plist/.gitlab-ci.yml create mode 100644 vendor/howett.net/plist/LICENSE create mode 100644 vendor/howett.net/plist/README.md create mode 100644 vendor/howett.net/plist/bplist.go create mode 100644 vendor/howett.net/plist/bplist_generator.go create mode 100644 vendor/howett.net/plist/bplist_parser.go create mode 100644 vendor/howett.net/plist/decode.go create mode 100644 vendor/howett.net/plist/doc.go create mode 100644 vendor/howett.net/plist/encode.go create mode 100644 vendor/howett.net/plist/fuzz.go create mode 100644 vendor/howett.net/plist/go.mod create mode 100644 vendor/howett.net/plist/marshal.go create mode 100644 vendor/howett.net/plist/must.go create mode 100644 vendor/howett.net/plist/plist.go create mode 100644 vendor/howett.net/plist/plist_types.go create mode 100644 vendor/howett.net/plist/text_generator.go create mode 100644 vendor/howett.net/plist/text_parser.go create mode 100644 vendor/howett.net/plist/text_tables.go create mode 100644 vendor/howett.net/plist/typeinfo.go create mode 100644 vendor/howett.net/plist/unmarshal.go create mode 100644 vendor/howett.net/plist/util.go create mode 100644 vendor/howett.net/plist/xml_generator.go create mode 100644 vendor/howett.net/plist/xml_parser.go create mode 100644 vendor/howett.net/plist/zerocopy.go create mode 100644 vendor/howett.net/plist/zerocopy_appengine.go diff --git a/compile.sh b/compile.sh index 3959b911..4fbebe4c 100755 --- a/compile.sh +++ b/compile.sh @@ -9,10 +9,11 @@ cd "${SCRIPT_DIR}" for build_tags in \ "" \ + "tracer_static tracer_static_elastic" \ "tracer_static tracer_static_jaeger" \ "tracer_static tracer_static_lightstep" \ "tracer_static tracer_static_datadog" \ - "tracer_static tracer_static_jaeger tracer_static_lightstep tracer_static_datadog" \ + "tracer_static tracer_static_elastic tracer_static_jaeger tracer_static_lightstep tracer_static_datadog" \ ; do ( set -x; diff --git a/go.mod b/go.mod index ff202b32..c359f72f 100644 --- a/go.mod +++ b/go.mod @@ -10,9 +10,10 @@ require ( github.com/lightstep/lightstep-tracer-go v0.15.6 github.com/onsi/ginkgo v1.7.0 // indirect github.com/onsi/gomega v1.4.3 // indirect - github.com/opentracing/opentracing-go v1.0.2 + github.com/opentracing/opentracing-go v1.1.0 github.com/philhofer/fwd v1.0.0 // indirect github.com/prometheus/client_golang v1.0.0 + github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 github.com/sebest/xff v0.0.0-20160910043805-6c115e0ffa35 github.com/sirupsen/logrus v1.3.0 github.com/stretchr/testify v1.3.0 @@ -20,9 +21,11 @@ require ( github.com/uber-go/atomic v1.3.2 // indirect github.com/uber/jaeger-client-go v2.15.0+incompatible github.com/uber/jaeger-lib v1.5.0 // indirect + go.elastic.co/apm v1.6.0 + go.elastic.co/apm/module/apmot v1.6.0 go.uber.org/atomic v1.3.2 // indirect - golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 // indirect - golang.org/x/sys v0.0.0-20190306220723-b294cbcfc56d // indirect google.golang.org/grpc v1.16.0 gopkg.in/DataDog/dd-trace-go.v1 v1.7.0 ) + +go 1.13 diff --git a/go.sum b/go.sum index fe544d84..2f9a0a1d 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= +github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0 h1:HWo1m869IqiPhD389kmkxeTalrjNbbJTC8LXupb+sl0= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= @@ -14,6 +16,10 @@ github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elastic/go-sysinfo v1.0.1 h1:lzGPX2sIXaETeMXitXL2XZU8K4B7k7JBhIKWxdOdUt8= +github.com/elastic/go-sysinfo v1.0.1/go.mod h1:O/D5m1VpYLwGjCYzEt63g3Z1uO3jXfwyzzjiW90t8cY= +github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY= +github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/getsentry/raven-go v0.1.0 h1:lc5jnN9D+q3panDpihwShgaOVvP6esoMEKbID2yhLoQ= @@ -31,10 +37,15 @@ github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c= github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -43,6 +54,9 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lightstep/lightstep-tracer-go v0.15.6 h1:D0GGa7afJ7GcQvu5as6ssLEEKYXvRgKI5d5cevtz8r4= github.com/lightstep/lightstep-tracer-go v0.15.6/go.mod h1:6AMpwZpsyCFwSovxzM78e+AsYxE8sGwiM6C3TytaWeI= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= @@ -57,10 +71,14 @@ github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/opentracing/opentracing-go v1.0.2 h1:3jA2P6O1F9UOrWVpwrIo17pu01KWvNWg4X946/Y5Zwg= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= +github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= github.com/philhofer/fwd v1.0.0 h1:UbZqGr5Y38ApvM/V/jEljVxwocdweyH+vmYvRPBnbqQ= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -72,8 +90,13 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1: github.com/prometheus/common v0.4.1 h1:K0MGApIoQvMw27RTdJkPbr3JZ7DNbtxQNyi5STVM6Kw= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= +github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= github.com/sebest/xff v0.0.0-20160910043805-6c115e0ffa35 h1:eajwn6K3weW5cd1ZXLu2sJ4pvwlBiCWY4uDejOr73gM= github.com/sebest/xff v0.0.0-20160910043805-6c115e0ffa35/go.mod h1:wozgYq9WEBQBaIJe4YZ0qTSFAMxmcwBhQH0fO0R34Z0= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -93,12 +116,22 @@ github.com/uber/jaeger-client-go v2.15.0+incompatible h1:NP3qsSqNxh8VYr956ur1N/1 github.com/uber/jaeger-client-go v2.15.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= github.com/uber/jaeger-lib v1.5.0 h1:OHbgr8l656Ub3Fw5k9SWnBfIEwvoHQ+W2y+Aa9D1Uyo= github.com/uber/jaeger-lib v1.5.0/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= +go.elastic.co/apm v1.6.0 h1:RzyNj9Qx2iXh4A8DIg/aMUdtwGFNw3R8sKO3/Hf4pqk= +go.elastic.co/apm v1.6.0/go.mod h1:/VByR6FBtuNu1YnPHz7Gri7YiIqAoFBGVp+2xkSE8tI= +go.elastic.co/apm/module/apmhttp v1.6.0 h1:Y67VwDNnUyq4akeiem8Wtpb222RbZCRfY3FBI0swoJk= +go.elastic.co/apm/module/apmhttp v1.6.0/go.mod h1:pf6GS5vDxdrSF0Qy6wESRBZCRZqATSZpr658ehD5QA4= +go.elastic.co/apm/module/apmot v1.6.0 h1:3Tjwu25SfB2Bq+UsO8JOKYOuMzUu4s8/fS8BGkliocg= +go.elastic.co/apm/module/apmot v1.6.0/go.mod h1:JIGFfrixcGjp8oD22PTTCvdNMfp+O+lOb5Hw4MtqxQ4= +go.elastic.co/fastjson v1.0.0 h1:ooXV/ABvf+tBul26jcVViPT3sBir0PvXgibYB1IQQzg= +go.elastic.co/fastjson v1.0.0/go.mod h1:PmeUOMMtLHQr9ZS9J9owrAVg0FkaZDRZJEFTTGHtchs= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25 h1:jsG6UpNLt9iAsb0S2AGW28DveNzzgmbXR+ENoPjUeIU= golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -106,6 +139,8 @@ golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80 h1:Ao/3l156eZf2AW5wK8a7/smtodRU+gha3+BeqJ69lRk= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -120,9 +155,15 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190306220723-b294cbcfc56d h1:4Ew1XHJYjwX6RiE8SgSymqS1zCRQyGpcAnVfbpEuXfE= golang.org/x/sys v0.0.0-20190306220723-b294cbcfc56d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190425145619-16072639606e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e h1:D5TXcfTk7xF7hvieo4QErS3qqCB4teTffacDWr7CI+0= +golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -133,6 +174,7 @@ gopkg.in/DataDog/dd-trace-go.v1 v1.7.0/go.mod h1:DVp8HmDh8PuTu2Z0fVVlBsyWaC++fzw gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 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/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= @@ -140,3 +182,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M= +howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= diff --git a/test.sh b/test.sh index b68a3ac8..c5a43dc4 100755 --- a/test.sh +++ b/test.sh @@ -8,7 +8,7 @@ cd "${SCRIPT_DIR}" for build_tags in \ "" \ - "tracer_static tracer_static_jaeger tracer_static_lightstep tracer_static_datadog" \ + "tracer_static tracer_static_elastic tracer_static_jaeger tracer_static_lightstep tracer_static_datadog" \ ; do ( set -x; diff --git a/tracing/impl/elastic_tracer.go b/tracing/impl/elastic_tracer.go new file mode 100644 index 00000000..dae5ec01 --- /dev/null +++ b/tracing/impl/elastic_tracer.go @@ -0,0 +1,66 @@ +// +build tracer_static,tracer_static_elastic + +package impl + +import ( + "fmt" + "io" + "os" + + "go.elastic.co/apm" + "go.elastic.co/apm/transport" + "go.elastic.co/apm/module/apmot" + + opentracing "github.com/opentracing/opentracing-go" +) + +type elasticCloser struct { + tracer *apm.Tracer +} + +func (c *elasticCloser) Close() error { + c.tracer.Close() + return nil +} + +func elasticTracerFactory(config map[string]string) (opentracing.Tracer, io.Closer, error) { + var serviceName = ""; + var serviceVersion = ""; + var url = ""; + + // Convert the configuration map into a jaeger configuration + for k, v := range config { + switch k { + case "ServiceName": + serviceName = v; + case "url": + url = v; + default: + if k == keyStrictConnectionParsing { + continue + } + } + } + + if url != "" { + // ELASTIC_APM_SERVER_URL should typically set in the environment + // when the process is started. The InitDefault call below is only + // required in this case because the environment variable is set + // after the program has been initialized. + os.Setenv("ELASTIC_APM_SERVER_URL", url) + defer os.Unsetenv("ELASTIC_APM_SERVER_URL") + transport.InitDefault() + } + + tracer, err := apm.NewTracer(serviceName, serviceVersion) + if err != nil { + return nil, nil, fmt.Errorf("elastic tracer: unable to create tracer, review log messages") + } + + opentracer := apmot.New(apmot.WithTracer(tracer)) + return opentracer, &elasticCloser{tracer}, nil +} + +func init() { + registerTracer("elastic", elasticTracerFactory) +} diff --git a/vendor/github.com/armon/go-radix/.gitignore b/vendor/github.com/armon/go-radix/.gitignore new file mode 100644 index 00000000..00268614 --- /dev/null +++ b/vendor/github.com/armon/go-radix/.gitignore @@ -0,0 +1,22 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe diff --git a/vendor/github.com/armon/go-radix/.travis.yml b/vendor/github.com/armon/go-radix/.travis.yml new file mode 100644 index 00000000..1a0bbea6 --- /dev/null +++ b/vendor/github.com/armon/go-radix/.travis.yml @@ -0,0 +1,3 @@ +language: go +go: + - tip diff --git a/vendor/github.com/armon/go-radix/LICENSE b/vendor/github.com/armon/go-radix/LICENSE new file mode 100644 index 00000000..a5df10e6 --- /dev/null +++ b/vendor/github.com/armon/go-radix/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2014 Armon Dadgar + +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. diff --git a/vendor/github.com/armon/go-radix/README.md b/vendor/github.com/armon/go-radix/README.md new file mode 100644 index 00000000..26f42a28 --- /dev/null +++ b/vendor/github.com/armon/go-radix/README.md @@ -0,0 +1,38 @@ +go-radix [![Build Status](https://travis-ci.org/armon/go-radix.png)](https://travis-ci.org/armon/go-radix) +========= + +Provides the `radix` package that implements a [radix tree](http://en.wikipedia.org/wiki/Radix_tree). +The package only provides a single `Tree` implementation, optimized for sparse nodes. + +As a radix tree, it provides the following: + * O(k) operations. In many cases, this can be faster than a hash table since + the hash function is an O(k) operation, and hash tables have very poor cache locality. + * Minimum / Maximum value lookups + * Ordered iteration + +For an immutable variant, see [go-immutable-radix](https://github.com/hashicorp/go-immutable-radix). + +Documentation +============= + +The full documentation is available on [Godoc](http://godoc.org/github.com/armon/go-radix). + +Example +======= + +Below is a simple example of usage + +```go +// Create a tree +r := radix.New() +r.Insert("foo", 1) +r.Insert("bar", 2) +r.Insert("foobar", 2) + +// Find the longest prefix match +m, _, _ := r.LongestPrefix("foozip") +if m != "foo" { + panic("should be foo") +} +``` + diff --git a/vendor/github.com/armon/go-radix/go.mod b/vendor/github.com/armon/go-radix/go.mod new file mode 100644 index 00000000..4336aa29 --- /dev/null +++ b/vendor/github.com/armon/go-radix/go.mod @@ -0,0 +1 @@ +module github.com/armon/go-radix diff --git a/vendor/github.com/armon/go-radix/radix.go b/vendor/github.com/armon/go-radix/radix.go new file mode 100644 index 00000000..e2bb22eb --- /dev/null +++ b/vendor/github.com/armon/go-radix/radix.go @@ -0,0 +1,540 @@ +package radix + +import ( + "sort" + "strings" +) + +// WalkFn is used when walking the tree. Takes a +// key and value, returning if iteration should +// be terminated. +type WalkFn func(s string, v interface{}) bool + +// leafNode is used to represent a value +type leafNode struct { + key string + val interface{} +} + +// edge is used to represent an edge node +type edge struct { + label byte + node *node +} + +type node struct { + // leaf is used to store possible leaf + leaf *leafNode + + // prefix is the common prefix we ignore + prefix string + + // Edges should be stored in-order for iteration. + // We avoid a fully materialized slice to save memory, + // since in most cases we expect to be sparse + edges edges +} + +func (n *node) isLeaf() bool { + return n.leaf != nil +} + +func (n *node) addEdge(e edge) { + n.edges = append(n.edges, e) + n.edges.Sort() +} + +func (n *node) updateEdge(label byte, node *node) { + num := len(n.edges) + idx := sort.Search(num, func(i int) bool { + return n.edges[i].label >= label + }) + if idx < num && n.edges[idx].label == label { + n.edges[idx].node = node + return + } + panic("replacing missing edge") +} + +func (n *node) getEdge(label byte) *node { + num := len(n.edges) + idx := sort.Search(num, func(i int) bool { + return n.edges[i].label >= label + }) + if idx < num && n.edges[idx].label == label { + return n.edges[idx].node + } + return nil +} + +func (n *node) delEdge(label byte) { + num := len(n.edges) + idx := sort.Search(num, func(i int) bool { + return n.edges[i].label >= label + }) + if idx < num && n.edges[idx].label == label { + copy(n.edges[idx:], n.edges[idx+1:]) + n.edges[len(n.edges)-1] = edge{} + n.edges = n.edges[:len(n.edges)-1] + } +} + +type edges []edge + +func (e edges) Len() int { + return len(e) +} + +func (e edges) Less(i, j int) bool { + return e[i].label < e[j].label +} + +func (e edges) Swap(i, j int) { + e[i], e[j] = e[j], e[i] +} + +func (e edges) Sort() { + sort.Sort(e) +} + +// Tree implements a radix tree. This can be treated as a +// Dictionary abstract data type. The main advantage over +// a standard hash map is prefix-based lookups and +// ordered iteration, +type Tree struct { + root *node + size int +} + +// New returns an empty Tree +func New() *Tree { + return NewFromMap(nil) +} + +// NewFromMap returns a new tree containing the keys +// from an existing map +func NewFromMap(m map[string]interface{}) *Tree { + t := &Tree{root: &node{}} + for k, v := range m { + t.Insert(k, v) + } + return t +} + +// Len is used to return the number of elements in the tree +func (t *Tree) Len() int { + return t.size +} + +// longestPrefix finds the length of the shared prefix +// of two strings +func longestPrefix(k1, k2 string) int { + max := len(k1) + if l := len(k2); l < max { + max = l + } + var i int + for i = 0; i < max; i++ { + if k1[i] != k2[i] { + break + } + } + return i +} + +// Insert is used to add a newentry or update +// an existing entry. Returns if updated. +func (t *Tree) Insert(s string, v interface{}) (interface{}, bool) { + var parent *node + n := t.root + search := s + for { + // Handle key exhaution + if len(search) == 0 { + if n.isLeaf() { + old := n.leaf.val + n.leaf.val = v + return old, true + } + + n.leaf = &leafNode{ + key: s, + val: v, + } + t.size++ + return nil, false + } + + // Look for the edge + parent = n + n = n.getEdge(search[0]) + + // No edge, create one + if n == nil { + e := edge{ + label: search[0], + node: &node{ + leaf: &leafNode{ + key: s, + val: v, + }, + prefix: search, + }, + } + parent.addEdge(e) + t.size++ + return nil, false + } + + // Determine longest prefix of the search key on match + commonPrefix := longestPrefix(search, n.prefix) + if commonPrefix == len(n.prefix) { + search = search[commonPrefix:] + continue + } + + // Split the node + t.size++ + child := &node{ + prefix: search[:commonPrefix], + } + parent.updateEdge(search[0], child) + + // Restore the existing node + child.addEdge(edge{ + label: n.prefix[commonPrefix], + node: n, + }) + n.prefix = n.prefix[commonPrefix:] + + // Create a new leaf node + leaf := &leafNode{ + key: s, + val: v, + } + + // If the new key is a subset, add to to this node + search = search[commonPrefix:] + if len(search) == 0 { + child.leaf = leaf + return nil, false + } + + // Create a new edge for the node + child.addEdge(edge{ + label: search[0], + node: &node{ + leaf: leaf, + prefix: search, + }, + }) + return nil, false + } +} + +// Delete is used to delete a key, returning the previous +// value and if it was deleted +func (t *Tree) Delete(s string) (interface{}, bool) { + var parent *node + var label byte + n := t.root + search := s + for { + // Check for key exhaution + if len(search) == 0 { + if !n.isLeaf() { + break + } + goto DELETE + } + + // Look for an edge + parent = n + label = search[0] + n = n.getEdge(label) + if n == nil { + break + } + + // Consume the search prefix + if strings.HasPrefix(search, n.prefix) { + search = search[len(n.prefix):] + } else { + break + } + } + return nil, false + +DELETE: + // Delete the leaf + leaf := n.leaf + n.leaf = nil + t.size-- + + // Check if we should delete this node from the parent + if parent != nil && len(n.edges) == 0 { + parent.delEdge(label) + } + + // Check if we should merge this node + if n != t.root && len(n.edges) == 1 { + n.mergeChild() + } + + // Check if we should merge the parent's other child + if parent != nil && parent != t.root && len(parent.edges) == 1 && !parent.isLeaf() { + parent.mergeChild() + } + + return leaf.val, true +} + +// DeletePrefix is used to delete the subtree under a prefix +// Returns how many nodes were deleted +// Use this to delete large subtrees efficiently +func (t *Tree) DeletePrefix(s string) int { + return t.deletePrefix(nil, t.root, s) +} + +// delete does a recursive deletion +func (t *Tree) deletePrefix(parent, n *node, prefix string) int { + // Check for key exhaustion + if len(prefix) == 0 { + // Remove the leaf node + subTreeSize := 0 + //recursively walk from all edges of the node to be deleted + recursiveWalk(n, func(s string, v interface{}) bool { + subTreeSize++ + return false + }) + if n.isLeaf() { + n.leaf = nil + } + n.edges = nil // deletes the entire subtree + + // Check if we should merge the parent's other child + if parent != nil && parent != t.root && len(parent.edges) == 1 && !parent.isLeaf() { + parent.mergeChild() + } + t.size -= subTreeSize + return subTreeSize + } + + // Look for an edge + label := prefix[0] + child := n.getEdge(label) + if child == nil || (!strings.HasPrefix(child.prefix, prefix) && !strings.HasPrefix(prefix, child.prefix)) { + return 0 + } + + // Consume the search prefix + if len(child.prefix) > len(prefix) { + prefix = prefix[len(prefix):] + } else { + prefix = prefix[len(child.prefix):] + } + return t.deletePrefix(n, child, prefix) +} + +func (n *node) mergeChild() { + e := n.edges[0] + child := e.node + n.prefix = n.prefix + child.prefix + n.leaf = child.leaf + n.edges = child.edges +} + +// Get is used to lookup a specific key, returning +// the value and if it was found +func (t *Tree) Get(s string) (interface{}, bool) { + n := t.root + search := s + for { + // Check for key exhaution + if len(search) == 0 { + if n.isLeaf() { + return n.leaf.val, true + } + break + } + + // Look for an edge + n = n.getEdge(search[0]) + if n == nil { + break + } + + // Consume the search prefix + if strings.HasPrefix(search, n.prefix) { + search = search[len(n.prefix):] + } else { + break + } + } + return nil, false +} + +// LongestPrefix is like Get, but instead of an +// exact match, it will return the longest prefix match. +func (t *Tree) LongestPrefix(s string) (string, interface{}, bool) { + var last *leafNode + n := t.root + search := s + for { + // Look for a leaf node + if n.isLeaf() { + last = n.leaf + } + + // Check for key exhaution + if len(search) == 0 { + break + } + + // Look for an edge + n = n.getEdge(search[0]) + if n == nil { + break + } + + // Consume the search prefix + if strings.HasPrefix(search, n.prefix) { + search = search[len(n.prefix):] + } else { + break + } + } + if last != nil { + return last.key, last.val, true + } + return "", nil, false +} + +// Minimum is used to return the minimum value in the tree +func (t *Tree) Minimum() (string, interface{}, bool) { + n := t.root + for { + if n.isLeaf() { + return n.leaf.key, n.leaf.val, true + } + if len(n.edges) > 0 { + n = n.edges[0].node + } else { + break + } + } + return "", nil, false +} + +// Maximum is used to return the maximum value in the tree +func (t *Tree) Maximum() (string, interface{}, bool) { + n := t.root + for { + if num := len(n.edges); num > 0 { + n = n.edges[num-1].node + continue + } + if n.isLeaf() { + return n.leaf.key, n.leaf.val, true + } + break + } + return "", nil, false +} + +// Walk is used to walk the tree +func (t *Tree) Walk(fn WalkFn) { + recursiveWalk(t.root, fn) +} + +// WalkPrefix is used to walk the tree under a prefix +func (t *Tree) WalkPrefix(prefix string, fn WalkFn) { + n := t.root + search := prefix + for { + // Check for key exhaution + if len(search) == 0 { + recursiveWalk(n, fn) + return + } + + // Look for an edge + n = n.getEdge(search[0]) + if n == nil { + break + } + + // Consume the search prefix + if strings.HasPrefix(search, n.prefix) { + search = search[len(n.prefix):] + + } else if strings.HasPrefix(n.prefix, search) { + // Child may be under our search prefix + recursiveWalk(n, fn) + return + } else { + break + } + } + +} + +// WalkPath is used to walk the tree, but only visiting nodes +// from the root down to a given leaf. Where WalkPrefix walks +// all the entries *under* the given prefix, this walks the +// entries *above* the given prefix. +func (t *Tree) WalkPath(path string, fn WalkFn) { + n := t.root + search := path + for { + // Visit the leaf values if any + if n.leaf != nil && fn(n.leaf.key, n.leaf.val) { + return + } + + // Check for key exhaution + if len(search) == 0 { + return + } + + // Look for an edge + n = n.getEdge(search[0]) + if n == nil { + return + } + + // Consume the search prefix + if strings.HasPrefix(search, n.prefix) { + search = search[len(n.prefix):] + } else { + break + } + } +} + +// recursiveWalk is used to do a pre-order walk of a node +// recursively. Returns true if the walk should be aborted +func recursiveWalk(n *node, fn WalkFn) bool { + // Visit the leaf values if any + if n.leaf != nil && fn(n.leaf.key, n.leaf.val) { + return true + } + + // Recurse on the children + for _, e := range n.edges { + if recursiveWalk(e.node, fn) { + return true + } + } + return false +} + +// ToMap is used to walk the tree and convert it into a map +func (t *Tree) ToMap() map[string]interface{} { + out := make(map[string]interface{}, t.size) + t.Walk(func(k string, v interface{}) bool { + out[k] = v + return false + }) + return out +} diff --git a/vendor/github.com/certifi/gocertifi/gen.go b/vendor/github.com/certifi/gocertifi/gen.go deleted file mode 100644 index a3bbbd78..00000000 --- a/vendor/github.com/certifi/gocertifi/gen.go +++ /dev/null @@ -1,74 +0,0 @@ -// +build ignore - -package main - -import ( - "io/ioutil" - "log" - "net/http" - "os" - "text/template" - "time" -) - -func main() { - const url = "https://mkcert.org/generate/" - resp, err := http.Get(url) - if err != nil { - log.Fatal(err) - } - if resp.StatusCode != 200 { - log.Fatal("expected 200, got", resp.StatusCode) - } - defer resp.Body.Close() - - bundle, err := ioutil.ReadAll(resp.Body) - - fp, err := os.Create("certifi.go") - if err != nil { - log.Fatal(err) - } - defer fp.Close() - - tmpl.Execute(fp, struct { - Timestamp time.Time - URL string - Bundle string - }{ - Timestamp: time.Now(), - URL: url, - Bundle: string(bundle), - }) -} - -var tmpl = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT -// {{ .Timestamp }} -// {{ .URL }} - -package gocertifi - -//go:generate go run gen.go - -import ( - "crypto/x509" - "errors" -) - -const pemcerts string = ` + "`" + ` -{{ .Bundle }} -` + "`" + ` - -var ErrParseFailed = errors.New("gocertifi: error when parsing certificates") - -// CACerts builds an X.509 certificate pool containing the Mozilla CA -// Certificate bundle. Returns nil on error along with an appropriate error -// code. -func CACerts() (*x509.CertPool, error) { - pool := x509.NewCertPool() - ok := pool.AppendCertsFromPEM([]byte(pemcerts)) - if !ok { - return nil, ErrParseFailed - } - return pool, nil -} -`)) diff --git a/vendor/github.com/elastic/go-sysinfo/.appveyor.yml b/vendor/github.com/elastic/go-sysinfo/.appveyor.yml new file mode 100644 index 00000000..cd78f767 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/.appveyor.yml @@ -0,0 +1,61 @@ +# Version format +version: "{build}" + +image: Visual Studio 2015 + +# Environment variables +environment: + GOPATH: c:\gopath + GO111MODULE: on + GVM_GO_VERSION: 1.12.4 + GVM_DL: https://github.com/andrewkroh/gvm/releases/download/v0.2.0/gvm-windows-amd64.exe + +# Custom clone folder (variables are not expanded here). +clone_folder: c:\gopath\src\github.com\elastic\go-sysinfo + +# Cache mingw install until appveyor.yml is modified. +cache: + - C:\ProgramData\chocolatey\bin -> .appveyor.yml + - C:\ProgramData\chocolatey\lib -> .appveyor.yml + - C:\Users\appveyor\.gvm -> .appveyor.yml + - C:\Windows\System32\gvm.exe -> .appveyor.yml + +# Scripts that run after cloning repository +install: + - ps: >- + if(!(Test-Path "C:\Windows\System32\gvm.exe")) { + wget "$env:GVM_DL" -Outfile C:\Windows\System32\gvm.exe + } + - ps: gvm --format=powershell "$env:GVM_GO_VERSION" | Invoke-Expression + # AppVeyor has MinGW64. Make sure it's on the PATH. + - set PATH=C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1;%GOROOT%\bin;%PATH% + - set PATH=%GOPATH%\bin;%PATH% + - go version + - go env + - cmd /C "set ""GO111MODULE=off"" && go get github.com/elastic/go-licenser" + - python --version + +before_build: + - go mod verify + - go-licenser -d + - go run .ci/scripts/check_format.go + - go run .ci/scripts/check_lint.go + +build_script: + # Compile + - appveyor AddCompilationMessage "Starting Compile" + - cd c:\gopath\src\github.com\elastic\go-sysinfo + - go build + - appveyor AddCompilationMessage "Compile Success" + +test_script: + # Unit tests + - ps: Add-AppveyorTest "Unit Tests" -Outcome Running + - go test -v ./... + - ps: Update-AppveyorTest "Unit Tests" -Outcome Passed + +# To disable deployment +deploy: off + +# Notifications should only be setup using the AppVeyor UI so that +# forks can be created without inheriting the settings. diff --git a/vendor/github.com/elastic/go-sysinfo/.editorconfig b/vendor/github.com/elastic/go-sysinfo/.editorconfig new file mode 100644 index 00000000..8cc16d1c --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/.editorconfig @@ -0,0 +1,27 @@ +# See: http://editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.json] +indent_size = 2 +indent_style = space + +[*.py] +indent_style = space +indent_size = 4 + +[*.yml] +indent_style = space +indent_size = 2 + +[Makefile] +indent_style = tab + +[Vagrantfile] +indent_size = 2 +indent_style = space diff --git a/vendor/github.com/elastic/go-sysinfo/.gitattributes b/vendor/github.com/elastic/go-sysinfo/.gitattributes new file mode 100644 index 00000000..875f4996 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/.gitattributes @@ -0,0 +1,5 @@ +# Treat all files in the Go repo as binary, with no git magic updating +# line endings. Windows users contributing to Go will need to use a +# modern version of git and editors capable of LF line endings. + +* -text diff --git a/vendor/github.com/elastic/go-sysinfo/.gitignore b/vendor/github.com/elastic/go-sysinfo/.gitignore new file mode 100644 index 00000000..0abf7050 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/.gitignore @@ -0,0 +1,11 @@ +*.iml +*.swp +*.o +.idea +.vagrant +_obj + +*TEST.out +main.retry +testing/ssh_config +testing/ve diff --git a/vendor/github.com/elastic/go-sysinfo/.travis.yml b/vendor/github.com/elastic/go-sysinfo/.travis.yml new file mode 100644 index 00000000..aa9b03ff --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/.travis.yml @@ -0,0 +1,27 @@ +sudo: false + +language: go + +os: +- linux +- osx +- windows + +go: +- 1.12.x + +env: +- GO111MODULE=on + +go_import_path: github.com/elastic/go-sysinfo + +before_install: +- git config -l +- GO111MODULE=off go get -u github.com/elastic/go-licenser + +script: +- go mod verify +- go-licenser -d +- go run .ci/scripts/check_format.go +- go run .ci/scripts/check_lint.go +- go test -v ./... diff --git a/vendor/github.com/elastic/go-sysinfo/CHANGELOG.md b/vendor/github.com/elastic/go-sysinfo/CHANGELOG.md new file mode 100644 index 00000000..ce5aa2df --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/CHANGELOG.md @@ -0,0 +1,49 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [1.0.1] - 2019-05-08 + +### Fixed + +- Add support for new prometheus/procfs API. [#49](https://github.com/elastic/go-sysinfo/pull/49) + +## [1.0.0] - 2019-05-03 + +### Added + +- Add Windows provider implementation. [#22](https://github.com/elastic/go-sysinfo/pull/22) +- Add Windows process provider. [#26](https://github.com/elastic/go-sysinfo/pull/26) +- Add `OpenHandleEnumerator` and `OpenHandleCount` and implement these for Windows. [#27](https://github.com/elastic/go-sysinfo/pull/27) +- Add user info to Process. [#34](https://github.com/elastic/go-sysinfo/pull/34) +- Implement `Processes` for Darwin. [#35](https://github.com/elastic/go-sysinfo/pull/35) +- Add `Parent()` to `Process`. [#46](https://github.com/elastic/go-sysinfo/pull/46) + +### Fixed + +- Fix Windows registry handle leak. [#33](https://github.com/elastic/go-sysinfo/pull/33) +- Fix Linux host ID by search for older locations for the machine-id file. [#44](https://github.com/elastic/go-sysinfo/pull/44) + +### Changed + +- Changed the host containerized check to reduce false positives. [#42](https://github.com/elastic/go-sysinfo/pull/42) [#43](https://github.com/elastic/go-sysinfo/pull/43) + +[Unreleased]: https://github.com/elastic/go-sysinfo/compare/v1.0.1...HEAD +[1.0.1]: https://github.com/elastic/go-sysinfo/releases/tag/v1.0.1 +[1.0.0]: https://github.com/elastic/go-sysinfo/releases/tag/v1.0.0 diff --git a/vendor/github.com/elastic/go-sysinfo/LICENSE.txt b/vendor/github.com/elastic/go-sysinfo/LICENSE.txt new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/LICENSE.txt @@ -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. diff --git a/vendor/github.com/elastic/go-sysinfo/NOTICE.txt b/vendor/github.com/elastic/go-sysinfo/NOTICE.txt new file mode 100644 index 00000000..c813ad58 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/NOTICE.txt @@ -0,0 +1,5 @@ +Elastic go-sysinfo +Copyright 2017-2019 Elasticsearch B.V. + +This product includes software developed at +Elasticsearch, B.V. (https://www.elastic.co/). diff --git a/vendor/github.com/elastic/go-sysinfo/README.md b/vendor/github.com/elastic/go-sysinfo/README.md new file mode 100644 index 00000000..3a657a4b --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/README.md @@ -0,0 +1,53 @@ +# go-sysinfo + +[![Build Status](http://img.shields.io/travis/elastic/go-sysinfo.svg?style=flat-square)][travis] +[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] + +[travis]: http://travis-ci.org/elastic/go-sysinfo +[godocs]: http://godoc.org/github.com/elastic/go-sysinfo + +go-sysinfo is a library for collecting system information. This includes +information about the host machine and processes running on the host. + +The available features vary based on what has been implemented by the "provider" +for the operating system. At runtime you check to see if additional interfaces +are implemented by the returned `Host` or `Process`. For example: + +```go +process, err := sysinfo.Self() +if err != nil { + return err +} + +if handleCounter, ok := process.(types.OpenHandleCounter); ok { + count, err := handleCounter.OpenHandleCount() + if err != nil { + return err + } + log.Printf("%d open handles", count) +} +``` + +These tables show what methods are implemented as well as the extra interfaces +that are implemented. + +| `Host` Features | Darwin | Linux | Windows | +|------------------|--------|-------|---------| +| `Info()` | x | x | x | +| `Memory()` | x | x | x | +| `CPUTimer` | x | x | x | + +| `Process` Features | Darwin | Linux | Windows | +|------------------------|--------|-------|---------| +| `Info()` | x | x | x | +| `Memory()` | x | x | x | +| `User()` | x | x | x | +| `Parent()` | x | x | x | +| `CPUTimer` | x | x | x | +| `Environment` | x | x | | +| `OpenHandleEnumerator` | | x | | +| `OpenHandleCounter` | | x | | +| `Seccomp` | | x | | +| `Capabilities` | | x | | + + diff --git a/vendor/github.com/elastic/go-sysinfo/go.mod b/vendor/github.com/elastic/go-sysinfo/go.mod new file mode 100644 index 00000000..068a0d14 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/go.mod @@ -0,0 +1,11 @@ +module github.com/elastic/go-sysinfo + +require ( + github.com/elastic/go-windows v1.0.0 + github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 + github.com/pkg/errors v0.8.1 + github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 + github.com/stretchr/testify v1.3.0 + golang.org/x/sys v0.0.0-20190425145619-16072639606e + howett.net/plist v0.0.0-20181124034731-591f970eefbb +) diff --git a/vendor/github.com/elastic/go-sysinfo/go.sum b/vendor/github.com/elastic/go-sysinfo/go.sum new file mode 100644 index 00000000..c84ee015 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/go.sum @@ -0,0 +1,27 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/elastic/go-windows v1.0.0 h1:qLURgZFkkrYyTTkvYpsZIgf83AUsdIHfvlJaqaZ7aSY= +github.com/elastic/go-windows v1.0.0/go.mod h1:TsU0Nrp7/y3+VwE82FoZF8gC/XFg/Elz6CcloAxnPgU= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 h1:rp+c0RAYOWj8l6qbCUTSiRLG/iKnW3K3/QfPPuSsBt4= +github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901/go.mod h1:Z86h9688Y0wesXCyonoVr47MasHilkuLMqGhRZ4Hpak= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0 h1:c8R11WC8m7KNMkTv/0+Be8vvwo4I3/Ut9AC2FW8fX3U= +github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190425145619-16072639606e h1:4ktJgTV34+N3qOZUc5fAaG3Pb11qzMm3PkAoTAgUZ2I= +golang.org/x/sys v0.0.0-20190425145619-16072639606e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M= +howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= diff --git a/vendor/github.com/elastic/go-sysinfo/internal/registry/registry.go b/vendor/github.com/elastic/go-sysinfo/internal/registry/registry.go new file mode 100644 index 00000000..21ba2ed3 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/internal/registry/registry.go @@ -0,0 +1,58 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 registry + +import ( + "github.com/pkg/errors" + + "github.com/elastic/go-sysinfo/types" +) + +var ( + hostProvider HostProvider + processProvider ProcessProvider +) + +type HostProvider interface { + Host() (types.Host, error) +} + +type ProcessProvider interface { + Processes() ([]types.Process, error) + Process(pid int) (types.Process, error) + Self() (types.Process, error) +} + +func Register(provider interface{}) { + if h, ok := provider.(HostProvider); ok { + if hostProvider != nil { + panic(errors.Errorf("HostProvider already registered: %v", hostProvider)) + } + hostProvider = h + } + + if p, ok := provider.(ProcessProvider); ok { + if processProvider != nil { + panic(errors.Errorf("ProcessProvider already registered: %v", processProvider)) + } + processProvider = p + } +} + +func GetHostProvider() HostProvider { return hostProvider } +func GetProcessProvider() ProcessProvider { return processProvider } diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/arch_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/arch_darwin_amd64.go new file mode 100644 index 00000000..67348d90 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/arch_darwin_amd64.go @@ -0,0 +1,35 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 darwin + +import ( + "syscall" + + "github.com/pkg/errors" +) + +const hardwareMIB = "hw.machine" + +func Architecture() (string, error) { + arch, err := syscall.Sysctl(hardwareMIB) + if err != nil { + return "", errors.Wrap(err, "failed to get architecture") + } + + return arch, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/boottime_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/boottime_darwin_amd64.go new file mode 100644 index 00000000..927139fb --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/boottime_darwin_amd64.go @@ -0,0 +1,39 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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. + +// +build darwin,amd64,cgo + +package darwin + +import ( + "syscall" + "time" + + "github.com/pkg/errors" +) + +const kernBoottimeMIB = "kern.boottime" + +func BootTime() (time.Time, error) { + var tv syscall.Timeval + if err := sysctlByName(kernBoottimeMIB, &tv); err != nil { + return time.Time{}, errors.Wrap(err, "failed to get host uptime") + } + + bootTime := time.Unix(int64(tv.Sec), int64(tv.Usec)*int64(time.Microsecond)) + return bootTime, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/doc.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/doc.go new file mode 100644 index 00000000..20e80f06 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/doc.go @@ -0,0 +1,20 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 darwin implements the HostProvider and ProcessProvider interfaces +// for providing information about MacOS. +package darwin diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/host_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/host_darwin_amd64.go new file mode 100644 index 00000000..9ea1708d --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/host_darwin_amd64.go @@ -0,0 +1,226 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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. + +// +build darwin,amd64,cgo + +package darwin + +import ( + "os" + "time" + + "github.com/joeshaw/multierror" + "github.com/pkg/errors" + + "github.com/elastic/go-sysinfo/internal/registry" + "github.com/elastic/go-sysinfo/providers/shared" + "github.com/elastic/go-sysinfo/types" +) + +func init() { + registry.Register(darwinSystem{}) +} + +type darwinSystem struct{} + +func (s darwinSystem) Host() (types.Host, error) { + return newHost() +} + +type host struct { + info types.HostInfo +} + +func (h *host) Info() types.HostInfo { + return h.info +} + +func (h *host) CPUTime() (types.CPUTimes, error) { + cpu, err := getHostCPULoadInfo() + if err != nil { + return types.CPUTimes{}, errors.Wrap(err, "failed to get host CPU usage") + } + + ticksPerSecond := time.Duration(getClockTicks()) + + return types.CPUTimes{ + User: time.Duration(cpu.User) * time.Second / ticksPerSecond, + System: time.Duration(cpu.System) * time.Second / ticksPerSecond, + Idle: time.Duration(cpu.Idle) * time.Second / ticksPerSecond, + Nice: time.Duration(cpu.Nice) * time.Second / ticksPerSecond, + }, nil +} + +func (h *host) Memory() (*types.HostMemoryInfo, error) { + var mem types.HostMemoryInfo + + // Total physical memory. + if err := sysctlByName("hw.memsize", &mem.Total); err != nil { + return nil, errors.Wrap(err, "failed to get total physical memory") + } + + // Page size for computing byte totals. + pageSizeBytes, err := getPageSize() + if err != nil { + return nil, errors.Wrap(err, "failed to get page size") + } + + // Virtual Memory Statistics + vmStat, err := getHostVMInfo64() + if err != nil { + return nil, errors.Wrap(err, "failed to get virtual memory statistics") + } + + // Swap + swap, err := getSwapUsage() + if err != nil { + return nil, errors.Wrap(err, "failed to get swap usage") + } + + inactiveBytes := uint64(vmStat.Inactive_count) * pageSizeBytes + purgeableBytes := uint64(vmStat.Purgeable_count) * pageSizeBytes + mem.Metrics = map[string]uint64{ + "active_bytes": uint64(vmStat.Active_count) * pageSizeBytes, + "compressed_bytes": uint64(vmStat.Compressor_page_count) * pageSizeBytes, + "compressions_bytes": uint64(vmStat.Compressions) * pageSizeBytes, // Cumulative compressions. + "copy_on_write_faults": vmStat.Cow_faults, + "decompressions_bytes": uint64(vmStat.Decompressions) * pageSizeBytes, // Cumulative decompressions. + "external_bytes": uint64(vmStat.External_page_count) * pageSizeBytes, // File Cache / File-backed pages + "inactive_bytes": inactiveBytes, + "internal_bytes": uint64(vmStat.Internal_page_count) * pageSizeBytes, // App Memory / Anonymous + "page_ins_bytes": uint64(vmStat.Pageins) * pageSizeBytes, + "page_outs_bytes": uint64(vmStat.Pageouts) * pageSizeBytes, + "purgeable_bytes": purgeableBytes, + "purged_bytes": uint64(vmStat.Purges) * pageSizeBytes, + "reactivated_bytes": uint64(vmStat.Reactivations) * pageSizeBytes, + "speculative_bytes": uint64(vmStat.Speculative_count) * pageSizeBytes, + "swap_ins_bytes": uint64(vmStat.Swapins) * pageSizeBytes, + "swap_outs_bytes": uint64(vmStat.Swapouts) * pageSizeBytes, + "throttled_bytes": uint64(vmStat.Throttled_count) * pageSizeBytes, + "translation_faults": vmStat.Faults, + "uncompressed_bytes": uint64(vmStat.Total_uncompressed_pages_in_compressor) * pageSizeBytes, + "wired_bytes": uint64(vmStat.Wire_count) * pageSizeBytes, + "zero_filled_bytes": uint64(vmStat.Zero_fill_count) * pageSizeBytes, + } + + // From Activity Monitor: Memory Used = App Memory (internal) + Wired + Compressed + // https://support.apple.com/en-us/HT201538 + mem.Used = uint64(vmStat.Internal_page_count+vmStat.Wire_count+vmStat.Compressor_page_count) * pageSizeBytes + mem.Free = uint64(vmStat.Free_count) * pageSizeBytes + mem.Available = mem.Free + inactiveBytes + purgeableBytes + mem.VirtualTotal = swap.Total + mem.VirtualUsed = swap.Used + mem.VirtualFree = swap.Available + + return &mem, nil +} + +func newHost() (*host, error) { + h := &host{} + r := &reader{} + r.architecture(h) + r.bootTime(h) + r.hostname(h) + r.network(h) + r.kernelVersion(h) + r.os(h) + r.time(h) + r.uniqueID(h) + return h, r.Err() +} + +type reader struct { + errs []error +} + +func (r *reader) addErr(err error) bool { + if err != nil { + if errors.Cause(err) != types.ErrNotImplemented { + r.errs = append(r.errs, err) + } + return true + } + return false +} + +func (r *reader) Err() error { + if len(r.errs) > 0 { + return &multierror.MultiError{Errors: r.errs} + } + return nil +} + +func (r *reader) architecture(h *host) { + v, err := Architecture() + if r.addErr(err) { + return + } + h.info.Architecture = v +} + +func (r *reader) bootTime(h *host) { + v, err := BootTime() + if r.addErr(err) { + return + } + h.info.BootTime = v +} + +func (r *reader) hostname(h *host) { + v, err := os.Hostname() + if r.addErr(err) { + return + } + h.info.Hostname = v +} + +func (r *reader) network(h *host) { + ips, macs, err := shared.Network() + if r.addErr(err) { + return + } + h.info.IPs = ips + h.info.MACs = macs +} + +func (r *reader) kernelVersion(h *host) { + v, err := KernelVersion() + if r.addErr(err) { + return + } + h.info.KernelVersion = v +} + +func (r *reader) os(h *host) { + v, err := OperatingSystem() + if r.addErr(err) { + return + } + h.info.OS = v +} + +func (r *reader) time(h *host) { + h.info.Timezone, h.info.TimezoneOffsetSec = time.Now().Zone() +} + +func (r *reader) uniqueID(h *host) { + v, err := MachineID() + if r.addErr(err) { + return + } + h.info.UniqueID = v +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/kernel_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/kernel_darwin_amd64.go new file mode 100644 index 00000000..20b67217 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/kernel_darwin_amd64.go @@ -0,0 +1,35 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 darwin + +import ( + "syscall" + + "github.com/pkg/errors" +) + +const kernelReleaseMIB = "kern.osrelease" + +func KernelVersion() (string, error) { + version, err := syscall.Sysctl(kernelReleaseMIB) + if err != nil { + return "", errors.Wrap(err, "failed to get kernel version") + } + + return version, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/machineid_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/machineid_darwin_amd64.go new file mode 100644 index 00000000..3b3e6ada --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/machineid_darwin_amd64.go @@ -0,0 +1,61 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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. + +// +build darwin,amd64,cgo + +package darwin + +// #include +// #include +import "C" + +import ( + "unsafe" + + "github.com/pkg/errors" +) + +// MachineID returns the Hardware UUID also accessible via +// About this Mac -> System Report and as the field +// IOPlatformUUID in the output of "ioreg -d2 -c IOPlatformExpertDevice". +func MachineID() (string, error) { + return getHostUUID() +} + +func getHostUUID() (string, error) { + var uuidC C.uuid_t + var id [unsafe.Sizeof(uuidC)]C.uchar + wait := C.struct_timespec{5, 0} // 5 seconds + + ret, err := C.gethostuuid(&id[0], &wait) + if ret != 0 { + if err != nil { + return "", errors.Wrapf(err, "gethostuuid failed with %v", ret) + } + + return "", errors.Errorf("gethostuuid failed with %v", ret) + } + + var uuidStringC C.uuid_string_t + var uuid [unsafe.Sizeof(uuidStringC)]C.char + _, err = C.uuid_unparse_upper(&id[0], &uuid[0]) + if err != nil { + return "", errors.Wrap(err, "uuid_unparse_upper failed") + } + + return C.GoString(&uuid[0]), nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/memory_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/memory_darwin_amd64.go new file mode 100644 index 00000000..4963a4fd --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/memory_darwin_amd64.go @@ -0,0 +1,35 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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. + +// +build darwin,amd64,cgo + +package darwin + +import ( + "github.com/pkg/errors" +) + +const hwMemsizeMIB = "hw.memsize" + +func MemTotal() (uint64, error) { + var size uint64 + if err := sysctlByName(hwMemsizeMIB, &size); err != nil { + return 0, errors.Wrap(err, "failed to get mem total") + } + + return size, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/os.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/os.go new file mode 100644 index 00000000..06cb68e7 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/os.go @@ -0,0 +1,93 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 darwin + +import ( + "io/ioutil" + "strconv" + "strings" + + "github.com/pkg/errors" + "howett.net/plist" + + "github.com/elastic/go-sysinfo/types" +) + +const ( + systemVersionPlist = "/System/Library/CoreServices/SystemVersion.plist" + + plistProductName = "ProductName" + plistProductVersion = "ProductVersion" + plistProductBuildVersion = "ProductBuildVersion" +) + +func OperatingSystem() (*types.OSInfo, error) { + data, err := ioutil.ReadFile(systemVersionPlist) + if err != nil { + return nil, errors.Wrap(err, "failed to read plist file") + } + + return getOSInfo(data) +} + +func getOSInfo(data []byte) (*types.OSInfo, error) { + attrs := map[string]string{} + if _, err := plist.Unmarshal(data, &attrs); err != nil { + return nil, errors.Wrap(err, "failed to unmarshal plist data") + } + + productName, found := attrs[plistProductName] + if !found { + return nil, errors.Errorf("plist key %v not found", plistProductName) + } + + version, found := attrs[plistProductVersion] + if !found { + return nil, errors.Errorf("plist key %v not found", plistProductVersion) + } + + build, found := attrs[plistProductBuildVersion] + if !found { + return nil, errors.Errorf("plist key %v not found", plistProductBuildVersion) + } + + var major, minor, patch int + for i, v := range strings.SplitN(version, ".", 3) { + switch i { + case 0: + major, _ = strconv.Atoi(v) + case 1: + minor, _ = strconv.Atoi(v) + case 2: + patch, _ = strconv.Atoi(v) + default: + break + } + } + + return &types.OSInfo{ + Family: "darwin", + Platform: "darwin", + Name: productName, + Version: version, + Major: major, + Minor: minor, + Patch: patch, + Build: build, + }, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/process_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/process_darwin_amd64.go new file mode 100644 index 00000000..a2122038 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/process_darwin_amd64.go @@ -0,0 +1,283 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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. + +// +build darwin,amd64,cgo + +package darwin + +// #cgo LDFLAGS:-lproc +// #include +// #include +import "C" + +import ( + "bytes" + "encoding/binary" + "os" + "strconv" + "time" + "unsafe" + + "github.com/pkg/errors" + + "github.com/elastic/go-sysinfo/types" +) + +//go:generate sh -c "go tool cgo -godefs defs_darwin.go > ztypes_darwin_amd64.go" + +func (s darwinSystem) Processes() ([]types.Process, error) { + n, err := C.proc_listallpids(nil, 0) + if err != nil { + return nil, errors.Wrapf(err, "error getting process count from proc_listallpids (n = %v)", n) + } else if n <= 0 { + return nil, errors.Errorf("proc_listallpids returned %v", n) + } + + var pid C.int + bufsize := n * C.int(unsafe.Sizeof(pid)) + buf := make([]byte, bufsize) + n, err = C.proc_listallpids(unsafe.Pointer(&buf[0]), bufsize) + if err != nil { + return nil, errors.Wrapf(err, "error getting processes from proc_listallpids (n = %v)", n) + } else if n <= 0 { + return nil, errors.Errorf("proc_listallpids returned %v", n) + } + + bbuf := bytes.NewBuffer(buf) + processes := make([]types.Process, 0, n) + for i := 0; i < int(n); i++ { + err = binary.Read(bbuf, binary.LittleEndian, &pid) + if err != nil { + return nil, errors.Wrap(err, "error reading binary list of PIDs") + } + + if pid == 0 { + continue + } + + processes = append(processes, &process{pid: int(pid)}) + } + return processes, nil +} + +func (s darwinSystem) Process(pid int) (types.Process, error) { + p := process{pid: pid} + + return &p, nil +} + +func (s darwinSystem) Self() (types.Process, error) { + return s.Process(os.Getpid()) +} + +type process struct { + info *types.ProcessInfo + pid int + cwd string + exe string + args []string + env map[string]string +} + +func (p *process) PID() int { + return p.pid +} + +func (p *process) Parent() (types.Process, error) { + info, err := p.Info() + if err != nil { + return nil, err + } + + return &process{pid: info.PPID}, nil +} + +func (p *process) Info() (types.ProcessInfo, error) { + if p.info != nil { + return *p.info, nil + } + + var task procTaskAllInfo + if err := getProcTaskAllInfo(p.pid, &task); err != nil { + return types.ProcessInfo{}, err + } + + var vnode procVnodePathInfo + if err := getProcVnodePathInfo(p.pid, &vnode); err != nil { + return types.ProcessInfo{}, err + } + + if err := kern_procargs(p.pid, p); err != nil { + return types.ProcessInfo{}, err + } + + p.info = &types.ProcessInfo{ + Name: int8SliceToString(task.Pbsd.Pbi_name[:]), + PID: p.pid, + PPID: int(task.Pbsd.Pbi_ppid), + CWD: int8SliceToString(vnode.Cdir.Path[:]), + Exe: p.exe, + Args: p.args, + StartTime: time.Unix(int64(task.Pbsd.Pbi_start_tvsec), + int64(task.Pbsd.Pbi_start_tvusec)*int64(time.Microsecond)), + } + + return *p.info, nil +} + +func (p *process) User() (types.UserInfo, error) { + var task procTaskAllInfo + if err := getProcTaskAllInfo(p.pid, &task); err != nil { + return types.UserInfo{}, err + } + + return types.UserInfo{ + UID: strconv.Itoa(int(task.Pbsd.Pbi_ruid)), + EUID: strconv.Itoa(int(task.Pbsd.Pbi_uid)), + SUID: strconv.Itoa(int(task.Pbsd.Pbi_svuid)), + GID: strconv.Itoa(int(task.Pbsd.Pbi_rgid)), + EGID: strconv.Itoa(int(task.Pbsd.Pbi_gid)), + SGID: strconv.Itoa(int(task.Pbsd.Pbi_svgid)), + }, nil +} + +func (p *process) Environment() (map[string]string, error) { + return p.env, nil +} + +func (p *process) CPUTime() (types.CPUTimes, error) { + var task procTaskAllInfo + if err := getProcTaskAllInfo(p.pid, &task); err != nil { + return types.CPUTimes{}, err + } + return types.CPUTimes{ + User: time.Duration(task.Ptinfo.Total_user), + System: time.Duration(task.Ptinfo.Total_system), + }, nil +} + +func (p *process) Memory() (types.MemoryInfo, error) { + var task procTaskAllInfo + if err := getProcTaskAllInfo(p.pid, &task); err != nil { + return types.MemoryInfo{}, err + } + return types.MemoryInfo{ + Virtual: task.Ptinfo.Virtual_size, + Resident: task.Ptinfo.Resident_size, + Metrics: map[string]uint64{ + "page_ins": uint64(task.Ptinfo.Pageins), + "page_faults": uint64(task.Ptinfo.Faults), + }, + }, nil +} + +func getProcTaskAllInfo(pid int, info *procTaskAllInfo) error { + size := C.int(unsafe.Sizeof(*info)) + ptr := unsafe.Pointer(info) + + n, err := C.proc_pidinfo(C.int(pid), C.PROC_PIDTASKALLINFO, 0, ptr, size) + if err != nil { + return err + } else if n != size { + return errors.New("failed to read process info with proc_pidinfo") + } + + return nil +} + +func getProcVnodePathInfo(pid int, info *procVnodePathInfo) error { + size := C.int(unsafe.Sizeof(*info)) + ptr := unsafe.Pointer(info) + + n := C.proc_pidinfo(C.int(pid), C.PROC_PIDVNODEPATHINFO, 0, ptr, size) + if n != size { + return errors.New("failed to read vnode info with proc_pidinfo") + } + + return nil +} + +var nullTerminator = []byte{0} + +// wrapper around sysctl KERN_PROCARGS2 +// callbacks params are optional, +// up to the caller as to which pieces of data they want +func kern_procargs(pid int, p *process) error { + mib := []C.int{C.CTL_KERN, C.KERN_PROCARGS2, C.int(pid)} + var data []byte + if err := sysctl(mib, &data); err != nil { + return nil + } + buf := bytes.NewBuffer(data) + + // argc + var argc int32 + if err := binary.Read(buf, binary.LittleEndian, &argc); err != nil { + return err + } + + // exe + lines := bytes.Split(buf.Bytes(), nullTerminator) + p.exe = string(lines[0]) + lines = lines[1:] + + // skip nulls + for len(lines) > 0 { + if len(lines[0]) == 0 { + lines = lines[1:] + continue + } + break + } + + // args + for i := 0; i < int(argc); i++ { + p.args = append(p.args, string(lines[0])) + lines = lines[1:] + } + + // env vars + env := make(map[string]string, len(lines)) + for _, l := range lines { + if len(l) == 0 { + break + } + parts := bytes.SplitN(l, []byte{'='}, 2) + if len(parts) != 2 { + return errors.New("failed to parse") + } + key := string(parts[0]) + value := string(parts[1]) + env[key] = value + } + p.env = env + + return nil +} + +func int8SliceToString(s []int8) string { + buf := bytes.NewBuffer(make([]byte, len(s))) + buf.Reset() + + for _, b := range s { + if b == 0 { + break + } + buf.WriteByte(byte(b)) + } + return buf.String() +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/syscall_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/syscall_darwin_amd64.go new file mode 100644 index 00000000..1b6832ca --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/syscall_darwin_amd64.go @@ -0,0 +1,240 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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. + +// +build darwin,amd64,cgo + +package darwin + +/* +#cgo LDFLAGS:-lproc +#include +#include +#include +#include +*/ +import "C" + +import ( + "bytes" + "encoding/binary" + "fmt" + "sync" + "syscall" + "unsafe" + + "github.com/pkg/errors" +) + +// Single-word zero for use when we need a valid pointer to 0 bytes. +// See mksyscall.pl. +var _zero uintptr + +// Buffer Pool + +var bufferPool = sync.Pool{ + New: func() interface{} { + return &poolMem{ + buf: make([]byte, argMax), + } + }, +} + +type poolMem struct { + buf []byte + pool *sync.Pool +} + +func getPoolMem() *poolMem { + pm := bufferPool.Get().(*poolMem) + pm.buf = pm.buf[0:cap(pm.buf)] + pm.pool = &bufferPool + return pm +} + +func (m *poolMem) Release() { m.pool.Put(m) } + +// Common errors. + +// Do the interface allocations only once for common +// Errno values. +var ( + errEAGAIN error = syscall.EAGAIN + errEINVAL error = syscall.EINVAL + errENOENT error = syscall.ENOENT +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case syscall.EAGAIN: + return errEAGAIN + case syscall.EINVAL: + return errEINVAL + case syscall.ENOENT: + return errENOENT + } + return e +} + +func _sysctl(mib []C.int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { + var _p0 unsafe.Pointer + if len(mib) > 0 { + _p0 = unsafe.Pointer(&mib[0]) + } else { + _p0 = unsafe.Pointer(&_zero) + } + _, _, e1 := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(_p0), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// Translate "kern.hostname" to []_C_int{0,1,2,3}. +func nametomib(name string) (mib []C.int, err error) { + const siz = unsafe.Sizeof(mib[0]) + + // NOTE(rsc): It seems strange to set the buffer to have + // size CTL_MAXNAME+2 but use only CTL_MAXNAME + // as the size. I don't know why the +2 is here, but the + // kernel uses +2 for its own implementation of this function. + // I am scared that if we don't include the +2 here, the kernel + // will silently write 2 words farther than we specify + // and we'll get memory corruption. + var buf [C.CTL_MAXNAME + 2]C.int + n := uintptr(C.CTL_MAXNAME) * siz + + p := (*byte)(unsafe.Pointer(&buf[0])) + bytes, err := syscall.ByteSliceFromString(name) + if err != nil { + return nil, err + } + + // Magic sysctl: "setting" 0.3 to a string name + // lets you read back the array of integers form. + if err = _sysctl([]C.int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil { + return nil, err + } + return buf[0 : n/siz], nil +} + +func sysctl(mib []C.int, value interface{}) error { + mem := getPoolMem() + defer mem.Release() + + size := uintptr(len(mem.buf)) + if err := _sysctl(mib, &mem.buf[0], &size, nil, 0); err != nil { + return err + } + data := mem.buf[0:size] + + switch v := value.(type) { + case *[]byte: + out := make([]byte, len(data)) + copy(out, data) + *v = out + return nil + default: + return binary.Read(bytes.NewReader(data), binary.LittleEndian, v) + } +} + +func sysctlByName(name string, out interface{}) error { + mib, err := nametomib(name) + if err != nil { + return err + } + + return sysctl(mib, out) +} + +type cpuUsage struct { + User uint32 + System uint32 + Idle uint32 + Nice uint32 +} + +func getHostCPULoadInfo() (*cpuUsage, error) { + var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT + var cpu cpuUsage + status := C.host_statistics(C.host_t(C.mach_host_self()), + C.HOST_CPU_LOAD_INFO, + C.host_info_t(unsafe.Pointer(&cpu)), + &count) + + if status != C.KERN_SUCCESS { + return nil, errors.Errorf("host_statistics returned status %d", status) + } + + return &cpu, nil +} + +// getClockTicks returns the number of click ticks in one jiffie. +func getClockTicks() int { + return int(C.sysconf(C._SC_CLK_TCK)) +} + +func getHostVMInfo64() (*vmStatistics64Data, error) { + var count C.mach_msg_type_number_t = C.HOST_VM_INFO64_COUNT + + var vmStat vmStatistics64Data + status := C.host_statistics64( + C.host_t(C.mach_host_self()), + C.HOST_VM_INFO64, + C.host_info_t(unsafe.Pointer(&vmStat)), + &count) + + if status != C.KERN_SUCCESS { + return nil, fmt.Errorf("host_statistics64 returned status %d", status) + } + + return &vmStat, nil +} + +func getPageSize() (uint64, error) { + var pageSize vmSize + status := C.host_page_size( + C.host_t(C.mach_host_self()), + (*C.vm_size_t)(unsafe.Pointer(&pageSize))) + if status != C.KERN_SUCCESS { + return 0, errors.Errorf("host_page_size returned status %d", status) + } + + return uint64(pageSize), nil +} + +// From sysctl.h - xsw_usage. +type swapUsage struct { + Total uint64 + Available uint64 + Used uint64 + PageSize uint64 +} + +const vmSwapUsageMIB = "vm.swapusage" + +func getSwapUsage() (*swapUsage, error) { + var swap swapUsage + if err := sysctlByName(vmSwapUsageMIB, &swap); err != nil { + return nil, err + } + return &swap, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/darwin/ztypes_darwin_amd64.go b/vendor/github.com/elastic/go-sysinfo/providers/darwin/ztypes_darwin_amd64.go new file mode 100644 index 00000000..4ad67792 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/darwin/ztypes_darwin_amd64.go @@ -0,0 +1,187 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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. + +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs defs_darwin.go + +package darwin + +type processState uint32 + +const ( + stateSIDL processState = iota + 1 + stateRun + stateSleep + stateStop + stateZombie +) + +const argMax = 0x40000 + +type bsdInfo struct { + Pbi_flags uint32 + Pbi_status uint32 + Pbi_xstatus uint32 + Pbi_pid uint32 + Pbi_ppid uint32 + Pbi_uid uint32 + Pbi_gid uint32 + Pbi_ruid uint32 + Pbi_rgid uint32 + Pbi_svuid uint32 + Pbi_svgid uint32 + Rfu_1 uint32 + Pbi_comm [16]int8 + Pbi_name [32]int8 + Pbi_nfiles uint32 + Pbi_pgid uint32 + Pbi_pjobc uint32 + E_tdev uint32 + E_tpgid uint32 + Pbi_nice int32 + Pbi_start_tvsec uint64 + Pbi_start_tvusec uint64 +} + +type procTaskInfo struct { + Virtual_size uint64 + Resident_size uint64 + Total_user uint64 + Total_system uint64 + Threads_user uint64 + Threads_system uint64 + Policy int32 + Faults int32 + Pageins int32 + Cow_faults int32 + Messages_sent int32 + Messages_received int32 + Syscalls_mach int32 + Syscalls_unix int32 + Csw int32 + Threadnum int32 + Numrunning int32 + Priority int32 +} + +type procTaskAllInfo struct { + Pbsd bsdInfo + Ptinfo procTaskInfo +} + +type vinfoStat struct { + Dev uint32 + Mode uint16 + Nlink uint16 + Ino uint64 + Uid uint32 + Gid uint32 + Atime int64 + Atimensec int64 + Mtime int64 + Mtimensec int64 + Ctime int64 + Ctimensec int64 + Birthtime int64 + Birthtimensec int64 + Size int64 + Blocks int64 + Blksize int32 + Flags uint32 + Gen uint32 + Rdev uint32 + Qspare [2]int64 +} + +type fsid struct { + Val [2]int32 +} + +type vnodeInfo struct { + Stat vinfoStat + Type int32 + Pad int32 + Fsid fsid +} + +type vnodeInfoPath struct { + Vi vnodeInfo + Path [1024]int8 +} + +type procVnodePathInfo struct { + Cdir vnodeInfoPath + Rdir vnodeInfoPath +} + +type vmStatisticsData struct { + Free_count uint32 + Active_count uint32 + Inactive_count uint32 + Wire_count uint32 + Zero_fill_count uint32 + Reactivations uint32 + Pageins uint32 + Pageouts uint32 + Faults uint32 + Cow_faults uint32 + Lookups uint32 + Hits uint32 + Purgeable_count uint32 + Purges uint32 + Speculative_count uint32 +} + +type vmStatistics64Data struct { + Free_count uint32 + Active_count uint32 + Inactive_count uint32 + Wire_count uint32 + Zero_fill_count uint64 + Reactivations uint64 + Pageins uint64 + Pageouts uint64 + Faults uint64 + Cow_faults uint64 + Lookups uint64 + Hits uint64 + Purges uint64 + Purgeable_count uint32 + Speculative_count uint32 + Decompressions uint64 + Compressions uint64 + Swapins uint64 + Swapouts uint64 + Compressor_page_count uint32 + Throttled_count uint32 + External_page_count uint32 + Internal_page_count uint32 + Total_uncompressed_pages_in_compressor uint64 +} + +type vmSize uint64 + +const ( + cpuStateUser = 0x0 + cpuStateSystem = 0x1 + cpuStateIdle = 0x2 + cpuStateNice = 0x3 +) + +type hostCPULoadInfo struct { + Ticks [4]uint32 +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/arch_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/arch_linux.go new file mode 100644 index 00000000..13a9574c --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/arch_linux.go @@ -0,0 +1,41 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "syscall" + + "github.com/pkg/errors" +) + +func Architecture() (string, error) { + var uname syscall.Utsname + if err := syscall.Uname(&uname); err != nil { + return "", errors.Wrap(err, "architecture") + } + + data := make([]byte, 0, len(uname.Machine)) + for _, v := range uname.Machine { + if v == 0 { + break + } + data = append(data, byte(v)) + } + + return string(data), nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/boottime_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/boottime_linux.go new file mode 100644 index 00000000..e229d54e --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/boottime_linux.go @@ -0,0 +1,47 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "sync" + "time" + + "github.com/prometheus/procfs" +) + +var ( + bootTimeValue time.Time // Cached boot time. + bootTimeLock sync.Mutex // Lock that guards access to bootTime. +) + +func bootTime(fs procfs.FS) (time.Time, error) { + bootTimeLock.Lock() + defer bootTimeLock.Unlock() + + if !bootTimeValue.IsZero() { + return bootTimeValue, nil + } + + stat, err := fs.NewStat() + if err != nil { + return time.Time{}, err + } + + bootTimeValue = time.Unix(int64(stat.BootTime), 0) + return bootTimeValue, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/capabilities_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/capabilities_linux.go new file mode 100644 index 00000000..c13e0402 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/capabilities_linux.go @@ -0,0 +1,117 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "strconv" + + "github.com/elastic/go-sysinfo/types" +) + +// capabilityNames is mapping of capability constant values to names. +// +// Generated with: +// curl -s https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/capability.h | \ +// grep -P '^#define CAP_\w+\s+\d+' | perl -pe 's/#define (\w+)\s+(\d+)/\2: "\1",/g' +var capabilityNames = map[int]string{ + 0: "chown", + 1: "dac_override", + 2: "dac_read_search", + 3: "fowner", + 4: "fsetid", + 5: "kill", + 6: "setgid", + 7: "setuid", + 8: "setpcap", + 9: "linux_immutable", + 10: "net_bind_service", + 11: "net_broadcast", + 12: "net_admin", + 13: "net_raw", + 14: "ipc_lock", + 15: "ipc_owner", + 16: "sys_module", + 17: "sys_rawio", + 18: "sys_chroot", + 19: "sys_ptrace", + 20: "sys_pacct", + 21: "sys_admin", + 22: "sys_boot", + 23: "sys_nice", + 24: "sys_resource", + 25: "sys_time", + 26: "sys_tty_config", + 27: "mknod", + 28: "lease", + 29: "audit_write", + 30: "audit_control", + 31: "setfcap", + 32: "mac_override", + 33: "mac_admin", + 34: "syslog", + 35: "wake_alarm", + 36: "block_suspend", + 37: "audit_read", +} + +func capabilityName(num int) string { + name, found := capabilityNames[num] + if found { + return name + } + + return strconv.Itoa(num) +} + +func readCapabilities(content []byte) (*types.CapabilityInfo, error) { + var cap types.CapabilityInfo + + err := parseKeyValue(content, ":", func(key, value []byte) error { + var err error + switch string(key) { + case "CapInh": + cap.Inheritable, err = decodeBitMap(string(value), capabilityName) + if err != nil { + return err + } + case "CapPrm": + cap.Permitted, err = decodeBitMap(string(value), capabilityName) + if err != nil { + return err + } + case "CapEff": + cap.Effective, err = decodeBitMap(string(value), capabilityName) + if err != nil { + return err + } + case "CapBnd": + cap.Bounding, err = decodeBitMap(string(value), capabilityName) + if err != nil { + return err + } + case "CapAmb": + cap.Ambient, err = decodeBitMap(string(value), capabilityName) + if err != nil { + return err + } + } + return nil + }) + + return &cap, err +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/container.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/container.go new file mode 100644 index 00000000..6081e0c4 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/container.go @@ -0,0 +1,58 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "bufio" + "bytes" + "io/ioutil" + "os" + + "github.com/pkg/errors" +) + +const procOneCgroup = "/proc/1/cgroup" + +// IsContainerized returns true if this process is containerized. +func IsContainerized() (bool, error) { + data, err := ioutil.ReadFile(procOneCgroup) + if err != nil { + if os.IsNotExist(err) { + return false, nil + } + + return false, errors.Wrap(err, "failed to read process cgroups") + } + + return isContainerizedCgroup(data) +} + +func isContainerizedCgroup(data []byte) (bool, error) { + s := bufio.NewScanner(bytes.NewReader(data)) + for n := 0; s.Scan(); n++ { + line := s.Bytes() + + // Following a suggestion on Stack Overflow on how to detect + // being inside a container: https://stackoverflow.com/a/20012536/235203 + if bytes.Contains(line, []byte("docker")) || bytes.Contains(line, []byte("lxc")) { + return true, nil + } + } + + return false, s.Err() +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/doc.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/doc.go new file mode 100644 index 00000000..53d3c36c --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/doc.go @@ -0,0 +1,20 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux implements the HostProvider and ProcessProvider interfaces +// for providing information about Linux. +package linux diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/host_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/host_linux.go new file mode 100644 index 00000000..9b09ddff --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/host_linux.go @@ -0,0 +1,210 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "io/ioutil" + "os" + "path/filepath" + "time" + + "github.com/joeshaw/multierror" + "github.com/pkg/errors" + "github.com/prometheus/procfs" + + "github.com/elastic/go-sysinfo/internal/registry" + "github.com/elastic/go-sysinfo/providers/shared" + "github.com/elastic/go-sysinfo/types" +) + +func init() { + registry.Register(newLinuxSystem("")) +} + +type linuxSystem struct { + procFS procFS +} + +func newLinuxSystem(hostFS string) linuxSystem { + mountPoint := filepath.Join(hostFS, procfs.DefaultMountPoint) + fs, _ := procfs.NewFS(mountPoint) + return linuxSystem{ + procFS: procFS{FS: fs, mountPoint: mountPoint}, + } +} + +func (s linuxSystem) Host() (types.Host, error) { + return newHost(s.procFS) +} + +type host struct { + procFS procFS + stat procfs.Stat + info types.HostInfo +} + +func (h *host) Info() types.HostInfo { + return h.info +} + +func (h *host) Memory() (*types.HostMemoryInfo, error) { + content, err := ioutil.ReadFile(h.procFS.path("meminfo")) + if err != nil { + return nil, err + } + + return parseMemInfo(content) +} + +func (h *host) CPUTime() (types.CPUTimes, error) { + stat, err := h.procFS.NewStat() + if err != nil { + return types.CPUTimes{}, err + } + + return types.CPUTimes{ + User: time.Duration(stat.CPUTotal.User * float64(time.Second)), + System: time.Duration(stat.CPUTotal.System * float64(time.Second)), + Idle: time.Duration(stat.CPUTotal.Idle * float64(time.Second)), + IOWait: time.Duration(stat.CPUTotal.Iowait * float64(time.Second)), + IRQ: time.Duration(stat.CPUTotal.IRQ * float64(time.Second)), + Nice: time.Duration(stat.CPUTotal.Nice * float64(time.Second)), + SoftIRQ: time.Duration(stat.CPUTotal.SoftIRQ * float64(time.Second)), + Steal: time.Duration(stat.CPUTotal.Steal * float64(time.Second)), + }, nil +} + +func newHost(fs procFS) (*host, error) { + stat, err := fs.NewStat() + if err != nil { + return nil, errors.Wrap(err, "failed to read proc stat") + } + + h := &host{stat: stat, procFS: fs} + r := &reader{} + r.architecture(h) + r.bootTime(h) + r.containerized(h) + r.hostname(h) + r.network(h) + r.kernelVersion(h) + r.os(h) + r.time(h) + r.uniqueID(h) + return h, r.Err() +} + +type reader struct { + errs []error +} + +func (r *reader) addErr(err error) bool { + if err != nil { + if errors.Cause(err) != types.ErrNotImplemented { + r.errs = append(r.errs, err) + } + return true + } + return false +} + +func (r *reader) Err() error { + if len(r.errs) > 0 { + return &multierror.MultiError{Errors: r.errs} + } + return nil +} + +func (r *reader) architecture(h *host) { + v, err := Architecture() + if r.addErr(err) { + return + } + h.info.Architecture = v +} + +func (r *reader) bootTime(h *host) { + v, err := bootTime(h.procFS.FS) + if r.addErr(err) { + return + } + h.info.BootTime = v +} + +func (r *reader) containerized(h *host) { + v, err := IsContainerized() + if r.addErr(err) { + return + } + h.info.Containerized = &v +} + +func (r *reader) hostname(h *host) { + v, err := os.Hostname() + if r.addErr(err) { + return + } + h.info.Hostname = v +} + +func (r *reader) network(h *host) { + ips, macs, err := shared.Network() + if r.addErr(err) { + return + } + h.info.IPs = ips + h.info.MACs = macs +} + +func (r *reader) kernelVersion(h *host) { + v, err := KernelVersion() + if r.addErr(err) { + return + } + h.info.KernelVersion = v +} + +func (r *reader) os(h *host) { + v, err := OperatingSystem() + if r.addErr(err) { + return + } + h.info.OS = v +} + +func (r *reader) time(h *host) { + h.info.Timezone, h.info.TimezoneOffsetSec = time.Now().Zone() +} + +func (r *reader) uniqueID(h *host) { + v, err := MachineID() + if r.addErr(err) { + return + } + h.info.UniqueID = v +} + +type procFS struct { + procfs.FS + mountPoint string +} + +func (fs *procFS) path(p ...string) string { + elem := append([]string{fs.mountPoint}, p...) + return filepath.Join(elem...) +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/kernel_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/kernel_linux.go new file mode 100644 index 00000000..1b88e479 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/kernel_linux.go @@ -0,0 +1,41 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "syscall" + + "github.com/pkg/errors" +) + +func KernelVersion() (string, error) { + var uname syscall.Utsname + if err := syscall.Uname(&uname); err != nil { + return "", errors.Wrap(err, "kernel version") + } + + data := make([]byte, 0, len(uname.Release)) + for _, v := range uname.Release { + if v == 0 { + break + } + data = append(data, byte(v)) + } + + return string(data), nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go new file mode 100644 index 00000000..a84d085c --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/machineid.go @@ -0,0 +1,63 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "bytes" + "io/ioutil" + "os" + + "github.com/pkg/errors" + + "github.com/elastic/go-sysinfo/types" +) + +var ( + // Possible (current and historic) locations of the machine-id file. + // These will be searched in order. + machineIDFiles = []string{"/etc/machine-id", "/var/lib/dbus/machine-id", "/var/db/dbus/machine-id"} +) + +func MachineID() (string, error) { + var contents []byte + var err error + + for _, file := range machineIDFiles { + contents, err = ioutil.ReadFile(file) + if err != nil { + if os.IsNotExist(err) { + // Try next location + continue + } + + // Return with error on any other error + return "", errors.Wrapf(err, "failed to read %v", file) + } + + // Found it + break + } + + if os.IsNotExist(err) { + // None of the locations existed + return "", types.ErrNotImplemented + } + + contents = bytes.TrimSpace(contents) + return string(contents), nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/memory_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/memory_linux.go new file mode 100644 index 00000000..30357430 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/memory_linux.go @@ -0,0 +1,100 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "bytes" + "strconv" + + "github.com/pkg/errors" + + "github.com/elastic/go-sysinfo/types" +) + +func parseMemInfo(content []byte) (*types.HostMemoryInfo, error) { + memInfo := &types.HostMemoryInfo{ + Metrics: map[string]uint64{}, + } + + hasAvailable := false + err := parseKeyValue(content, ":", func(key, value []byte) error { + num, err := parseBytesOrNumber(value) + if err != nil { + return errors.Wrapf(err, "failed to parse %v value of %v", string(key), string(value)) + } + + k := string(key) + switch k { + case "MemTotal": + memInfo.Total = num + case "MemAvailable": + hasAvailable = true + memInfo.Available = num + case "MemFree": + memInfo.Free = num + case "SwapTotal": + memInfo.VirtualTotal = num + case "SwapFree": + memInfo.VirtualFree = num + default: + memInfo.Metrics[k] = num + } + + return nil + }) + if err != nil { + return nil, err + } + + memInfo.Used = memInfo.Total - memInfo.Free + memInfo.VirtualUsed = memInfo.VirtualTotal - memInfo.VirtualFree + + // MemAvailable was added in kernel 3.14. + if !hasAvailable { + // Linux uses this for the calculation (but we are using a simpler calculation). + // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 + memInfo.Available = memInfo.Free + memInfo.Metrics["Buffers"] + memInfo.Metrics["Cached"] + } + + return memInfo, nil +} + +func parseBytesOrNumber(data []byte) (uint64, error) { + parts := bytes.Fields(data) + + if len(parts) == 0 { + return 0, errors.New("empty value") + } + + num, err := strconv.ParseUint(string(parts[0]), 10, 64) + if err != nil { + return 0, errors.Wrap(err, "failed to parse value") + } + + var multiplier uint64 = 1 + if len(parts) >= 2 { + switch string(parts[1]) { + case "kB": + multiplier = 1024 + default: + return 0, errors.Errorf("unhandled unit %v", string(parts[1])) + } + } + + return num * multiplier, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/os.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/os.go new file mode 100644 index 00000000..d4daedd5 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/os.go @@ -0,0 +1,264 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "bufio" + "bytes" + "io/ioutil" + "os" + "path/filepath" + "regexp" + "strconv" + "strings" + + "github.com/pkg/errors" + + "github.com/elastic/go-sysinfo/types" +) + +const ( + osRelease = "/etc/os-release" + lsbRelease = "/etc/lsb-release" + distribRelease = "/etc/*-release" + versionGrok = `(?P(?P[0-9]+)\.?(?P[0-9]+)?\.?(?P\w+)?)(?: \((?P\w+)\))?` +) + +var ( + // distribReleaseRegexp parses the /etc/-release file. See man lsb-release. + distribReleaseRegexp = regexp.MustCompile(`(?P[\w]+).* ` + versionGrok) + + // versionRegexp parses version numbers (e.g. 6 or 6.1 or 6.1.0 or 6.1.0_20150102). + versionRegexp = regexp.MustCompile(versionGrok) +) + +// familyMap contains a mapping of family -> []platforms. +var familyMap = map[string][]string{ + "redhat": {"redhat", "fedora", "centos", "scientific", "oraclelinux", "amzn", "rhel"}, + "debian": {"debian", "ubuntu", "raspbian"}, + "suse": {"suse", "sles", "opensuse"}, +} + +var platformToFamilyMap map[string]string + +func init() { + platformToFamilyMap = map[string]string{} + for family, platformList := range familyMap { + for _, platform := range platformList { + platformToFamilyMap[platform] = family + } + } +} + +func OperatingSystem() (*types.OSInfo, error) { + return getOSInfo("") +} + +func getOSInfo(baseDir string) (*types.OSInfo, error) { + osInfo, err := getOSRelease(baseDir) + if err != nil { + // Fallback + return findDistribRelease(baseDir) + } + + // For the redhat family, enrich version info with data from + // /etc/[distrib]-release because the minor and patch info isn't always + // present in os-release. + if osInfo.Family != "redhat" { + return osInfo, nil + } + + distInfo, err := findDistribRelease(baseDir) + if err != nil { + return osInfo, err + } + osInfo.Major = distInfo.Major + osInfo.Minor = distInfo.Minor + osInfo.Patch = distInfo.Patch + osInfo.Codename = distInfo.Codename + return osInfo, nil +} + +func getOSRelease(baseDir string) (*types.OSInfo, error) { + lsbRel, _ := ioutil.ReadFile(filepath.Join(baseDir, lsbRelease)) + + osRel, err := ioutil.ReadFile(filepath.Join(baseDir, osRelease)) + if err != nil { + return nil, err + } + if len(osRel) == 0 { + return nil, errors.Errorf("%v is empty", osRelease) + } + + return parseOSRelease(append(lsbRel, osRel...)) +} + +func parseOSRelease(content []byte) (*types.OSInfo, error) { + fields := map[string]string{} + + s := bufio.NewScanner(bytes.NewReader(content)) + for s.Scan() { + line := bytes.TrimSpace(s.Bytes()) + + // Skip blank lines and comments. + if len(line) == 0 || bytes.HasPrefix(line, []byte("#")) { + continue + } + + parts := bytes.SplitN(s.Bytes(), []byte("="), 2) + if len(parts) != 2 { + continue + } + + key := string(bytes.TrimSpace(parts[0])) + val := string(bytes.TrimSpace(parts[1])) + fields[key] = val + + // Trim quotes. + val, err := strconv.Unquote(val) + if err == nil { + fields[key] = strings.TrimSpace(val) + } + } + + if s.Err() != nil { + return nil, s.Err() + } + + return makeOSInfo(fields) +} + +func makeOSInfo(osRelease map[string]string) (*types.OSInfo, error) { + os := &types.OSInfo{ + Platform: osRelease["ID"], + Name: osRelease["NAME"], + Version: osRelease["VERSION"], + Build: osRelease["BUILD_ID"], + Codename: osRelease["VERSION_CODENAME"], + } + + if os.Codename == "" { + // Some OSes uses their own CODENAME keys (e.g UBUNTU_CODENAME) or we + // can get the DISTRIB_CODENAME value from the lsb-release data. + for k, v := range osRelease { + if strings.Contains(k, "CODENAME") { + os.Codename = v + break + } + } + } + + if os.Platform == "" { + // Fallback to the first word of the NAME field. + parts := strings.SplitN(os.Name, " ", 2) + if len(parts) > 0 { + os.Platform = strings.ToLower(parts[0]) + } + } + + if os.Version != "" { + // Try parsing info from the version. + keys := versionRegexp.SubexpNames() + for i, m := range versionRegexp.FindStringSubmatch(os.Version) { + switch keys[i] { + case "major": + os.Major, _ = strconv.Atoi(m) + case "minor": + os.Minor, _ = strconv.Atoi(m) + case "patch": + os.Patch, _ = strconv.Atoi(m) + case "codename": + if os.Codename == "" { + os.Codename = m + } + } + } + } + + os.Family = platformToFamilyMap[strings.ToLower(os.Platform)] + return os, nil +} + +func findDistribRelease(baseDir string) (*types.OSInfo, error) { + matches, err := filepath.Glob(filepath.Join(baseDir, distribRelease)) + if err != nil { + return nil, err + } + for _, path := range matches { + if strings.HasSuffix(path, osRelease) || strings.HasSuffix(path, lsbRelease) { + continue + } + + info, err := os.Lstat(path) + if err != nil || !info.Mode().IsRegular() || info.Size() == 0 { + continue + } + + return getDistribRelease(path) + } + + return nil, errors.New("no /etc/-release file found") +} + +func getDistribRelease(file string) (*types.OSInfo, error) { + data, err := ioutil.ReadFile(file) + if err != nil { + return nil, err + } + parts := bytes.SplitN(data, []byte("\n"), 2) + if len(parts) != 2 { + return nil, errors.Errorf("failed to parse %v", file) + } + + // Use distrib as platform name. + var platform string + if parts := strings.SplitN(filepath.Base(file), "-", 2); len(parts) > 0 { + platform = strings.ToLower(parts[0]) + } + + return parseDistribRelease(platform, parts[0]) +} + +func parseDistribRelease(platform string, content []byte) (*types.OSInfo, error) { + var ( + line = string(bytes.TrimSpace(content)) + keys = distribReleaseRegexp.SubexpNames() + os = &types.OSInfo{Platform: platform} + ) + + for i, m := range distribReleaseRegexp.FindStringSubmatch(line) { + switch keys[i] { + case "name": + os.Name = m + case "version": + os.Version = m + case "major": + os.Major, _ = strconv.Atoi(m) + case "minor": + os.Minor, _ = strconv.Atoi(m) + case "patch": + os.Patch, _ = strconv.Atoi(m) + case "codename": + os.Version += " (" + m + ")" + os.Codename = m + } + } + + os.Family = platformToFamilyMap[strings.ToLower(os.Platform)] + return os, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/process_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/process_linux.go new file mode 100644 index 00000000..3ea7fd87 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/process_linux.go @@ -0,0 +1,259 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "bytes" + "io/ioutil" + "os" + "strconv" + "strings" + "time" + + "github.com/prometheus/procfs" + + "github.com/elastic/go-sysinfo/types" +) + +const userHz = 100 + +func (s linuxSystem) Processes() ([]types.Process, error) { + procs, err := s.procFS.AllProcs() + if err != nil { + return nil, err + } + + processes := make([]types.Process, 0, len(procs)) + for _, proc := range procs { + processes = append(processes, &process{Proc: proc, fs: s.procFS}) + } + return processes, nil +} + +func (s linuxSystem) Process(pid int) (types.Process, error) { + proc, err := s.procFS.NewProc(pid) + if err != nil { + return nil, err + } + + return &process{Proc: proc, fs: s.procFS}, nil +} + +func (s linuxSystem) Self() (types.Process, error) { + proc, err := s.procFS.Self() + if err != nil { + return nil, err + } + + return &process{Proc: proc, fs: s.procFS}, nil +} + +type process struct { + procfs.Proc + fs procFS + info *types.ProcessInfo +} + +func (p *process) PID() int { + return p.Proc.PID +} + +func (p *process) Parent() (types.Process, error) { + info, err := p.Info() + if err != nil { + return nil, err + } + + proc, err := p.fs.NewProc(info.PPID) + if err != nil { + return nil, err + } + + return &process{Proc: proc, fs: p.fs}, nil +} + +func (p *process) path(pa ...string) string { + return p.fs.path(append([]string{strconv.Itoa(p.PID())}, pa...)...) +} + +func (p *process) CWD() (string, error) { + // TODO: add CWD to procfs + cwd, err := os.Readlink(p.path("cwd")) + if os.IsNotExist(err) { + return "", nil + } + + return cwd, err +} + +func (p *process) Info() (types.ProcessInfo, error) { + if p.info != nil { + return *p.info, nil + } + + stat, err := p.NewStat() + if err != nil { + return types.ProcessInfo{}, err + } + + exe, err := p.Executable() + if err != nil { + return types.ProcessInfo{}, err + } + + args, err := p.CmdLine() + if err != nil { + return types.ProcessInfo{}, err + } + + cwd, err := p.CWD() + if err != nil { + return types.ProcessInfo{}, err + } + + bootTime, err := bootTime(p.fs.FS) + if err != nil { + return types.ProcessInfo{}, err + } + + p.info = &types.ProcessInfo{ + Name: stat.Comm, + PID: p.PID(), + PPID: stat.PPID, + CWD: cwd, + Exe: exe, + Args: args, + StartTime: bootTime.Add(ticksToDuration(stat.Starttime)), + } + + return *p.info, nil +} + +func (p *process) Memory() (types.MemoryInfo, error) { + stat, err := p.NewStat() + if err != nil { + return types.MemoryInfo{}, err + } + + return types.MemoryInfo{ + Resident: uint64(stat.ResidentMemory()), + Virtual: uint64(stat.VirtualMemory()), + }, nil +} + +func (p *process) CPUTime() (types.CPUTimes, error) { + stat, err := p.NewStat() + if err != nil { + return types.CPUTimes{}, err + } + + return types.CPUTimes{ + User: ticksToDuration(uint64(stat.UTime)), + System: ticksToDuration(uint64(stat.STime)), + }, nil +} + +// OpenHandles returns the list of open file descriptors of the process. +func (p *process) OpenHandles() ([]string, error) { + return p.Proc.FileDescriptorTargets() +} + +// OpenHandles returns the number of open file descriptors of the process. +func (p *process) OpenHandleCount() (int, error) { + return p.Proc.FileDescriptorsLen() +} + +func (p *process) Environment() (map[string]string, error) { + // TODO: add Environment to procfs + content, err := ioutil.ReadFile(p.path("environ")) + if err != nil { + return nil, err + } + + env := map[string]string{} + pairs := bytes.Split(content, []byte{0}) + for _, kv := range pairs { + parts := bytes.SplitN(kv, []byte{'='}, 2) + if len(parts) != 2 { + continue + } + + key := string(bytes.TrimSpace(parts[0])) + if key == "" { + continue + } + + env[key] = string(parts[1]) + } + + return env, nil +} + +func (p *process) Seccomp() (*types.SeccompInfo, error) { + content, err := ioutil.ReadFile(p.path("status")) + if err != nil { + return nil, err + } + + return readSeccompFields(content) +} + +func (p *process) Capabilities() (*types.CapabilityInfo, error) { + content, err := ioutil.ReadFile(p.path("status")) + if err != nil { + return nil, err + } + + return readCapabilities(content) +} + +func (p *process) User() (types.UserInfo, error) { + content, err := ioutil.ReadFile(p.path("status")) + if err != nil { + return types.UserInfo{}, err + } + + var user types.UserInfo + err = parseKeyValue(content, ":", func(key, value []byte) error { + // See proc(5) for the format of /proc/[pid]/status + switch string(key) { + case "Uid": + ids := strings.Split(string(value), "\t") + if len(ids) >= 3 { + user.UID = ids[0] + user.EUID = ids[1] + user.SUID = ids[2] + } + case "Gid": + ids := strings.Split(string(value), "\t") + if len(ids) >= 3 { + user.GID = ids[0] + user.EGID = ids[1] + user.SGID = ids[2] + } + } + return nil + }) + + return user, nil +} + +func ticksToDuration(ticks uint64) time.Duration { + seconds := float64(ticks) / float64(userHz) * float64(time.Second) + return time.Duration(int64(seconds)) +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/seccomp_linux.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/seccomp_linux.go new file mode 100644 index 00000000..d04bb3c7 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/seccomp_linux.go @@ -0,0 +1,69 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "strconv" + + "github.com/elastic/go-sysinfo/types" +) + +type SeccompMode uint8 + +const ( + SeccompModeDisabled SeccompMode = iota + SeccompModeStrict + SeccompModeFilter +) + +func (m SeccompMode) String() string { + switch m { + case SeccompModeDisabled: + return "disabled" + case SeccompModeStrict: + return "strict" + case SeccompModeFilter: + return "filter" + default: + return strconv.Itoa(int(m)) + } +} + +func readSeccompFields(content []byte) (*types.SeccompInfo, error) { + var seccomp types.SeccompInfo + + err := parseKeyValue(content, ":", func(key, value []byte) error { + switch string(key) { + case "Seccomp": + mode, err := strconv.ParseUint(string(value), 10, 8) + if err != nil { + return err + } + seccomp.Mode = SeccompMode(mode).String() + case "NoNewPrivs": + noNewPrivs, err := strconv.ParseBool(string(value)) + if err != nil { + return err + } + seccomp.NoNewPrivs = &noNewPrivs + } + return nil + }) + + return &seccomp, err +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/linux/util.go b/vendor/github.com/elastic/go-sysinfo/providers/linux/util.go new file mode 100644 index 00000000..066fef6a --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/linux/util.go @@ -0,0 +1,86 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 linux + +import ( + "bufio" + "bytes" + "io/ioutil" + "strconv" + + "github.com/pkg/errors" +) + +func parseKeyValue(content []byte, separator string, callback func(key, value []byte) error) error { + sc := bufio.NewScanner(bytes.NewReader(content)) + for sc.Scan() { + parts := bytes.SplitN(sc.Bytes(), []byte(separator), 2) + if len(parts) != 2 { + continue + } + + if err := callback(parts[0], bytes.TrimSpace(parts[1])); err != nil { + return err + } + } + + return sc.Err() +} + +func findValue(filename, separator, key string) (string, error) { + content, err := ioutil.ReadFile(filename) + if err != nil { + return "", err + } + + var line []byte + sc := bufio.NewScanner(bytes.NewReader(content)) + for sc.Scan() { + if bytes.HasPrefix(sc.Bytes(), []byte(key)) { + line = sc.Bytes() + break + } + } + if len(line) == 0 { + return "", errors.Errorf("%v not found", key) + } + + parts := bytes.SplitN(line, []byte(separator), 2) + if len(parts) != 2 { + return "", errors.Errorf("unexpected line format for '%v'", string(line)) + } + + return string(bytes.TrimSpace(parts[1])), nil +} + +func decodeBitMap(s string, lookupName func(int) string) ([]string, error) { + mask, err := strconv.ParseUint(s, 16, 64) + if err != nil { + return nil, err + } + + var names []string + for i := 0; i < 64; i++ { + bit := mask & (1 << uint(i)) + if bit > 0 { + names = append(names, lookupName(i)) + } + } + + return names, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/shared/network.go b/vendor/github.com/elastic/go-sysinfo/providers/shared/network.go new file mode 100644 index 00000000..cd11acd6 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/shared/network.go @@ -0,0 +1,48 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 shared + +import ( + "net" +) + +func Network() (ips, macs []string, err error) { + ifcs, err := net.Interfaces() + if err != nil { + return nil, nil, err + } + + ips = make([]string, 0, len(ifcs)) + macs = make([]string, 0, len(ifcs)) + for _, ifc := range ifcs { + addrs, err := ifc.Addrs() + if err != nil { + return nil, nil, err + } + for _, addr := range addrs { + ips = append(ips, addr.String()) + } + + mac := ifc.HardwareAddr.String() + if mac != "" { + macs = append(macs, mac) + } + } + + return ips, macs, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/arch_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/arch_windows.go new file mode 100644 index 00000000..0edfc4d7 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/arch_windows.go @@ -0,0 +1,31 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + windows "github.com/elastic/go-windows" +) + +func Architecture() (string, error) { + systemInfo, err := windows.GetNativeSystemInfo() + if err != nil { + return "", err + } + + return systemInfo.ProcessorArchitecture.String(), nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/boottime_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/boottime_windows.go new file mode 100644 index 00000000..fbac5879 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/boottime_windows.go @@ -0,0 +1,39 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + "time" + + windows "github.com/elastic/go-windows" + "github.com/pkg/errors" +) + +func BootTime() (time.Time, error) { + msSinceBoot, err := windows.GetTickCount64() + if err != nil { + return time.Time{}, errors.Wrap(err, "failed to get boot time") + } + + // According to GetTickCount64 the resolution is limited to between 10 to 16 + // milliseconds so truncate the time as to not mislead anyone about the + // resolution. + bootTime := time.Now().Add(-1 * time.Duration(msSinceBoot) * time.Millisecond) + bootTime = bootTime.Truncate(10 * time.Millisecond) + return bootTime, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/device_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/device_windows.go new file mode 100644 index 00000000..998295de --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/device_windows.go @@ -0,0 +1,192 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + "strings" + "unsafe" + + "github.com/pkg/errors" + "golang.org/x/sys/windows" +) + +const ( + // DeviceMup is the device used for unmounted network filesystems + DeviceMup = "\\device\\mup" + + // LANManRedirector is an string that appears in mounted network filesystems + LANManRedirector = "lanmanredirector" +) + +var ( + // ErrNoDevice is the error returned by DevicePathToDrivePath when + // an invalid device-path is supplied. + ErrNoDevice = errors.New("not a device path") + + // ErrDeviceNotFound is the error returned by DevicePathToDrivePath when + // a path pointing to an unmapped device is passed. + ErrDeviceNotFound = errors.New("logical device not found") +) + +type deviceProvider interface { + GetLogicalDrives() (uint32, error) + QueryDosDevice(*uint16, *uint16, uint32) (uint32, error) +} + +type deviceMapper struct { + deviceProvider +} + +type winapiDeviceProvider struct{} + +type testingDeviceProvider map[byte]string + +func newDeviceMapper() deviceMapper { + return deviceMapper{ + deviceProvider: winapiDeviceProvider{}, + } +} + +func fixNetworkDrivePath(device string) string { + // For a VirtualBox share: + // device=\device\vboxminirdr\;z:\vboxsvr\share + // path=\device\vboxminirdr\vboxsvr\share + // + // For a network share: + // device=\device\lanmanredirector\;q:nnnnnnn\server\share + // path=\device\mup\server\share + + semicolonPos := strings.IndexByte(device, ';') + colonPos := strings.IndexByte(device, ':') + if semicolonPos == -1 || colonPos != semicolonPos+2 { + return device + } + pathStart := strings.IndexByte(device[colonPos+1:], '\\') + if pathStart == -1 { + return device + } + dev := device[:semicolonPos] + path := device[colonPos+pathStart+1:] + n := len(dev) + if n > 0 && dev[n-1] == '\\' { + dev = dev[:n-1] + } + return dev + path +} + +func (mapper *deviceMapper) getDevice(driveLetter byte) (string, error) { + driveBuf := [3]uint16{uint16(driveLetter), ':', 0} + + for bufSize := 64; bufSize <= 1024; bufSize *= 2 { + deviceBuf := make([]uint16, bufSize) + n, err := mapper.QueryDosDevice(&driveBuf[0], &deviceBuf[0], uint32(len(deviceBuf))) + if err != nil { + if err == windows.ERROR_INSUFFICIENT_BUFFER { + continue + } + return "", err + } + return windows.UTF16ToString(deviceBuf[:n]), nil + } + return "", windows.ERROR_INSUFFICIENT_BUFFER +} + +func (mapper *deviceMapper) DevicePathToDrivePath(path string) (string, error) { + pathLower := strings.ToLower(path) + isMUP := strings.Index(pathLower, DeviceMup) == 0 + mask, err := mapper.GetLogicalDrives() + if err != nil { + return "", errors.Wrap(err, "GetLogicalDrives") + } + + for bit := uint32(0); mask != 0 && bit < uint32('Z'-'A'+1); bit++ { + if mask&(1< \\server\share\path + if isMUP { + return "\\" + path[len(DeviceMup):], nil + } + return "", ErrDeviceNotFound +} + +func (winapiDeviceProvider) GetLogicalDrives() (uint32, error) { + return windows.GetLogicalDrives() +} + +func (winapiDeviceProvider) QueryDosDevice(name *uint16, buf *uint16, length uint32) (uint32, error) { + return windows.QueryDosDevice(name, buf, length) +} + +func (m testingDeviceProvider) GetLogicalDrives() (mask uint32, err error) { + for drive := range m { + mask |= 1 << uint32(drive-'A') + } + return mask, nil +} + +func ptrOffset(ptr *uint16, off uint32) *uint16 { + return (*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(ptr)) + uintptr(off*2))) +} + +func (m testingDeviceProvider) QueryDosDevice(nameW *uint16, buf *uint16, length uint32) (uint32, error) { + drive := byte(*nameW) + if byte(*ptrOffset(nameW, 1)) != ':' { + return 0, errors.New("not a drive") + } + if *ptrOffset(nameW, 2) != 0 { + return 0, errors.New("drive not terminated") + } + path, ok := m[drive] + if !ok { + return 0, errors.Errorf("drive %c not found", drive) + } + n := uint32(len(path)) + if n+2 > length { + return 0, windows.ERROR_INSUFFICIENT_BUFFER + } + for i := uint32(0); i < n; i++ { + *ptrOffset(buf, i) = uint16(path[i]) + } + *ptrOffset(buf, n) = 0 + *ptrOffset(buf, n+1) = 0 + return n + 2, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/doc.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/doc.go new file mode 100644 index 00000000..fa351940 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/doc.go @@ -0,0 +1,20 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows implements the HostProvider and ProcessProvider interfaces +// for providing information about Windows. +package windows diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/host_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/host_windows.go new file mode 100644 index 00000000..0bc99e46 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/host_windows.go @@ -0,0 +1,175 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + "os" + "time" + + windows "github.com/elastic/go-windows" + "github.com/joeshaw/multierror" + "github.com/pkg/errors" + + "github.com/elastic/go-sysinfo/internal/registry" + "github.com/elastic/go-sysinfo/providers/shared" + "github.com/elastic/go-sysinfo/types" +) + +func init() { + registry.Register(windowsSystem{}) +} + +type windowsSystem struct{} + +func (s windowsSystem) Host() (types.Host, error) { + return newHost() +} + +type host struct { + info types.HostInfo +} + +func (h *host) Info() types.HostInfo { + return h.info +} + +func (h *host) CPUTime() (types.CPUTimes, error) { + idle, kernel, user, err := windows.GetSystemTimes() + if err != nil { + return types.CPUTimes{}, err + } + + return types.CPUTimes{ + System: kernel, + User: user, + Idle: idle, + }, nil +} + +func (h *host) Memory() (*types.HostMemoryInfo, error) { + mem, err := windows.GlobalMemoryStatusEx() + if err != nil { + return nil, err + } + + return &types.HostMemoryInfo{ + Total: mem.TotalPhys, + Used: mem.TotalPhys - mem.AvailPhys, + Free: mem.AvailPhys, + Available: mem.AvailPhys, + VirtualTotal: mem.TotalPageFile, + VirtualUsed: mem.TotalPageFile - mem.AvailPageFile, + VirtualFree: mem.AvailPageFile, + }, nil +} + +func newHost() (*host, error) { + h := &host{} + r := &reader{} + r.architecture(h) + r.bootTime(h) + r.hostname(h) + r.network(h) + r.kernelVersion(h) + r.os(h) + r.time(h) + r.uniqueID(h) + return h, r.Err() +} + +type reader struct { + errs []error +} + +func (r *reader) addErr(err error) bool { + if err != nil { + if errors.Cause(err) != types.ErrNotImplemented { + r.errs = append(r.errs, err) + } + return true + } + return false +} + +func (r *reader) Err() error { + if len(r.errs) > 0 { + return &multierror.MultiError{Errors: r.errs} + } + return nil +} + +func (r *reader) architecture(h *host) { + v, err := Architecture() + if r.addErr(err) { + return + } + h.info.Architecture = v +} + +func (r *reader) bootTime(h *host) { + v, err := BootTime() + if r.addErr(err) { + return + } + h.info.BootTime = v +} + +func (r *reader) hostname(h *host) { + v, err := os.Hostname() + if r.addErr(err) { + return + } + h.info.Hostname = v +} + +func (r *reader) network(h *host) { + ips, macs, err := shared.Network() + if r.addErr(err) { + return + } + h.info.IPs = ips + h.info.MACs = macs +} + +func (r *reader) kernelVersion(h *host) { + v, err := KernelVersion() + if r.addErr(err) { + return + } + h.info.KernelVersion = v +} + +func (r *reader) os(h *host) { + v, err := OperatingSystem() + if r.addErr(err) { + return + } + h.info.OS = v +} + +func (r *reader) time(h *host) { + h.info.Timezone, h.info.TimezoneOffsetSec = time.Now().Zone() +} + +func (r *reader) uniqueID(h *host) { + v, err := MachineID() + if r.addErr(err) { + return + } + h.info.UniqueID = v +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/kernel_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/kernel_windows.go new file mode 100644 index 00000000..c295c799 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/kernel_windows.go @@ -0,0 +1,43 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + windows "github.com/elastic/go-windows" +) + +const windowsKernelExe = `C:\Windows\System32\ntoskrnl.exe` + +func KernelVersion() (string, error) { + versionData, err := windows.GetFileVersionInfo(windowsKernelExe) + if err != nil { + return "", err + } + + fileVersion, err := versionData.QueryValue("FileVersion") + if err == nil { + return fileVersion, nil + } + + // Make a second attempt through the fixed version info. + info, err := versionData.FixedFileInfo() + if err != nil { + return "", err + } + return info.ProductVersion(), nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/machineid_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/machineid_windows.go new file mode 100644 index 00000000..ea814f4c --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/machineid_windows.go @@ -0,0 +1,46 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + "github.com/pkg/errors" + "golang.org/x/sys/windows/registry" +) + +func MachineID() (string, error) { + return getMachineGUID() +} + +func getMachineGUID() (string, error) { + const key = registry.LOCAL_MACHINE + const path = `SOFTWARE\Microsoft\Cryptography` + const name = "MachineGuid" + + k, err := registry.OpenKey(key, path, registry.READ|registry.WOW64_64KEY) + if err != nil { + return "", errors.Wrapf(err, `failed to open HKLM\%v`, path) + } + defer k.Close() + + guid, _, err := k.GetStringValue(name) + if err != nil { + return "", errors.Wrapf(err, `failed to get value of HKLM\%v\%v`, path, name) + } + + return guid, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/os_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/os_windows.go new file mode 100644 index 00000000..7a4d899f --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/os_windows.go @@ -0,0 +1,92 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + "fmt" + "strconv" + "strings" + + "github.com/pkg/errors" + "golang.org/x/sys/windows/registry" + + "github.com/elastic/go-sysinfo/types" +) + +func OperatingSystem() (*types.OSInfo, error) { + const key = registry.LOCAL_MACHINE + const path = `SOFTWARE\Microsoft\Windows NT\CurrentVersion` + const flags = registry.READ | registry.WOW64_64KEY + + k, err := registry.OpenKey(key, path, flags) + if err != nil { + return nil, errors.Wrapf(err, `failed to open HKLM\%v`, path) + } + defer k.Close() + + osInfo := &types.OSInfo{ + Family: "windows", + Platform: "windows", + } + name := "ProductName" + osInfo.Name, _, err = k.GetStringValue(name) + if err != nil { + return nil, errors.Wrapf(err, `failed to get value of HKLM\%v\%v`, path, name) + } + + // Newer versions (Win 10 and 2016) have CurrentMajor/CurrentMinor. + major, _, majorErr := k.GetIntegerValue("CurrentMajorVersionNumber") + minor, _, minorErr := k.GetIntegerValue("CurrentMinorVersionNumber") + if majorErr == nil && minorErr == nil { + osInfo.Major = int(major) + osInfo.Minor = int(minor) + osInfo.Version = fmt.Sprintf("%d.%d", major, minor) + } else { + name = "CurrentVersion" + osInfo.Version, _, err = k.GetStringValue(name) + if err != nil { + return nil, errors.Wrapf(err, `failed to get value of HKLM\%v\%v`, path, name) + } + parts := strings.SplitN(osInfo.Version, ".", 3) + for i, p := range parts { + switch i { + case 0: + osInfo.Major, _ = strconv.Atoi(p) + case 1: + osInfo.Major, _ = strconv.Atoi(p) + } + } + } + + name = "CurrentBuild" + osInfo.Build, _, err = k.GetStringValue(name) + if err != nil { + return nil, errors.Wrapf(err, `failed to get value of HKLM\%v\%v`, path, name) + } + + // Update Build Revision (optional) + name = "UBR" + updateBuildRevision, _, err := k.GetIntegerValue(name) + if err != nil && err != registry.ErrNotExist { + return nil, errors.Wrapf(err, `failed to get value of HKLM\%v\%v`, path, name) + } else { + osInfo.Build = fmt.Sprintf("%v.%d", osInfo.Build, updateBuildRevision) + } + + return osInfo, nil +} diff --git a/vendor/github.com/elastic/go-sysinfo/providers/windows/process_windows.go b/vendor/github.com/elastic/go-sysinfo/providers/windows/process_windows.go new file mode 100644 index 00000000..6ff7da53 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/providers/windows/process_windows.go @@ -0,0 +1,349 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 windows + +import ( + "os" + "path/filepath" + "strings" + "syscall" + "time" + "unsafe" + + "github.com/pkg/errors" + syswin "golang.org/x/sys/windows" + + windows "github.com/elastic/go-windows" + + "github.com/elastic/go-sysinfo/types" +) + +var ( + selfPID = os.Getpid() + devMapper = newDeviceMapper() +) + +func (s windowsSystem) Processes() (procs []types.Process, err error) { + pids, err := windows.EnumProcesses() + if err != nil { + return nil, errors.Wrap(err, "EnumProcesses") + } + procs = make([]types.Process, 0, len(pids)) + var proc types.Process + for _, pid := range pids { + if pid == 0 || pid == 4 { + // The Idle and System processes (PIDs 0 and 4) can never be + // opened by user-level code (see documentation for OpenProcess). + continue + } + + if proc, err = s.Process(int(pid)); err == nil { + procs = append(procs, proc) + } + } + if len(procs) == 0 { + return nil, err + } + return procs, nil +} + +func (s windowsSystem) Process(pid int) (types.Process, error) { + return newProcess(pid) +} + +func (s windowsSystem) Self() (types.Process, error) { + return newProcess(selfPID) +} + +type process struct { + pid int + info types.ProcessInfo +} + +func (p *process) PID() int { + return p.pid +} + +func (p *process) Parent() (types.Process, error) { + info, err := p.Info() + if err != nil { + return nil, err + } + + return newProcess(info.PPID) +} + +func newProcess(pid int) (*process, error) { + p := &process{pid: pid} + if err := p.init(); err != nil { + return nil, err + } + return p, nil +} + +func (p *process) init() error { + handle, err := p.open() + if err != nil { + return err + } + defer syscall.CloseHandle(handle) + + var path string + if imgf, err := windows.GetProcessImageFileName(handle); err == nil { + path, err = devMapper.DevicePathToDrivePath(imgf) + if err != nil { + path = imgf + } + } + + var creationTime, exitTime, kernelTime, userTime syscall.Filetime + if err := syscall.GetProcessTimes(handle, &creationTime, &exitTime, &kernelTime, &userTime); err != nil { + return err + } + + // Try to read the RTL_USER_PROCESS_PARAMETERS struct from the target process + // memory. This can fail due to missing access rights or when we are running + // as a 32bit process in a 64bit system (WOW64). + // Don't make this a fatal error: If it fails, `args` and `cwd` fields will + // be missing. + var args []string + var cwd string + var ppid int + pbi, err := getProcessBasicInformation(handle) + if err == nil { + ppid = int(pbi.InheritedFromUniqueProcessID) + userProcParams, err := getUserProcessParams(handle, pbi) + if err == nil { + if argsW, err := readProcessUnicodeString(handle, &userProcParams.CommandLine); err == nil { + args, err = splitCommandline(argsW) + if err != nil { + args = nil + } + } + if cwdW, err := readProcessUnicodeString(handle, &userProcParams.CurrentDirectoryPath); err == nil { + cwd, _, err = windows.UTF16BytesToString(cwdW) + if err != nil { + cwd = "" + } + // Remove trailing separator + cwd = strings.TrimRight(cwd, "\\") + } + } + } + + p.info = types.ProcessInfo{ + Name: filepath.Base(path), + PID: p.pid, + PPID: ppid, + Exe: path, + Args: args, + CWD: cwd, + StartTime: time.Unix(0, creationTime.Nanoseconds()), + } + return nil +} + +func getProcessBasicInformation(handle syscall.Handle) (pbi windows.ProcessBasicInformationStruct, err error) { + actualSize, err := windows.NtQueryInformationProcess(handle, windows.ProcessBasicInformation, unsafe.Pointer(&pbi), uint32(windows.SizeOfProcessBasicInformationStruct)) + if actualSize < uint32(windows.SizeOfProcessBasicInformationStruct) { + return pbi, errors.New("bad size for PROCESS_BASIC_INFORMATION") + } + return pbi, err +} + +func getUserProcessParams(handle syscall.Handle, pbi windows.ProcessBasicInformationStruct) (params windows.RtlUserProcessParameters, err error) { + const is32bitProc = unsafe.Sizeof(uintptr(0)) == 4 + + // Offset of params field within PEB structure. + // This structure is different in 32 and 64 bit. + paramsOffset := 0x20 + if is32bitProc { + paramsOffset = 0x10 + } + + // Read the PEB from the target process memory + pebSize := paramsOffset + 8 + peb := make([]byte, pebSize) + nRead, err := windows.ReadProcessMemory(handle, pbi.PebBaseAddress, peb) + if err != nil { + return params, err + } + if nRead != uintptr(pebSize) { + return params, errors.Errorf("PEB: short read (%d/%d)", nRead, pebSize) + } + + // Get the RTL_USER_PROCESS_PARAMETERS struct pointer from the PEB + paramsAddr := *(*uintptr)(unsafe.Pointer(&peb[paramsOffset])) + + // Read the RTL_USER_PROCESS_PARAMETERS from the target process memory + paramsBuf := make([]byte, windows.SizeOfRtlUserProcessParameters) + nRead, err = windows.ReadProcessMemory(handle, paramsAddr, paramsBuf) + if err != nil { + return params, err + } + if nRead != uintptr(windows.SizeOfRtlUserProcessParameters) { + return params, errors.Errorf("RTL_USER_PROCESS_PARAMETERS: short read (%d/%d)", nRead, windows.SizeOfRtlUserProcessParameters) + } + + params = *(*windows.RtlUserProcessParameters)(unsafe.Pointer(¶msBuf[0])) + return params, nil +} + +// read an UTF-16 string from another process memory. Result is an []byte +// with the UTF-16 data. +func readProcessUnicodeString(handle syscall.Handle, s *windows.UnicodeString) ([]byte, error) { + buf := make([]byte, s.Size) + nRead, err := windows.ReadProcessMemory(handle, s.Buffer, buf) + if err != nil { + return nil, err + } + if nRead != uintptr(s.Size) { + return nil, errors.Errorf("unicode string: short read: (%d/%d)", nRead, s.Size) + } + return buf, nil +} + +// Use Windows' CommandLineToArgv API to split an UTF-16 command line string +// into a list of parameters. +func splitCommandline(utf16 []byte) ([]string, error) { + if len(utf16) == 0 { + return nil, nil + } + var numArgs int32 + argsWide, err := syscall.CommandLineToArgv((*uint16)(unsafe.Pointer(&utf16[0])), &numArgs) + if err != nil { + return nil, err + } + args := make([]string, numArgs) + for idx := range args { + args[idx] = syscall.UTF16ToString(argsWide[idx][:]) + } + return args, nil +} + +func (p *process) open() (handle syscall.Handle, err error) { + if p.pid == selfPID { + return syscall.GetCurrentProcess() + } + + // Try different access rights, from broader to more limited. + // PROCESS_VM_READ is needed to get command-line and working directory + // PROCESS_QUERY_LIMITED_INFORMATION is only available in Vista+ + for _, permissions := range [4]uint32{ + syscall.PROCESS_QUERY_INFORMATION | windows.PROCESS_VM_READ, + windows.PROCESS_QUERY_LIMITED_INFORMATION | windows.PROCESS_VM_READ, + syscall.PROCESS_QUERY_INFORMATION, + windows.PROCESS_QUERY_LIMITED_INFORMATION, + } { + if handle, err = syscall.OpenProcess(permissions, false, uint32(p.pid)); err == nil { + break + } + } + return handle, err +} + +func (p *process) Info() (types.ProcessInfo, error) { + return p.info, nil +} + +func (p *process) User() (types.UserInfo, error) { + handle, err := p.open() + if err != nil { + return types.UserInfo{}, errors.Wrap(err, "OpenProcess failed") + } + defer syscall.CloseHandle(handle) + + var accessToken syswin.Token + err = syswin.OpenProcessToken(syswin.Handle(handle), syscall.TOKEN_QUERY, &accessToken) + if err != nil { + return types.UserInfo{}, errors.Wrap(err, "OpenProcessToken failed") + } + defer accessToken.Close() + + tokenUser, err := accessToken.GetTokenUser() + if err != nil { + return types.UserInfo{}, errors.Wrap(err, "GetTokenUser failed") + } + + sid, err := tokenUser.User.Sid.String() + if err != nil { + return types.UserInfo{}, errors.Wrap(err, "failed to look up user SID") + } + + tokenGroup, err := accessToken.GetTokenPrimaryGroup() + if err != nil { + return types.UserInfo{}, errors.Wrap(err, "GetTokenPrimaryGroup failed") + } + gsid, err := tokenGroup.PrimaryGroup.String() + if err != nil { + return types.UserInfo{}, errors.Wrap(err, "failed to look up primary group SID") + } + + return types.UserInfo{ + UID: sid, + GID: gsid, + }, nil +} + +func (p *process) Memory() (types.MemoryInfo, error) { + handle, err := p.open() + if err != nil { + return types.MemoryInfo{}, err + } + defer syscall.CloseHandle(handle) + + counters, err := windows.GetProcessMemoryInfo(handle) + if err != nil { + return types.MemoryInfo{}, err + } + + return types.MemoryInfo{ + Resident: uint64(counters.WorkingSetSize), + Virtual: uint64(counters.PrivateUsage), + }, nil +} + +func (p *process) CPUTime() (types.CPUTimes, error) { + handle, err := p.open() + if err != nil { + return types.CPUTimes{}, err + } + defer syscall.CloseHandle(handle) + + var creationTime, exitTime, kernelTime, userTime syscall.Filetime + if err := syscall.GetProcessTimes(handle, &creationTime, &exitTime, &kernelTime, &userTime); err != nil { + return types.CPUTimes{}, err + } + + return types.CPUTimes{ + User: windows.FiletimeToDuration(&userTime), + System: windows.FiletimeToDuration(&kernelTime), + }, nil +} + +// OpenHandles returns the number of open handles of the process. +func (p *process) OpenHandleCount() (int, error) { + handle, err := p.open() + if err != nil { + return 0, err + } + defer syscall.CloseHandle(handle) + + count, err := windows.GetProcessHandleCount(handle) + return int(count), err +} diff --git a/vendor/github.com/elastic/go-sysinfo/system.go b/vendor/github.com/elastic/go-sysinfo/system.go new file mode 100644 index 00000000..90f81691 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/system.go @@ -0,0 +1,85 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 sysinfo + +import ( + "runtime" + + "github.com/elastic/go-sysinfo/internal/registry" + "github.com/elastic/go-sysinfo/types" + + // Register host and process providers. + _ "github.com/elastic/go-sysinfo/providers/darwin" + _ "github.com/elastic/go-sysinfo/providers/linux" + _ "github.com/elastic/go-sysinfo/providers/windows" +) + +// Go returns information about the Go runtime. +func Go() types.GoInfo { + return types.GoInfo{ + OS: runtime.GOOS, + Arch: runtime.GOARCH, + MaxProcs: runtime.GOMAXPROCS(0), + Version: runtime.Version(), + } +} + +// Host returns information about host on which this process is running. If +// host information collection is not implemented for this platform then +// types.ErrNotImplemented is returned. +func Host() (types.Host, error) { + provider := registry.GetHostProvider() + if provider == nil { + return nil, types.ErrNotImplemented + } + return provider.Host() +} + +// Process returns a types.Process object representing the process associated +// with the given PID. The types.Process object can be used to query information +// about the process. If process information collection is not implemented for +// this platform then types.ErrNotImplemented is returned. +func Process(pid int) (types.Process, error) { + provider := registry.GetProcessProvider() + if provider == nil { + return nil, types.ErrNotImplemented + } + return provider.Process(pid) +} + +// Processes return a list of all processes. If process information collection +// is not implemented for this platform then types.ErrNotImplemented is +// returned. +func Processes() ([]types.Process, error) { + provider := registry.GetProcessProvider() + if provider == nil { + return nil, types.ErrNotImplemented + } + return provider.Processes() +} + +// Self return a types.Process object representing this process. If process +// information collection is not implemented for this platform then +// types.ErrNotImplemented is returned. +func Self() (types.Process, error) { + provider := registry.GetProcessProvider() + if provider == nil { + return nil, types.ErrNotImplemented + } + return provider.Self() +} diff --git a/vendor/github.com/elastic/go-sysinfo/types/errors.go b/vendor/github.com/elastic/go-sysinfo/types/errors.go new file mode 100644 index 00000000..b4af4052 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/types/errors.go @@ -0,0 +1,22 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 types + +import "github.com/pkg/errors" + +var ErrNotImplemented = errors.New("unimplemented") diff --git a/vendor/github.com/elastic/go-sysinfo/types/go.go b/vendor/github.com/elastic/go-sysinfo/types/go.go new file mode 100644 index 00000000..c195c9ff --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/types/go.go @@ -0,0 +1,25 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 types + +type GoInfo struct { + OS string `json:"os"` + Arch string `json:"arch"` + MaxProcs int `json:"max_procs"` + Version string `json:"version"` +} diff --git a/vendor/github.com/elastic/go-sysinfo/types/host.go b/vendor/github.com/elastic/go-sysinfo/types/host.go new file mode 100644 index 00000000..32554dd9 --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/types/host.go @@ -0,0 +1,78 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 types + +import "time" + +type Host interface { + CPUTimer + Info() HostInfo + Memory() (*HostMemoryInfo, error) +} + +type HostInfo struct { + Architecture string `json:"architecture"` // Hardware architecture (e.g. x86_64, arm, ppc, mips). + BootTime time.Time `json:"boot_time"` // Host boot time. + Containerized *bool `json:"containerized,omitempty"` // Is the process containerized. + Hostname string `json:"name"` // Hostname + IPs []string `json:"ip,omitempty"` // List of all IPs. + KernelVersion string `json:"kernel_version"` // Kernel version. + MACs []string `json:"mac"` // List of MAC addresses. + OS *OSInfo `json:"os"` // OS information. + Timezone string `json:"timezone"` // System timezone. + TimezoneOffsetSec int `json:"timezone_offset_sec"` // Timezone offset (seconds from UTC). + UniqueID string `json:"id,omitempty"` // Unique ID of the host (optional). +} + +func (host HostInfo) Uptime() time.Duration { + return time.Since(host.BootTime) +} + +type OSInfo struct { + Family string `json:"family"` // OS Family (e.g. redhat, debian, freebsd, windows). + Platform string `json:"platform"` // OS platform (e.g. centos, ubuntu, windows). + Name string `json:"name"` // OS Name (e.g. Mac OS X, CentOS). + Version string `json:"version"` // OS version (e.g. 10.12.6). + Major int `json:"major"` // Major release version. + Minor int `json:"minor"` // Minor release version. + Patch int `json:"patch"` // Patch release version. + Build string `json:"build,omitempty"` // Build (e.g. 16G1114). + Codename string `json:"codename,omitempty"` // OS codename (e.g. jessie). +} + +type LoadAverage interface { + LoadAverage() LoadAverageInfo +} + +type LoadAverageInfo struct { + One float64 `json:"one_min"` + Five float64 `json:"five_min"` + Fifteen float64 `json:"fifteen_min"` +} + +// HostMemoryInfo (all values are specified in bytes). +type HostMemoryInfo struct { + Total uint64 `json:"total_bytes"` // Total physical memory. + Used uint64 `json:"used_bytes"` // Total - Free + Available uint64 `json:"available_bytes"` // Amount of memory available without swapping. + Free uint64 `json:"free_bytes"` // Amount of memory not used by the system. + VirtualTotal uint64 `json:"virtual_total_bytes"` // Total virtual memory. + VirtualUsed uint64 `json:"virtual_used_bytes"` // VirtualTotal - VirtualFree + VirtualFree uint64 `json:"virtual_free_bytes"` // Virtual memory that is not used. + Metrics map[string]uint64 `json:"raw,omitempty"` // Other memory related metrics. +} diff --git a/vendor/github.com/elastic/go-sysinfo/types/process.go b/vendor/github.com/elastic/go-sysinfo/types/process.go new file mode 100644 index 00000000..8dd2074c --- /dev/null +++ b/vendor/github.com/elastic/go-sysinfo/types/process.go @@ -0,0 +1,138 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you 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 types + +import "time" + +type Process interface { + CPUTimer + Info() (ProcessInfo, error) + Memory() (MemoryInfo, error) + User() (UserInfo, error) + Parent() (Process, error) + PID() int +} + +type ProcessInfo struct { + Name string `json:"name"` + PID int `json:"pid"` + PPID int `json:"ppid"` + CWD string `json:"cwd"` + Exe string `json:"exe"` + Args []string `json:"args"` + StartTime time.Time `json:"start_time"` +} + +// UserInfo contains information about the UID and GID +// values of a process. +type UserInfo struct { + // UID is the user ID. + // On Linux and Darwin (macOS) this is the real user ID. + // On Windows, this is the security identifier (SID) of the + // user account of the process access token. + UID string `json:"uid"` + + // On Linux and Darwin (macOS) this is the effective user ID. + // On Windows, this is empty. + EUID string `json:"euid"` + + // On Linux and Darwin (macOS) this is the saved user ID. + // On Windows, this is empty. + SUID string `json:"suid"` + + // GID is the primary group ID. + // On Linux and Darwin (macOS) this is the real group ID. + // On Windows, this is the security identifier (SID) of the + // primary group of the process access token. + GID string `json:"gid"` + + // On Linux and Darwin (macOS) this is the effective group ID. + // On Windows, this is empty. + EGID string `json:"egid"` + + // On Linux and Darwin (macOS) this is the saved group ID. + // On Windows, this is empty. + SGID string `json:"sgid"` +} + +type Environment interface { + Environment() (map[string]string, error) +} + +// OpenHandleEnumerator lists the open file handles. +type OpenHandleEnumerator interface { + OpenHandles() ([]string, error) +} + +// OpenHandleCount returns the number the open file handles. +type OpenHandleCounter interface { + OpenHandleCount() (int, error) +} + +type CPUTimer interface { + // CPUTime returns a CPUTimes structure for + // the host or some process. + // + // The User and System fields are guaranteed + // to be populated for all platforms, and + // for both hosts and processes. + CPUTime() (CPUTimes, error) +} + +type CPUTimes struct { + User time.Duration `json:"user"` + System time.Duration `json:"system"` + Idle time.Duration `json:"idle,omitempty"` + IOWait time.Duration `json:"iowait,omitempty"` + IRQ time.Duration `json:"irq,omitempty"` + Nice time.Duration `json:"nice,omitempty"` + SoftIRQ time.Duration `json:"soft_irq,omitempty"` + Steal time.Duration `json:"steal,omitempty"` +} + +func (cpu CPUTimes) Total() time.Duration { + return cpu.User + cpu.System + cpu.Idle + cpu.IOWait + cpu.IRQ + cpu.Nice + + cpu.SoftIRQ + cpu.Steal +} + +type MemoryInfo struct { + Resident uint64 `json:"resident_bytes"` + Virtual uint64 `json:"virtual_bytes"` + Metrics map[string]uint64 `json:"raw,omitempty"` // Other memory related metrics. +} + +type SeccompInfo struct { + Mode string `json:"mode"` + NoNewPrivs *bool `json:"no_new_privs,omitempty"` // Added in kernel 4.10. +} + +type CapabilityInfo struct { + Inheritable []string `json:"inheritable"` + Permitted []string `json:"permitted"` + Effective []string `json:"effective"` + Bounding []string `json:"bounding"` + Ambient []string `json:"ambient"` +} + +type Capabilities interface { + Capabilities() (*CapabilityInfo, error) +} + +type Seccomp interface { + Seccomp() (*SeccompInfo, error) +} diff --git a/vendor/github.com/elastic/go-windows/.appveyor.yml b/vendor/github.com/elastic/go-windows/.appveyor.yml new file mode 100644 index 00000000..ab06a51e --- /dev/null +++ b/vendor/github.com/elastic/go-windows/.appveyor.yml @@ -0,0 +1,61 @@ +# Version format +version: "{build}" + +image: Visual Studio 2015 + +# Environment variables +environment: + GOPATH: c:\gopath + GO111MODULE: on + GVM_GO_VERSION: 1.12.4 + GVM_DL: https://github.com/andrewkroh/gvm/releases/download/v0.2.0/gvm-windows-amd64.exe + +# Custom clone folder (variables are not expanded here). +clone_folder: c:\gopath\src\github.com\elastic\go-windows + +# Cache mingw install until appveyor.yml is modified. +cache: +- C:\ProgramData\chocolatey\bin -> .appveyor.yml +- C:\ProgramData\chocolatey\lib -> .appveyor.yml +- C:\Users\appveyor\.gvm -> .appveyor.yml +- C:\Windows\System32\gvm.exe -> .appveyor.yml + +# Scripts that run after cloning repository +install: + - ps: >- + if(!(Test-Path "C:\Windows\System32\gvm.exe")) { + wget "$env:GVM_DL" -Outfile C:\Windows\System32\gvm.exe + } + - ps: gvm --format=powershell "$env:GVM_GO_VERSION" | Invoke-Expression + # AppVeyor has MinGW64. Make sure it's on the PATH. + - set PATH=C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1;%GOROOT%\bin;%PATH% + - set PATH=%GOPATH%\bin;%PATH% + - go version + - go env + - cmd /C "set ""GO111MODULE=off"" && go get github.com/elastic/go-licenser" + - python --version + +before_build: +- go mod verify +- go-licenser -d +- go run .ci/scripts/check_format.go +- go run .ci/scripts/check_lint.go + +build_script: + # Compile + - appveyor AddCompilationMessage "Starting Compile" + - cd c:\gopath\src\github.com\elastic\go-windows + - go build + - appveyor AddCompilationMessage "Compile Success" + +test_script: + # Unit tests + - ps: Add-AppveyorTest "Unit Tests" -Outcome Running + - go test -v ./... + - ps: Update-AppveyorTest "Unit Tests" -Outcome Passed + +# To disable deployment +deploy: off + +# Notifications should only be setup using the AppVeyor UI so that +# forks can be created without inheriting the settings. diff --git a/vendor/github.com/elastic/go-windows/.gitattributes b/vendor/github.com/elastic/go-windows/.gitattributes new file mode 100644 index 00000000..875f4996 --- /dev/null +++ b/vendor/github.com/elastic/go-windows/.gitattributes @@ -0,0 +1,5 @@ +# Treat all files in the Go repo as binary, with no git magic updating +# line endings. Windows users contributing to Go will need to use a +# modern version of git and editors capable of LF line endings. + +* -text diff --git a/vendor/github.com/elastic/go-windows/.gitignore b/vendor/github.com/elastic/go-windows/.gitignore new file mode 100644 index 00000000..3b38be37 --- /dev/null +++ b/vendor/github.com/elastic/go-windows/.gitignore @@ -0,0 +1,24 @@ +# Directories +/.vagrant +/.idea +/build + +# Files +.DS_Store +/*.iml +*.h + +# Editor swap files +*.swp +*.swo +*.swn + +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so +*.exe +*.test +*.prof +*.pyc +*.swp diff --git a/vendor/github.com/elastic/go-windows/.travis.yml b/vendor/github.com/elastic/go-windows/.travis.yml new file mode 100644 index 00000000..2a96a1a6 --- /dev/null +++ b/vendor/github.com/elastic/go-windows/.travis.yml @@ -0,0 +1,25 @@ +sudo: false + +language: go + +os: +- windows +- linux + +go: +- 1.12.x + +env: +- GO111MODULE=on + +go_import_path: github.com/elastic/go-windows + +before_install: +- GO111MODULE=off go get -u github.com/elastic/go-licenser + +script: +- go mod verify +- go-licenser -d +- go run .ci/scripts/check_format.go +- go run .ci/scripts/check_lint.go +- go test -v ./... diff --git a/vendor/github.com/elastic/go-windows/CHANGELOG.md b/vendor/github.com/elastic/go-windows/CHANGELOG.md new file mode 100644 index 00000000..f87a51dd --- /dev/null +++ b/vendor/github.com/elastic/go-windows/CHANGELOG.md @@ -0,0 +1,34 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +### Changed + +### Deprecated + +### Removed + +### Fixed + +### Security + +## [1.0.0] - 2019-04-26 + +### Added + +- Add GetProcessMemoryInfo. #2 +- Add APIs to fetch process information #6. + - NtQueryInformationProcess + - ReadProcessMemory + - GetProcessImageFileName + - EnumProcesses +- Add GetProcessHandleCount to kernel32. #7 + +[Unreleased]: https://github.com/elastic/go-windows/compare/v1.0.0...HEAD +[1.0.0]: https://github.com/elastic/go-windows/v1.0.0 diff --git a/vendor/github.com/elastic/go-windows/LICENSE.txt b/vendor/github.com/elastic/go-windows/LICENSE.txt new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/vendor/github.com/elastic/go-windows/LICENSE.txt @@ -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. diff --git a/vendor/github.com/elastic/go-windows/NOTICE.txt b/vendor/github.com/elastic/go-windows/NOTICE.txt new file mode 100644 index 00000000..807d3ab9 --- /dev/null +++ b/vendor/github.com/elastic/go-windows/NOTICE.txt @@ -0,0 +1,5 @@ +Elastic go-windows +Copyright 2017-2019 Elasticsearch B.V. + +This product includes software developed at +Elasticsearch, B.V. (https://www.elastic.co/). diff --git a/vendor/github.com/elastic/go-windows/README.md b/vendor/github.com/elastic/go-windows/README.md new file mode 100644 index 00000000..1140052d --- /dev/null +++ b/vendor/github.com/elastic/go-windows/README.md @@ -0,0 +1,18 @@ +# go-windows + +[![Build Status](http://img.shields.io/travis/elastic/go-windows.svg?style=flat-square)][travis] +[![Build status](https://ci.appveyor.com/api/projects/status/remqhuw0jjguygc3/branch/master?svg=true)][appveyor] +[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] + +[travis]: http://travis-ci.org/elastic/go-windows +[appveyor]: https://ci.appveyor.com/project/elastic-beats/go-windows/branch/master +[godocs]: http://godoc.org/github.com/elastic/go-windows + +go-windows is a library for Go (golang) that provides wrappers to various +Windows APIs that are not covered by the stdlib or by +[golang.org/x/sys/windows](https://godoc.org/golang.org/x/sys/windows). + +Goals / Features + +- Does not use cgo. +- Provide abstractions to make using the APIs easier. diff --git a/vendor/github.com/elastic/go-windows/Vagrantfile b/vendor/github.com/elastic/go-windows/Vagrantfile new file mode 100644 index 00000000..5f529549 --- /dev/null +++ b/vendor/github.com/elastic/go-windows/Vagrantfile @@ -0,0 +1,30 @@ +# NOTE: This is not a public image. It's only available within the Elastic +# organization and requires a 'vagrant login'. + +GO_VERSION = "1.12.4" + +# Provisioning for Windows PowerShell. +$winPsProvision = <