Skip to content

Commit

Permalink
Revive linter placeholders for Serverless
Browse files Browse the repository at this point in the history
  • Loading branch information
KSerrania authored and dd-mergequeue[bot] committed Dec 5, 2023
1 parent 324b029 commit bb2f9c7
Show file tree
Hide file tree
Showing 39 changed files with 119 additions and 16 deletions.
11 changes: 8 additions & 3 deletions cmd/serverless-init/cloudservice/appservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package cloudservice

import (
Expand All @@ -15,9 +16,13 @@ import (
type AppService struct{}

const (
WebsiteName = "WEBSITE_SITE_NAME"
RegionName = "REGION_NAME"
RunZip = "APPSVC_RUN_ZIP"
//nolint:revive // TODO(SERV) Fix revive linter
WebsiteName = "WEBSITE_SITE_NAME"
//nolint:revive // TODO(SERV) Fix revive linter
RegionName = "REGION_NAME"
//nolint:revive // TODO(SERV) Fix revive linter
RunZip = "APPSVC_RUN_ZIP"
//nolint:revive // TODO(SERV) Fix revive linter
AppLogsTrace = "WEBSITE_APPSERVICEAPPLOGS_TRACE_ENABLED"
)

Expand Down
16 changes: 12 additions & 4 deletions cmd/serverless-init/cloudservice/containerapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@ import (

// ContainerApp has helper functions for getting specific Azure Container App data
type ContainerApp struct {
//nolint:revive // TODO(SERV) Fix revive linter
SubscriptionId string
ResourceGroup string
//nolint:revive // TODO(SERV) Fix revive linter
ResourceGroup string
}

const (
//nolint:revive // TODO(SERV) Fix revive linter
ContainerAppNameEnvVar = "CONTAINER_APP_NAME"
ContainerAppDNSSuffix = "CONTAINER_APP_ENV_DNS_SUFFIX"
ContainerAppRevision = "CONTAINER_APP_REVISION"
//nolint:revive // TODO(SERV) Fix revive linter
ContainerAppDNSSuffix = "CONTAINER_APP_ENV_DNS_SUFFIX"
//nolint:revive // TODO(SERV) Fix revive linter
ContainerAppRevision = "CONTAINER_APP_REVISION"

//nolint:revive // TODO(SERV) Fix revive linter
AzureSubscriptionIdEnvVar = "DD_AZURE_SUBSCRIPTION_ID"
AzureResourceGroupEnvVar = "DD_AZURE_RESOURCE_GROUP"
//nolint:revive // TODO(SERV) Fix revive linter
AzureResourceGroupEnvVar = "DD_AZURE_RESOURCE_GROUP"
)

// GetTags returns a map of Azure-related tags
Expand Down Expand Up @@ -86,6 +93,7 @@ func (c *ContainerApp) Init() error {
// and DD_AZURE_RESOURCE_GROUP.
// These environment variables are optional for now. Once we go GA,
// return an error if these are not set.
//nolint:revive // TODO(SERV) Fix revive linter
if subscriptionId, exists := os.LookupEnv(AzureSubscriptionIdEnvVar); exists {
c.SubscriptionId = subscriptionId
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/serverless-init/cloudservice/containerapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestInitHasErrorsWhenMissingSubscriptionId(t *testing.T) {
err := cmd.Run()
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
return
} else {
} else { //nolint:revive // TODO(SERV) Fix revive linter
assert.FailNow(t, "Process didn't exit when not specifying DD_AZURE_SUBSCRIPTION_ID")
}
}
Expand All @@ -106,7 +106,7 @@ func TestInitHasErrorsWhenMissingResourceGroup(t *testing.T) {
err := cmd.Run()
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
return
} else {
} else { //nolint:revive // TODO(SERV) Fix revive linter
assert.FailNow(t, "Process didn't exit when not specifying DD_AZURE_RESOURCE_GROUP")
}
}
1 change: 1 addition & 0 deletions cmd/serverless-init/cloudservice/helper/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package helper

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/serverless-init/cloudservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type CloudService interface {
Init() error
}

//nolint:revive // TODO(SERV) Fix revive linter
type LocalService struct{}

// GetTags is a default implementation that returns a local empty tag set
Expand All @@ -49,6 +50,7 @@ func (l *LocalService) Init() error {
return nil
}

//nolint:revive // TODO(SERV) Fix revive linter
func GetCloudServiceType() CloudService {
if isCloudRunService() {
return &CloudRun{}
Expand Down
1 change: 1 addition & 0 deletions cmd/serverless-init/initcontainer/initcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//go:build !windows

//nolint:revive // TODO(SERV) Fix revive linter
package initcontainer

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/serverless-init/initcontainer/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package initcontainer

import (
Expand Down
1 change: 1 addition & 0 deletions cmd/serverless-init/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//go:build windows

//nolint:revive // TODO(SERV) Fix revive linter
package main

func main() {
Expand Down
5 changes: 5 additions & 0 deletions cmd/serverless-init/metric/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package metric

import (
Expand All @@ -14,11 +15,15 @@ import (
)

// AddColdStartMetric adds the coldstart metric to the demultiplexer
//
//nolint:revive // TODO(SERV) Fix revive linter
func AddColdStartMetric(metricPrefix string, tags []string, timestamp time.Time, demux aggregator.Demultiplexer) {
add(fmt.Sprintf("%v.enhanced.cold_start", metricPrefix), tags, time.Now(), demux)
}

// AddShutdownMetric adds the shutdown metric to the demultiplexer
//
//nolint:revive // TODO(SERV) Fix revive linter
func AddShutdownMetric(metricPrefix string, tags []string, timestamp time.Time, demux aggregator.Demultiplexer) {
add(fmt.Sprintf("%v.enhanced.shutdown", metricPrefix), tags, time.Now(), demux)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/serverless-init/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package tag

import (
Expand All @@ -13,6 +14,8 @@ import (
)

// TagPair contains a pair of tag key and value
//
//nolint:revive // TODO(SERV) Fix revive linter
type TagPair struct {
name string
envName string
Expand Down
2 changes: 2 additions & 0 deletions cmd/serverless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package main

import (
Expand Down Expand Up @@ -182,6 +183,7 @@ func runAgent() {
// Channels for ColdStartCreator
lambdaSpanChan := make(chan *pb.Span)
lambdaInitMetricChan := make(chan *serverlessLogs.LambdaInitMetric)
//nolint:revive // TODO(SERV) Fix revive linter
coldStartSpanId := random.Random.Uint64()
metricAgent := &metrics.ServerlessMetricAgent{
SketchesBucketOffset: time.Second * 10,
Expand Down
3 changes: 3 additions & 0 deletions pkg/serverless/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package daemon

import (
Expand Down Expand Up @@ -208,10 +209,12 @@ func (d *Daemon) SetTraceAgent(traceAgent *trace.ServerlessTraceAgent) {
d.TraceAgent = traceAgent
}

//nolint:revive // TODO(SERV) Fix revive linter
func (d *Daemon) SetOTLPAgent(otlpAgent *otlp.ServerlessOTLPAgent) {
d.OTLPAgent = otlpAgent
}

//nolint:revive // TODO(SERV) Fix revive linter
func (d *Daemon) SetColdStartSpanCreator(creator *trace.ColdStartSpanCreator) {
d.ColdStartCreator = creator
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/serverless/daemon/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Hello struct {
daemon *Daemon
}

//nolint:revive // TODO(SERV) Fix revive linter
func (h *Hello) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Debug("Hit on the serverless.Hello route.")
h.daemon.LambdaLibraryDetected = true
Expand All @@ -34,6 +35,7 @@ type Flush struct {
daemon *Daemon
}

//nolint:revive // TODO(SERV) Fix revive linter
func (f *Flush) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Debug("Hit on the serverless.Flush route.")
if os.Getenv(LocalTestEnvVar) == "true" || os.Getenv(LocalTestEnvVar) == "1" {
Expand Down Expand Up @@ -131,6 +133,7 @@ type TraceContext struct {
daemon *Daemon
}

//nolint:revive // TODO(SERV) Fix revive linter
func (tc *TraceContext) ServeHTTP(w http.ResponseWriter, r *http.Request) {
executionInfo := tc.daemon.InvocationProcessor.GetExecutionInfo()
log.Debug("Hit on the serverless.TraceContext route.")
Expand Down
1 change: 1 addition & 0 deletions pkg/serverless/daemon/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"
)

//nolint:revive // TODO(SERV) Fix revive linter
const LocalTestEnvVar = "DD_LOCAL_TEST"

// waitWithTimeout waits for a WaitGroup with a specified max timeout.
Expand Down
8 changes: 8 additions & 0 deletions pkg/serverless/executioncontext/executioncontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package executioncontext

import (
Expand All @@ -15,6 +16,7 @@ import (

const persistedStateFilePath = "/tmp/dd-lambda-extension-cache.json"

//nolint:revive // TODO(SERV) Fix revive linter
type ColdStartTags struct {
IsColdStart bool
IsProactiveInit bool
Expand Down Expand Up @@ -73,6 +75,8 @@ func (ec *ExecutionContext) GetCurrentState() State {
}

// Returns whether or not the given request ID is a cold start or is a proactive init
//
//nolint:revive // TODO(SERV) Fix revive linter
func (ec *ExecutionContext) GetColdStartTagsForRequestID(requestID string) ColdStartTags {
ec.m.Lock()
defer ec.m.Unlock()
Expand Down Expand Up @@ -130,6 +134,8 @@ func (ec *ExecutionContext) SetArnFromExtensionResponse(arn string) {
}

// SetInitTime sets the agent initialization time
//
//nolint:revive // TODO(SERV) Fix revive linter
func (ec *ExecutionContext) SetInitializationTime(time time.Time) {
ec.m.Lock()
defer ec.m.Unlock()
Expand All @@ -153,6 +159,8 @@ func (ec *ExecutionContext) UpdateEndTime(time time.Time) {

// UpdateOutOfMemoryRequestID updates the execution context with the request ID if an
// out of memory is detected either in the function or platform.report logs
//
//nolint:revive // TODO(SERV) Fix revive linter
func (ec *ExecutionContext) UpdateOutOfMemoryRequestID(requestId string) {
ec.m.Lock()
defer ec.m.Unlock()
Expand Down
1 change: 1 addition & 0 deletions pkg/serverless/flush/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package flush

import (
Expand Down
1 change: 1 addition & 0 deletions pkg/serverless/invocationlifecycle/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package invocationlifecycle

const (
Expand Down
7 changes: 7 additions & 0 deletions pkg/serverless/logs/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package logs

import (
Expand All @@ -11,19 +12,25 @@ import (
)

// LambdaLogsAPI implements the AWS Lambda Logs API callback
//
//nolint:revive // TODO(SERV) Fix revive linter
type LambdaLogsAPIServer struct {
out chan<- []LambdaLogAPIMessage
}

//nolint:revive // TODO(SERV) Fix revive linter
func NewLambdaLogsAPIServer(out chan<- []LambdaLogAPIMessage) LambdaLogsAPIServer {
return LambdaLogsAPIServer{out}
}

//nolint:revive // TODO(SERV) Fix revive linter
func (l *LambdaLogsAPIServer) Close() {
close(l.out)
}

// ServeHTTP - see type LambdaLogsCollector comment.
//
//nolint:revive // TODO(SERV) Fix revive linter
func (c *LambdaLogsAPIServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
data, _ := io.ReadAll(r.Body)
defer r.Body.Close()
Expand Down
12 changes: 8 additions & 4 deletions pkg/serverless/logs/logs_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Tags struct {
Tags []string
}

//nolint:revive // TODO(SERV) Fix revive linter
type LambdaInitMetric struct {
InitDurationTelemetry float64
InitStartTime time.Time
Expand All @@ -50,17 +51,19 @@ type LambdaLogsCollector struct {
enhancedMetricsEnabled bool
invocationStartTime time.Time
invocationEndTime time.Time
process_once *sync.Once
executionContext *executioncontext.ExecutionContext
lambdaInitMetricChan chan<- *LambdaInitMetric
orphanLogsChan chan []LambdaLogAPIMessage
//nolint:revive // TODO(SERV) Fix revive linter
process_once *sync.Once
executionContext *executioncontext.ExecutionContext
lambdaInitMetricChan chan<- *LambdaInitMetric
orphanLogsChan chan []LambdaLogAPIMessage

arn string

// handleRuntimeDone is the function to be called when a platform.runtimeDone log message is received
handleRuntimeDone func()
}

//nolint:revive // TODO(SERV) Fix revive linter
func NewLambdaLogCollector(out chan<- *logConfig.ChannelMessage, demux aggregator.Demultiplexer, extraTags *Tags, logsEnabled bool, enhancedMetricsEnabled bool, executionContext *executioncontext.ExecutionContext, handleRuntimeDone func(), lambdaInitMetricChan chan<- *LambdaInitMetric) *LambdaLogsCollector {

return &LambdaLogsCollector{
Expand Down Expand Up @@ -258,6 +261,7 @@ func (lc *LambdaLogsCollector) processMessage(
coldStart = coldStartTags.IsColdStart
}
tags := tags.AddColdStartTag(lc.extraTags.Tags, coldStart, proactiveInit)
//nolint:revive // TODO(SERV) Fix revive linter
outOfMemoryRequestId := ""

if message.logType == logTypeFunction {
Expand Down
1 change: 1 addition & 0 deletions pkg/serverless/logs/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (l *LambdaLogAPIMessage) handlePlatformReport(objectRecord map[string]inter
log.Debugf("Enhanced metrics: %+v\n", l.objectRecord.reportLogItem)
}

//nolint:revive // TODO(SERV) Fix revive linter
func (l *LambdaLogAPIMessage) handlePlatformInitStart(objectRecord map[string]interface{}) {
l.objectRecord.reportLogItem.initStartTime = l.time
}
Expand Down
1 change: 1 addition & 0 deletions pkg/serverless/logs/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func SetLogsTags(tags []string) {
}
}

//nolint:revive // TODO(SERV) Fix revive linter
func GetLogsTags() []string {
if logsScheduler != nil {
return logsScheduler.GetLogsTags()
Expand Down
1 change: 1 addition & 0 deletions pkg/serverless/metrics/enhanced_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//nolint:revive // TODO(SERV) Fix revive linter
package metrics

import (
Expand Down
Loading

0 comments on commit bb2f9c7

Please sign in to comment.