diff --git a/.github/workflows/bins.yaml b/.github/workflows/bins.yaml index a1ef50b9e..bebf9378f 100644 --- a/.github/workflows/bins.yaml +++ b/.github/workflows/bins.yaml @@ -36,12 +36,6 @@ jobs: package: virtwhat secrets: token: ${{ secrets.HUB_JWT }} - logtrunc: - uses: ./.github/workflows/bin-package.yaml - with: - package: logtrunc - secrets: - token: ${{ secrets.HUB_JWT }} yggdrasil: uses: ./.github/workflows/bin-package.yaml with: @@ -96,10 +90,16 @@ jobs: package: virtiofsd secrets: token: ${{ secrets.HUB_JWT }} - node-exporter: + # node-exporter: + # uses: ./.github/workflows/bin-package.yaml + # with: + # package: node-exporter + # secrets: + # token: ${{ secrets.HUB_JWT }} + vector: uses: ./.github/workflows/bin-package.yaml with: - package: node-exporter + package: vector secrets: token: ${{ secrets.HUB_JWT }} tpm: diff --git a/bins/packages/logtrunc/logtrunc.sh b/bins/packages/logtrunc/logtrunc.sh deleted file mode 100644 index d04dad55b..000000000 --- a/bins/packages/logtrunc/logtrunc.sh +++ /dev/null @@ -1,56 +0,0 @@ -LOGTRUNC_VERSION="0.1" -LOGTRUNC_CHECKSUM="0fbc114c8becf012cf9bb6c734dbc3d9" -LOGTRUNC_LINK="https://github.com/maxux/logtrunc/archive/v${LOGTRUNC_VERSION}.tar.gz" - -dependencies_logtrunc() { - apt-get install -y build-essential -} - -download_logtrunc() { - download_file ${LOGTRUNC_LINK} ${LOGTRUNC_CHECKSUM} logtrunc-${LOGTRUNC_VERSION}.tar.gz -} - -extract_logtrunc() { - tar -xf ${DISTDIR}/logtrunc-${LOGTRUNC_VERSION}.tar.gz -C ${WORKDIR} -} - -prepare_logtrunc() { - echo "[+] prepare logtrunc" - github_name "logtrunc-${LOGTRUNC_VERSION}" -} - -compile_logtrunc() { - echo "[+] compile promtail" - pwd - make release -} - -install_logtrunc() { - echo "[+] install logtrunc" - - mkdir -p "${ROOTDIR}/usr/bin" - mkdir -p "${ROOTDIR}/etc/zinit" - - cp logtrunc ${ROOTDIR}/usr/bin/logtrunc - cp logtrunc.yaml ${ROOTDIR}/etc/zinit/ - - chmod +x ${ROOTDIR}/usr/bin/* -} - -build_logtrunc() { - pushd "${DISTDIR}" - - dependencies_logtrunc - download_logtrunc - extract_logtrunc - - popd - pushd ${WORKDIR}/logtrunc-${LOGTRUNC_VERSION} - - prepare_logtrunc - compile_logtrunc - install_logtrunc - - popd -} - diff --git a/bins/packages/node-exporter/root/etc/zinit/node-exporter.yaml b/bins/packages/node-exporter/root/etc/zinit/node-exporter.yaml index c52c72c4e..ca161c115 100644 --- a/bins/packages/node-exporter/root/etc/zinit/node-exporter.yaml +++ b/bins/packages/node-exporter/root/etc/zinit/node-exporter.yaml @@ -1 +1 @@ -exec: sh -c "if grep -E '(runmode=test|runmode=dev|runmode=qa)' /proc/cmdline ; then node_exporter '--collector.netdev.device-exclude=(b|br)-.*' ; else sleep infinity ; fi" +exec: node_exporter '--collector.netdev.device-exclude=(b|br)-.*' diff --git a/bins/packages/vector/files/vector.yaml b/bins/packages/vector/files/vector.yaml new file mode 100644 index 000000000..0727fa2d5 --- /dev/null +++ b/bins/packages/vector/files/vector.yaml @@ -0,0 +1,96 @@ +--- +sources: + zinit: + type: exec + mode: streaming + command: + - zinit + - log + metrics: + type: host_metrics + network: + devices: + excludes: + - b-* + - br-* + - dumdum + - dummy* + - tozos* + filesystem: + mountpoints: + excludes: + - /var/cache + - /var/cache/* + - /var/run/* + - /dev + - /dev/* + - /sys + - /sys/* + - /proc + - /proc/* +transforms: + parsed: + type: remap + inputs: + - zinit + source: |- + structured, err = parse_regex(.message, r'\[(?P\+|\-)\] (?P[^:]+):') + if err == null { + . = merge(., structured) + } + + level, err = parse_regex(.message, r'(?Pdebug|info|error|warn|fatal|panic)') + if err != null { + .level = "info" + } else { + . = merge(., level) + } + + if .output == "+" { + .stream = "stdout" + } else { + .stream = "stderr" + } + + .node = get_env_var("NODE") ?? "unknown" + .network = get_env_var("NETWORK") ?? "unknown" + .farm = get_env_var("FARM") ?? "unknown" + + del(.output) + del(.command) + del(.host) + del(.source_type) + del(.pid) + +sinks: + # out: + # inputs: + # - parsed + # type: console + # encoding: + # codec: "text" + # TODO: enable once we have vector installed + # vector: + # inputs: + # - metrics + # type: console + # encoding: + # codec: "json" + + loki: + inputs: + - parsed + type: loki + labels: + node: "{{ node }}" + level: "{{ level }}" + module: "{{ module }}" + network: "{{ network }}" + stream: "{{ stream }}" + farm: "{{ farm }}" + endpoint: http://loki.grid.tf:3100 + encoding: + codec: text + compression: snappy + healthcheck: + enabled: false diff --git a/bins/packages/vector/files/zinit-vector.yaml b/bins/packages/vector/files/zinit-vector.yaml new file mode 100644 index 000000000..bdaa5c51f --- /dev/null +++ b/bins/packages/vector/files/zinit-vector.yaml @@ -0,0 +1,14 @@ +# pkill -HUP is for older version of zinit that doesn't start process +# in its own process group +exec: | + sh -c ' + pkill vector + + export NODE=$(identityd -address) + export FARM=$(identityd -farm) + export NETWORK=$(identityd -net) + exec vector -c /etc/vector/vector.yaml + ' +log: stdout +after: + - identityd diff --git a/bins/packages/vector/vector.sh b/bins/packages/vector/vector.sh new file mode 100644 index 000000000..b4387b089 --- /dev/null +++ b/bins/packages/vector/vector.sh @@ -0,0 +1,52 @@ +VECTOR_VERSION="0.25.1" +VECTOR_CHECKSUM="07bcae774d8f6dc5f34a5f4f7bafd313" +VECTOR_LINK="https://github.com/vectordotdev/vector/releases/download/v${VECTOR_VERSION}/vector-${VECTOR_VERSION}-x86_64-unknown-linux-musl.tar.gz" +VECTOR_PACKAGE="vector.tar.gz" + +download_vector() { + download_file ${VECTOR_LINK} ${VECTOR_CHECKSUM} ${VECTOR_PACKAGE} +} + +extract_vector() { + tar -xf ${DISTDIR}/${VECTOR_PACKAGE} -C ${WORKDIR} +} + +prepare_vector() { + echo "[+] prepare vector" + github_name "vector-${VECTOR_VERSION}" +} + +compile_vector() { + echo "[+] compile vector" +} + +install_vector() { + echo "[+] install vector" + + mkdir -p "${ROOTDIR}/usr/bin" + mkdir -p "${ROOTDIR}/etc/zinit" + mkdir -p "${ROOTDIR}/etc/vector" + + cp ${WORKDIR}/vector-x86_64-unknown-linux-musl/bin/vector ${ROOTDIR}/usr/bin/vector + + cp ${FILESDIR}/zinit-vector.yaml ${ROOTDIR}/etc/zinit/vector.yaml + cp ${FILESDIR}/vector.yaml ${ROOTDIR}/etc/vector/ + + chmod +x ${ROOTDIR}/usr/bin/* +} + +build_vector() { + pushd "${DISTDIR}" + + download_vector + extract_vector + + popd + pushd ${WORKDIR} + + prepare_vector + compile_vector + install_vector + + popd +} diff --git a/cmds/identityd/main.go b/cmds/identityd/main.go index 9f6a916ba..6bbfe40f1 100644 --- a/cmds/identityd/main.go +++ b/cmds/identityd/main.go @@ -64,30 +64,53 @@ func main() { interval int ver bool debug bool - id bool + + id bool + net bool + farm bool + address bool ) flag.StringVar(&root, "root", "/var/cache/modules/identityd", "root working directory of the module") flag.StringVar(&broker, "broker", redisSocket, "connection string to broker") flag.IntVar(&interval, "interval", 600, "interval in seconds between update checks, default to 600") flag.BoolVar(&ver, "v", false, "show version and exit") - flag.BoolVar(&debug, "d", false, "when set, no self update is done before upgradeing") - flag.BoolVar(&id, "id", false, "prints the node ID and exits") + flag.BoolVar(&debug, "d", false, "when set, no self update is done before upgrading") + flag.BoolVar(&id, "id", false, "[deprecated] prints the node ID and exits") + flag.BoolVar(&net, "net", false, "prints the node network and exits") + flag.BoolVar(&farm, "farm", false, "prints the node farm id and exits") + flag.BoolVar(&address, "address", false, "prints the node ss58 address and exits") flag.Parse() if ver { version.ShowAndExit(false) } - if id { + if farm { + env := environment.MustGet() + fmt.Println(env.FarmerID) + os.Exit(0) + } else if net { + env := environment.MustGet() + fmt.Println(env.RunningMode.String()) + os.Exit(0) + } else if id || address { ctx := context.Background() client, err := zbus.NewRedisClient(broker) if err != nil { log.Fatal().Err(err).Msg("failed to connect to zbus") } stub := stubs.NewIdentityManagerStub(client) - nodeID := stub.NodeID(ctx) - fmt.Println(nodeID) + + if id { + fmt.Println(stub.NodeID(ctx)) + } else { // address + add, err := stub.Address(ctx) + if err != nil { + log.Fatal().Err(err).Msg("failed to get node address") + } + fmt.Println(add) + } os.Exit(0) } diff --git a/etc/zinit/logger.yaml b/etc/zinit/logger.yaml deleted file mode 100644 index ed3d7f716..000000000 --- a/etc/zinit/logger.yaml +++ /dev/null @@ -1,3 +0,0 @@ -exec: sh -c 'mkdir -p /var/cache/log/ && zinit log >> /var/cache/log/system.log' -after: - - boot diff --git a/pkg/identity.go b/pkg/identity.go index a128614d7..1d551a1b5 100644 --- a/pkg/identity.go +++ b/pkg/identity.go @@ -18,6 +18,12 @@ func (s StrIdentifier) Identity() string { return string(s) } +type Address string + +func (s Address) String() string { + return string(s) +} + // IdentityManager interface. type IdentityManager interface { // Store returns the key store kind @@ -26,8 +32,8 @@ type IdentityManager interface { // NodeID returns the node id (public key) NodeID() StrIdentifier - // NodeIDNumeric returns the node registered ID. - NodeIDNumeric() (uint32, error) + // Address return the node address (SS58Address address) + Address() (Address, error) // FarmID return the farm id this node is part of. this is usually a configuration // that the node is booted with. An error is returned if the farmer id is not configured diff --git a/pkg/identity/identityd.go b/pkg/identity/identityd.go index 7ef13d4bd..a341fe546 100644 --- a/pkg/identity/identityd.go +++ b/pkg/identity/identityd.go @@ -20,7 +20,6 @@ type identityManager struct { env environment.Environment farm string - node uint32 } // NewManager creates an identity daemon from seed @@ -83,31 +82,13 @@ func (d *identityManager) NodeID() pkg.StrIdentifier { return pkg.StrIdentifier(d.key.Identity()) } -func (d *identityManager) NodeIDNumeric() (uint32, error) { - if d.node != 0 { - return d.node, nil - } +// NodeID returns the node identity +func (d *identityManager) Address() (pkg.Address, error) { id, err := substrate.NewIdentityFromEd25519Key(d.key.PrivateKey) if err != nil { - return 0, err - } - cl, err := d.sub.Substrate() - if err != nil { - return 0, err - } - defer cl.Close() - - twin, err := cl.GetTwinByPubKey(id.PublicKey()) - if err != nil { - return 0, errors.Wrap(err, "failed to get node twin") - } - - node, err := cl.GetNodeByTwinID(twin) - if err != nil { - return 0, err + return "", err } - d.node = node - return node, nil + return pkg.Address(id.Address()), nil } func (d *identityManager) Farm() (string, error) { diff --git a/pkg/network/nr/net_resource_test.go b/pkg/network/nr/net_resource_test.go index 9ab00b9fb..8dcbc429a 100644 --- a/pkg/network/nr/net_resource_test.go +++ b/pkg/network/nr/net_resource_test.go @@ -28,8 +28,8 @@ func (t *testIdentityManager) NodeID() pkg.StrIdentifier { return pkg.StrIdentifier(t.id) } -func (t *testIdentityManager) NodeIDNumeric() (uint32, error) { - return 1, nil +func (t *testIdentityManager) Address() (pkg.Address, error) { + return pkg.Address(t.id), nil } func (t *testIdentityManager) Farm() (string, error) { diff --git a/pkg/stubs/identity_stub.go b/pkg/stubs/identity_stub.go index 42e890ee2..a30eb2267 100644 --- a/pkg/stubs/identity_stub.go +++ b/pkg/stubs/identity_stub.go @@ -23,6 +23,23 @@ func NewIdentityManagerStub(client zbus.Client) *IdentityManagerStub { } } +func (s *IdentityManagerStub) Address(ctx context.Context) (ret0 pkg.Address, ret1 error) { + args := []interface{}{} + result, err := s.client.RequestContext(ctx, s.module, s.object, "Address", args...) + if err != nil { + panic(err) + } + result.PanicOnError() + ret1 = result.CallError() + loader := zbus.Loader{ + &ret0, + } + if err := result.Unmarshal(&loader); err != nil { + panic(err) + } + return +} + func (s *IdentityManagerStub) Decrypt(ctx context.Context, arg0 []uint8) (ret0 []uint8, ret1 error) { args := []interface{}{arg0} result, err := s.client.RequestContext(ctx, s.module, s.object, "Decrypt", args...) @@ -158,23 +175,6 @@ func (s *IdentityManagerStub) NodeID(ctx context.Context) (ret0 pkg.StrIdentifie return } -func (s *IdentityManagerStub) NodeIDNumeric(ctx context.Context) (ret0 uint32, ret1 error) { - args := []interface{}{} - result, err := s.client.RequestContext(ctx, s.module, s.object, "NodeIDNumeric", args...) - if err != nil { - panic(err) - } - result.PanicOnError() - ret1 = result.CallError() - loader := zbus.Loader{ - &ret0, - } - if err := result.Unmarshal(&loader); err != nil { - panic(err) - } - return -} - func (s *IdentityManagerStub) PrivateKey(ctx context.Context) (ret0 []uint8) { args := []interface{}{} result, err := s.client.RequestContext(ctx, s.module, s.object, "PrivateKey", args...) diff --git a/pkg/stubs/statistics_stub.go b/pkg/stubs/statistics_stub.go index ad5cf61ca..0cce05967 100644 --- a/pkg/stubs/statistics_stub.go +++ b/pkg/stubs/statistics_stub.go @@ -23,13 +23,14 @@ func NewStatisticsStub(client zbus.Client) *StatisticsStub { } } -func (s *StatisticsStub) Current(ctx context.Context) (ret0 gridtypes.Capacity) { +func (s *StatisticsStub) Current(ctx context.Context) (ret0 gridtypes.Capacity, ret1 error) { args := []interface{}{} result, err := s.client.RequestContext(ctx, s.module, s.object, "Current", args...) if err != nil { panic(err) } result.PanicOnError() + ret1 = result.CallError() loader := zbus.Loader{ &ret0, } diff --git a/pkg/upgrade/upgrade.go b/pkg/upgrade/upgrade.go index 34c609639..d9a5bc3f1 100644 --- a/pkg/upgrade/upgrade.go +++ b/pkg/upgrade/upgrade.go @@ -358,7 +358,7 @@ func (u *Upgrader) applyUpgrade(from, to FullFListInfo) error { } if err := u.uninstall(from.FListInfo); err != nil { - log.Error().Err(err).Msg("failed to unistall current flist. Upgraded anyway") + log.Error().Err(err).Msg("failed to uninstall current flist. Upgraded anyway") } log.Info().Msg("clean up complete, copying new files")