inlet/flow: make it compile on MacOS

This commit is contained in:
Vincent Bernat
2022-07-16 20:55:42 +02:00
parent e6a10f7627
commit 13e8c65bfb
7 changed files with 98 additions and 23 deletions

View File

@@ -10,7 +10,7 @@ on:
schedule:
- cron: 0 7 1 * *
jobs:
build:
build-linux:
runs-on: ubuntu-latest
services:
zookeeper:
@@ -86,9 +86,39 @@ jobs:
path: changelog.md
if-no-files-found: error
build-macos:
runs-on: macos-latest
steps:
# Setup
- uses: actions/checkout@v3
- name: Install dependencies
run: brew install protobuf
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
cache: true
# Cache
- uses: actions/cache@v3
id: npm-cache
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('console/frontend/package-lock.json') }}
- uses: actions/cache@v3
id: gobin-cache
with:
path: bin
key: ${{ runner.os }}-gobin-${{ hashFiles('Makefile') }}
# Build and test
- name: Build
run: make
- name: Tests
run: make test || make test
docker:
needs:
- build
- build-linux
runs-on: ubuntu-latest
name: Build Docker images
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
@@ -125,7 +155,8 @@ jobs:
release:
needs:
- build
- build-linux
- build-macos
- docker
runs-on: ubuntu-latest
name: Publish release

View File

@@ -6,6 +6,7 @@ package metrics_test
import (
"fmt"
"net/http/httptest"
"runtime"
"strings"
"testing"
@@ -45,7 +46,11 @@ func TestNew(t *testing.T) {
got := strings.Split(w.Body.String(), "\n")
// We expect some go_* and process_* gauges
for _, expected := range []string{"process_open_fds", "go_threads", "go_sched_goroutines_goroutines"} {
expecteds := []string{"go_threads", "go_sched_goroutines_goroutines"}
if runtime.GOOS == "linux" {
expecteds = append(expecteds, "process_open_fds")
}
for _, expected := range expecteds {
found := false
for _, line := range got {
if line == fmt.Sprintf("# TYPE %s gauge", expected) {

View File

@@ -14,6 +14,7 @@ identified with a specific icon:
- 🩹 *console*: fix use of `InIfBoundary` and `OutIfBoundary` as dimensions [PR #11][]
- 🩹 *docker-compose*: avoid starting bogus "akvorado-image" service
- 🩹 *build*: make *Akvorado* compile on MacOS
- 🌱 *doc*: add configuration for Juniper devices
- 🌱 *docker-compose*: add [UI for Apache Kafka][] to help debug starter issues

View File

@@ -8,18 +8,15 @@ import (
"syscall"
"golang.org/x/sys/unix"
"akvorado/common/helpers"
)
var (
oobLength = syscall.CmsgLen(4)
// listenConfig configures a listening socket to reuse port and return overflows
listenConfig = net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
var err error
c.Control(func(fd uintptr) {
opts := []int{unix.SO_REUSEADDR, unix.SO_REUSEPORT, unix.SO_RXQ_OVFL}
opts := udpSocketOptions
for _, opt := range opts {
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, opt, 1)
if err != nil {
@@ -31,18 +28,3 @@ var (
},
}
)
// parseSocketControlMessage parses b and extract the number of drops
// returned (SO_RXQ_OVFL).
func parseSocketControlMessage(b []byte) (uint32, error) {
cmsgs, err := syscall.ParseSocketControlMessage(b)
if err != nil {
return 0, err
}
for _, cmsg := range cmsgs {
if cmsg.Header.Level == unix.SOL_SOCKET && cmsg.Header.Type == unix.SO_RXQ_OVFL {
return helpers.NativeEndian.Uint32(cmsg.Data), nil
}
}
return 0, nil
}

View File

@@ -0,0 +1,34 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
//go:build linux
package udp
import (
"syscall"
"akvorado/common/helpers"
"golang.org/x/sys/unix"
)
var (
oobLength = syscall.CmsgLen(4)
udpSocketOptions = []int{unix.SO_REUSEADDR, unix.SO_REUSEPORT, unix.SO_RXQ_OVFL}
)
// parseSocketControlMessage parses b and extract the number of drops
// returned (SO_RXQ_OVFL).
func parseSocketControlMessage(b []byte) (uint32, error) {
cmsgs, err := syscall.ParseSocketControlMessage(b)
if err != nil {
return 0, err
}
for _, cmsg := range cmsgs {
if cmsg.Header.Level == unix.SOL_SOCKET && cmsg.Header.Type == unix.SO_RXQ_OVFL {
return helpers.NativeEndian.Uint32(cmsg.Data), nil
}
}
return 0, nil
}

View File

@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
//go:build !linux
package udp
import "golang.org/x/sys/unix"
var (
oobLength = 0
udpSocketOptions = []int{unix.SO_REUSEADDR, unix.SO_REUSEPORT}
)
// parseSocketControlMessage always returns 0.
func parseSocketControlMessage(b []byte) (uint32, error) {
return 0, nil
}

View File

@@ -8,11 +8,15 @@ import (
"errors"
"net"
"os"
"runtime"
"testing"
"time"
)
func TestParseSocketControlMessage(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("Skip Linux-only test")
}
server, err := listenConfig.ListenPacket(context.Background(), "udp", "127.0.0.1:0")
if err != nil {
t.Fatalf("ListenPacket() error:\n%+v", err)