Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add staticcheck github action #1434

Closed
wants to merge 8 commits into from
Closed
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
52 changes: 52 additions & 0 deletions .github/workflows/static-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: static-check

on:
pull_request:
push:
tags:
- 'v*'
branches:
- main

jobs:
staticcheck:
strategy:
matrix:
go: "1.21.x"
module:
- pkg/configprovider/globprovider
- pkg/configprovider/opampprovider
- pkg/exporter/sumologicexporter
- pkg/exporter/syslogexporter
- pkg/extension/opampextension
- pkg/extension/sumologicextension
- pkg/processor/cascadingfilterprocessor
- pkg/processor/k8sprocessor
- pkg/processor/metricfrequencyprocessor
- pkg/processor/sourceprocessor
- pkg/processor/sumologicschemaprocessor
- pkg/processor/sumologicsyslogprocessor
- pkg/receiver/activedirectoryinvreceiver
- pkg/receiver/jobreceiver
- pkg/receiver/rawk8seventsreceiver
- pkg/receiver/telegrafreceiver
- pkg/scripts_test
- pkg/test
name: ${{ matrix.module }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- uses: WillAbides/[email protected]
with:
go-version: "${{ matrix.go }}"
- uses: dominikh/[email protected]
with:
working-directory:
${{ matrix.module }}
version: "2023.1.6"
install-go: false
cache-key: "${{ matrix.go }}"
env:
GO_VERSION: 1.21.3
49 changes: 24 additions & 25 deletions pkg/processor/k8sprocessor/kube/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"go.uber.org/zap/zapcore"
"go.uber.org/zap/zaptest/observer"
api_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -244,7 +243,7 @@ func TestPodAddOutOfSync(t *testing.T) {
pod.Name = "podA"
pod.Namespace = "namespace"
pod.Status.PodIP = "1.1.1.1"
startTime := meta_v1.NewTime(time.Now())
startTime := metav1.NewTime(time.Now())
pod.Status.StartTime = &startTime
c.handlePodAdd(pod)
assert.Equal(t, len(c.Pods), 2)
Expand All @@ -256,7 +255,7 @@ func TestPodAddOutOfSync(t *testing.T) {
pod2.Name = "podB"
pod2.Namespace = "namespace"
pod2.Status.PodIP = "1.1.1.1"
startTime2 := meta_v1.NewTime(time.Now().Add(-time.Second * 10))
startTime2 := metav1.NewTime(time.Now().Add(-time.Second * 10))
pod2.Status.StartTime = &startTime2
c.handlePodAdd(pod2)
assert.Equal(t, len(c.Pods), 3)
Expand Down Expand Up @@ -405,7 +404,7 @@ func TestGetPod(t *testing.T) {
pod.UID = "1234"
pod.Name = "pod_name"
pod.Namespace = "namespace_name"
pod.OwnerReferences = []meta_v1.OwnerReference{
pod.OwnerReferences = []metav1.OwnerReference{
metav1.OwnerReference{
Name: "A reference",
},
Expand Down Expand Up @@ -445,7 +444,7 @@ func TestGetPodConcurrent(t *testing.T) {
pod.UID = "1234"
pod.Name = "pod_name"
pod.Namespace = "namespace_name"
pod.OwnerReferences = []meta_v1.OwnerReference{
pod.OwnerReferences = []metav1.OwnerReference{
{
Kind: "StatefulSet",
Name: "snug-sts",
Expand Down Expand Up @@ -490,7 +489,7 @@ func TestGetPodOwnerAttributesConcurrent(t *testing.T) {
pod.UID = "1234"
pod.Name = "pod_name"
pod.Namespace = "namespace_name"
pod.OwnerReferences = []meta_v1.OwnerReference{
pod.OwnerReferences = []metav1.OwnerReference{
{
Kind: "StatefulSet",
Name: "snug-sts",
Expand Down Expand Up @@ -572,7 +571,7 @@ func TestNoHostnameExtractionRules(t *testing.T) {
podName := "auth-service-abc12-xyz3"

pod := &api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: podName,
},
Spec: api_v1.PodSpec{},
Expand All @@ -596,11 +595,11 @@ func TestExtractionRules(t *testing.T) {
c, _ := newTestClientWithRulesAndFilters(t, ExtractionRules{OwnerLookupEnabled: true}, Filters{})

pod := &api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "auth-service-abc12-xyz3",
Namespace: "ns1",
UID: "33333",
CreationTimestamp: meta_v1.Now(),
CreationTimestamp: metav1.Now(),
Labels: map[string]string{
"label1": "lv1",
"label2": "k1=v1 k5=v5 extra!",
Expand Down Expand Up @@ -631,7 +630,7 @@ func TestExtractionRules(t *testing.T) {

testCases := []struct {
name string
podOwner *meta_v1.OwnerReference
podOwner *metav1.OwnerReference
rules ExtractionRules
attributes map[string]string
}{
Expand All @@ -650,7 +649,7 @@ func TestExtractionRules(t *testing.T) {
},
{
name: "deployment name with owner lookup",
podOwner: &meta_v1.OwnerReference{
podOwner: &metav1.OwnerReference{
Kind: "ReplicaSet",
Name: "dearest-deploy-77c99ccb96",
UID: "1a1658f9-7818-11e9-90f1-02324f7e0d1e",
Expand All @@ -666,7 +665,7 @@ func TestExtractionRules(t *testing.T) {
},
{
name: "statefulset name",
podOwner: &meta_v1.OwnerReference{
podOwner: &metav1.OwnerReference{
Kind: "StatefulSet",
Name: "snug-sts",
UID: "f15f0585-a0bc-43a3-96e4-dd2eace75391",
Expand All @@ -683,7 +682,7 @@ func TestExtractionRules(t *testing.T) {
},
{
name: "job name and cron job are not added by default",
podOwner: &meta_v1.OwnerReference{
podOwner: &metav1.OwnerReference{
Kind: "Job",
Name: "hello-job",
UID: "f15f0585-a0bc-43a3-96e4-dd2ea9975391",
Expand All @@ -696,7 +695,7 @@ func TestExtractionRules(t *testing.T) {
},
{
name: "job name is added properly",
podOwner: &meta_v1.OwnerReference{
podOwner: &metav1.OwnerReference{
Kind: "Job",
Name: "hello-job",
UID: "f15f0585-a0bc-43a3-96e4-dd2ea9975391",
Expand All @@ -712,7 +711,7 @@ func TestExtractionRules(t *testing.T) {
},
{
name: "job name and cron job name are added properly",
podOwner: &meta_v1.OwnerReference{
podOwner: &metav1.OwnerReference{
Kind: "Job",
Name: "hello-job",
UID: "f15f0585-a0bc-43a3-96e4-dd2ea9975391",
Expand All @@ -730,7 +729,7 @@ func TestExtractionRules(t *testing.T) {
},
{
name: "metadata",
podOwner: &meta_v1.OwnerReference{
podOwner: &metav1.OwnerReference{
Kind: "ReplicaSet",
Name: "foo-bar-rs",
UID: "1a1658f9-7818-11e9-90f1-02324f7e0d1e",
Expand Down Expand Up @@ -863,7 +862,7 @@ func TestExtractionRules(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
if tc.podOwner != nil {
pod.OwnerReferences = []meta_v1.OwnerReference{
pod.OwnerReferences = []metav1.OwnerReference{
*tc.podOwner,
}
}
Expand Down Expand Up @@ -986,7 +985,7 @@ func TestPodIgnorePatterns(t *testing.T) {
}, {
ignore: true,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"opentelemetry.io/k8s-processor/ignore": "True ",
},
Expand All @@ -995,7 +994,7 @@ func TestPodIgnorePatterns(t *testing.T) {
}, {
ignore: true,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"opentelemetry.io/k8s-processor/ignore": "true",
},
Expand All @@ -1004,7 +1003,7 @@ func TestPodIgnorePatterns(t *testing.T) {
}, {
ignore: false,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"opentelemetry.io/k8s-processor/ignore": "false",
},
Expand All @@ -1013,7 +1012,7 @@ func TestPodIgnorePatterns(t *testing.T) {
}, {
ignore: false,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"opentelemetry.io/k8s-processor/ignore": "",
},
Expand All @@ -1022,28 +1021,28 @@ func TestPodIgnorePatterns(t *testing.T) {
}, {
ignore: true,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "jaeger-agent",
},
},
}, {
ignore: true,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "jaeger-collector",
},
},
}, {
ignore: true,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "jaeger-agent-b2zdv",
},
},
}, {
ignore: false,
pod: api_v1.Pod{
ObjectMeta: meta_v1.ObjectMeta{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod-name",
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/receiver/activedirectoryinvreceiver/adinvreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (r *ADReceiver) poll(ctx context.Context) error {
_ = resourceLogs.ScopeLogs().AppendEmpty()
root, err := r.client.Open(r.config.BaseDN, resourceLogs)
if err != nil {
return fmt.Errorf("Invalid Distinguished Name, please verify that the domain exists: %w", err)
return fmt.Errorf("invalid distinguished name, please verify that the domain exists: %w", err)
}
r.traverse(root, r.config.Attributes, resourceLogs)
err = r.consumer.ConsumeLogs(ctx, logs)
Expand Down
2 changes: 1 addition & 1 deletion pkg/receiver/activedirectoryinvreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ADConfig struct {
var (
errInvalidDN = errors.New("base_dn is required, it must be a valid distinguished name (CN=Guest,OU=Users,DC=example,DC=com)")
errInvalidPollInterval = errors.New("poll_interval is incorrect, invalid duration")
errSupportedOS = errors.New(typeStr + " is only supported on Windows.")
errSupportedOS = errors.New(typeStr + " is only supported on Windows")
)

func isValidDuration(duration time.Duration) bool {
Expand Down
Loading