Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Devtools 1273 lint #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Standard Lint

on:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
standard-lint:
uses: Typeform/.github/.github/workflows/go-lint-workflow.yaml@v1
secrets:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
with:
go-version: 1.20.3
71 changes: 47 additions & 24 deletions bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func TestHandlePacket(t *testing.T) {
}{
{
name: "empty",
}, {
},
{
name: "simple counter",
in: "foo:2|c",
out: Events{
Expand All @@ -36,7 +37,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "simple gauge",
in: "foo:3|g",
out: Events{
Expand All @@ -46,7 +48,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "gauge decrement",
in: "foo:-10|g",
out: Events{
Expand All @@ -57,7 +60,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "simple timer",
in: "foo:200|ms",
out: Events{
Expand All @@ -67,7 +71,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "datadog tag extension",
in: "foo:100|c|#tag1:bar,tag2:baz",
out: Events{
Expand All @@ -77,7 +82,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
},
{
name: "datadog tag extension with # in all keys (as sent by datadog php client)",
in: "foo:100|c|#tag1:bar,#tag2:baz",
out: Events{
Expand All @@ -87,7 +93,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
},
{
name: "datadog tag extension with tag keys unsupported by prometheus",
in: "foo:100|c|#09digits:0,tag.with.dots:1",
out: Events{
Expand All @@ -97,7 +104,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"_09digits": "0", "tag_with_dots": "1"},
},
},
}, {
},
{
name: "datadog tag extension with valueless tags: ignored",
in: "foo:100|c|#tag_without_a_value",
out: Events{
Expand All @@ -107,7 +115,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "datadog tag extension with valueless tags (edge case)",
in: "foo:100|c|#tag_without_a_value,tag:value",
out: Events{
Expand All @@ -117,7 +126,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"tag": "value"},
},
},
}, {
},
{
name: "datadog tag extension with empty tags (edge case)",
in: "foo:100|c|#tag:value,,",
out: Events{
Expand All @@ -127,7 +137,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"tag": "value"},
},
},
}, {
},
{
name: "datadog tag extension with sampling",
in: "foo:100|c|@0.1|#tag1:bar,#tag2:baz",
out: Events{
Expand All @@ -137,7 +148,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"tag1": "bar", "tag2": "baz"},
},
},
}, {
},
{
name: "datadog tag extension with multiple colons",
in: "foo:100|c|@0.1|#tag1:foo:bar",
out: Events{
Expand All @@ -147,13 +159,16 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"tag1": "foo:bar"},
},
},
}, {
},
{
name: "datadog tag extension with invalid utf8 tag values",
in: "foo:100|c|@0.1|#tag:\xc3\x28invalid",
}, {
},
{
name: "datadog tag extension with both valid and invalid utf8 tag values",
in: "foo:100|c|@0.1|#tag1:valid,tag2:\xc3\x28invalid",
}, {
},
{
name: "multiple metrics with invalid datadog utf8 tag values",
in: "foo:200|c|#tag:value\nfoo:300|c|#tag:\xc3\x28invalid",
out: Events{
Expand All @@ -163,7 +178,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{"tag": "value"},
},
},
}, {
},
{
name: "combined multiline metrics",
in: "foo:200|ms:300|ms:5|c|@0.1:6|g\nbar:1|c:5|ms",
out: Events{
Expand Down Expand Up @@ -198,7 +214,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "timings with sampling factor",
in: "foo.timing:0.5|ms|@0.1",
out: Events{
Expand All @@ -213,16 +230,20 @@ func TestHandlePacket(t *testing.T) {
&TimerEvent{metricName: "foo.timing", value: 0.5, labels: map[string]string{}},
&TimerEvent{metricName: "foo.timing", value: 0.5, labels: map[string]string{}},
},
}, {
},
{
name: "bad line",
in: "foo",
}, {
},
{
name: "bad component",
in: "foo:1",
}, {
},
{
name: "bad value",
in: "foo:1o|c",
}, {
},
{
name: "illegal sampling factor",
in: "foo:1|c|@bar",
out: Events{
Expand All @@ -232,7 +253,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "zero sampling factor",
in: "foo:2|c|@0",
out: Events{
Expand All @@ -242,7 +264,8 @@ func TestHandlePacket(t *testing.T) {
labels: map[string]string{},
},
},
}, {
},
{
name: "illegal stat type",
in: "foo:2|t",
},
Expand Down Expand Up @@ -288,7 +311,7 @@ func TestHandlePacket(t *testing.T) {
}

for j, expected := range scenario.out {
if !reflect.DeepEqual(&expected, &actual[j]) {
if !reflect.DeepEqual(&expected, &actual[j]) { //nolint:gosec
t.Fatalf("%d.%d.%d. Expected %#v, got %#v in scenario '%s'", k, i, j, expected, actual[j], scenario.name)
}
}
Expand Down
Loading