Skip to content

Commit

Permalink
Merge branch 'denopink/feat/optimize-qos-trim-v2' of https://github.c…
Browse files Browse the repository at this point in the history
…om/xmidt-org/xmidt-agent into denopink/feat/optimize-qos-trim-v2
  • Loading branch information
denopink committed Aug 5, 2024
2 parents 19bd918 + e1a0ae3 commit 1d2bbb6
Show file tree
Hide file tree
Showing 23 changed files with 358 additions and 172 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
---
name: 'Automatically relase patch versions.'

on:
schedule: # Run every day at 12:00 UTC
- cron: '0 12 * * *'
workflow_dispatch:

jobs:
release:
uses: xmidt-org/shared-go/.github/workflows/auto-releaser.yml@12a58ef01ff3da83567e930742524d5a215b90a2 # v4.4.17
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:

jobs:
ci:
uses: xmidt-org/shared-go/.github/workflows/ci.yml@f15dd81338419cfdec19a9110510cf9bf3182ca6 # v4.4.1
uses: xmidt-org/shared-go/.github/workflows/ci.yml@12a58ef01ff3da83567e930742524d5a215b90a2 # v4.4.17
with:
release-type: program
release-main-package: ./cmd/xmidt-agent
Expand Down
58 changes: 58 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
---
project_name: xmidt-agent

version: 2

changelog:
use: github
Expand Down Expand Up @@ -71,6 +72,63 @@ archives:
format: zip
name_template: '{{ .ProjectName }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'

nfpms:
-
id: rdk
file_name_template: '{{ .PackageName }}_{{ .Version }}_rdk_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
vendor: xmidt-org
homepage: https://github.com/xmidt-org/xmidt-agent
license: Apache-2.0
maintainer: [email protected]
description: The client agent for the Xmidt service.

formats:
- ipk

dependencies:
- systemd

contents:
# systemd service file
- src: .release/ipk/xmidt-agent.service
dst: /lib/systemd/system/xmidt-agent.service

# base configuration file
- src: .release/ipk/config.yml
dst: /etc/xmidt-agent/01-config.yml

scripts:
preinstall: .release/ipk/preinstall.sh
postinstall: .release/ipk/postinstall.sh

ipk:
fields:
Bugs: https://github.com/xmidt-org/xmidt-agent/issues

-
id: openwrt
file_name_template: '{{ .PackageName }}_{{ .Version }}_openwrt_{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}{{ with .Mips }}_{{ . }}{{ end }}{{ if not (eq .Amd64 "v1") }}{{ .Amd64 }}{{ end }}'
vendor: xmidt-org
homepage: https://github.com/xmidt-org/xmidt-agent
license: Apache-2.0
maintainer: [email protected]
description: The client agent for the Xmidt service.

formats:
- ipk

dependencies:
- systemd

contents:
# base configuration file
- src: .release/ipk/config.yml
dst: /etc/xmidt-agent/01-config.yml

ipk:
fields:
Bugs: https://github.com/xmidt-org/xmidt-agent/issues

source:
enabled: true
name_template: '{{ .ProjectName }}_{{ .Version }}_src'
Expand Down
2 changes: 1 addition & 1 deletion .release/docker/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
mock_tr_181:
enabled: true
file_path: "/mock_tr181.json"
service_name: "mock_config"
service_name: "config"
54 changes: 0 additions & 54 deletions .release/docker/config/example-config.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions .release/ipk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0
#
# Put any configuration values that should always be present here.
#
# Note:
# These values should be generic and apply to all consumers (openwrt, rdk, etc)
---
5 changes: 5 additions & 0 deletions .release/ipk/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0

systemctl preset xmidt-agent.service >/dev/null 2>&1
13 changes: 13 additions & 0 deletions .release/ipk/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0

getent group xmidt-agent > /dev/null || groupadd -r xmidt-agent
getent passwd xmidt-agent > /dev/null || \
useradd \
-d /var/run/xmidt-agent \
-r \
-g xmidt-agent \
-s /sbin/nologin \
-c "Xmidt-Agent Client" \
xmidt-agent
22 changes: 22 additions & 0 deletions .release/ipk/xmidt-agent.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: 2024 Comcast Cable Communications Management, LLC
# SPDX-License-Identifier: Apache-2.0

[Unit]
Description=The client agent for the Xmidt service.
After=network.target remote-fs.target nss-lookup.target

[Service]
User=xmidt-agent
Group=xmidt-agent
SyslogIdentifier=xmidt-agent
PIDFile=/run/xmidt-agent.pid
ExecStartPre=/usr/bin/rm -f /run/xmidt-agent.pid
ExecStart=/usr/bin/xmidt-agent
Type=simple
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
PrivateTmp=true
Restart=always

[Install]
WantedBy=multi-user.target
9 changes: 9 additions & 0 deletions cmd/xmidt-agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,15 @@ func provideConfig(cli *CLI) (*goschtalt.Config, error) {
return nil, err
}

if cli.Default != "" {
err := os.WriteFile("./"+cli.Default, defaultConfigFile, 0644) // nolint: gosec
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
os.Exit(0)
}

if cli.Show {
// handleCLIShow handles the -s/--show option where the configuration is
// shown, then the program is exited.
Expand Down
6 changes: 3 additions & 3 deletions cmd/xmidt-agent/default-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ logger:
level_key: L
name_key: N
caller_key: C
function_key: "zapcore.OmitKey"
function_key: ""
message_key: M
stacktrace_key: S
line_ending: "zapcore.DefaultLineEnding"
line_ending: "\n"
encode_level: capital
encode_time: RFC3339Nano
encode_duration: string
Expand All @@ -121,7 +121,7 @@ storage:
# temporary: "~/local-rdk-testing/temporary"
# durable: "~/local-rdk-testing/durable"
mock_tr_181:
enabled: true
enabled: false
file_path: "mock_tr181.json"
service_name: "mock_config"
xmidt_agent_crud:
Expand Down
9 changes: 5 additions & 4 deletions cmd/xmidt-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ var (

// CLI is the structure that is used to capture the command line arguments.
type CLI struct {
Dev bool `optional:"" short:"d" help:"Run in development mode."`
Show bool `optional:"" short:"s" help:"Show the configuration and exit."`
Graph string `optional:"" short:"g" help:"Output the dependency graph to the specified file."`
Files []string `optional:"" short:"f" help:"Specific configuration files or directories."`
Dev bool `optional:"" short:"d" help:"Run in development mode."`
Show bool `optional:"" short:"s" help:"Show the configuration and exit."`
Default string `optional:"" help:"Output the default configuration file as the specified file."`
Graph string `optional:"" short:"g" help:"Output the dependency graph to the specified file."`
Files []string `optional:"" short:"f" help:"Specific configuration files or directories."`
}

type LifeCycleIn struct {
Expand Down
46 changes: 0 additions & 46 deletions cmd/xmidt-agent/xmidt_agent.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ require (
github.com/stretchr/testify v1.9.0
github.com/ugorji/go/codec v1.2.12
github.com/xmidt-org/arrange v0.5.0
github.com/xmidt-org/eventor v1.0.0
github.com/xmidt-org/eventor v1.0.11
github.com/xmidt-org/retry v0.0.3
github.com/xmidt-org/sallust v0.2.2
github.com/xmidt-org/wrp-go/v3 v3.5.2
go.nanomsg.org/mangos/v3 v3.4.2
go.uber.org/fx v1.22.0
go.uber.org/fx v1.22.1
go.uber.org/zap v1.27.0
gopkg.in/dealancer/validate.v2 v2.1.0
)
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/xmidt-org/arrange v0.5.0 h1:ajkVHkr7dXnfCYm/6eafWoOab+6A3b2jEHQO0IdIIb0=
github.com/xmidt-org/arrange v0.5.0/go.mod h1:PoZB9lR49ma0osydQbaWpNeA3XPoLkjP5RYUoOw8wZU=
github.com/xmidt-org/eventor v1.0.0 h1:FiX4UsU4gztIcAn8UJAZwJjNleOeeDyBxuBS4nGeuik=
github.com/xmidt-org/eventor v1.0.0/go.mod h1:NpaRwPEiiaB5oEdFI41o6Lf4iQHAVwCdtwKb3z7R8mY=
github.com/xmidt-org/eventor v1.0.11 h1:yBoF39jzxSBeDvMVJVVyL/g85UO8/g1GxLojMmxQj5E=
github.com/xmidt-org/eventor v1.0.11/go.mod h1:NpaRwPEiiaB5oEdFI41o6Lf4iQHAVwCdtwKb3z7R8mY=
github.com/xmidt-org/httpaux v0.4.0 h1:cAL/MzIBpSsv4xZZeq/Eu1J5M3vfNe49xr41mP3COKU=
github.com/xmidt-org/httpaux v0.4.0/go.mod h1:UypqZwuZV1nn8D6+K1JDb+im9IZrLNg/2oO/Bgiybxc=
github.com/xmidt-org/retry v0.0.3 h1:wvmBnEEn1OKwSZaQtr1RZ2Vey8JIvP72mGTgR+3wPiM=
Expand All @@ -81,8 +81,8 @@ go.nanomsg.org/mangos/v3 v3.4.2 h1:gHlopxjWvJcVCcUilQIsRQk9jdj6/HB7wrTiUN8Ki7Q=
go.nanomsg.org/mangos/v3 v3.4.2/go.mod h1:8+hjBMQub6HvXmuGvIq6hf19uxGQIjCofmc62lbedLA=
go.uber.org/dig v1.17.1 h1:Tga8Lz8PcYNsWsyHMZ1Vm0OQOUaJNDyvPImgbAu9YSc=
go.uber.org/dig v1.17.1/go.mod h1:Us0rSJiThwCv2GteUN0Q7OKvU7n5J4dxZ9JKUXozFdE=
go.uber.org/fx v1.22.0 h1:pApUK7yL0OUHMd8vkunWSlLxZVFFk70jR2nKde8X2NM=
go.uber.org/fx v1.22.0/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
go.uber.org/fx v1.22.1 h1:nvvln7mwyT5s1q201YE29V/BFrGor6vMiDNpU/78Mys=
go.uber.org/fx v1.22.1/go.mod h1:HT2M7d7RHo+ebKGh9NRcrsrHHfpZ60nW3QRubMRfv48=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
Expand Down
3 changes: 2 additions & 1 deletion internal/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"strings"

"encoding/base64"
"github.com/xmidt-org/wrp-go/v3"
"github.com/xmidt-org/xmidt-agent/internal/net"
)
Expand Down Expand Up @@ -114,7 +115,7 @@ func (c *MetadataProvider) Decorate(headers http.Header) error {
return fmt.Errorf("error marshaling convey header: %w", err)
}

headers.Set(HeaderName, string(headerBytes))
headers.Set(HeaderName, base64.StdEncoding.EncodeToString(headerBytes))

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (ps *PubSub) subscribe(route string, h wrpkit.Handler) (CancelFunc, error)
func (ps *PubSub) HandleWrp(msg wrp.Message) error {
normalized, dest, err := ps.normalize(&msg)
if err != nil {
return err
return errors.Join(err, wrpkit.ErrNotHandled)
}

// Unless the destination is this device, the message will be sent to the
Expand Down
Loading

0 comments on commit 1d2bbb6

Please sign in to comment.