Skip to content

Commit

Permalink
{,x-pack/}packetbeat: remove dead code and unused fields, vars, const…
Browse files Browse the repository at this point in the history
…s and comments (#30489)

This removes the majority of unused code identified by running:

staticcheck -checks 'U*' ./{,x-pack/}packetbeat/...

Care has been taken to not remove platform-specific code and mage-required code.
  • Loading branch information
efd6 authored Feb 22, 2022
1 parent b33c45e commit 05ac8cf
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 98 deletions.
8 changes: 0 additions & 8 deletions packetbeat/flows/flowid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ func addVLan(u []byte) applyAddr {
}
}

func addUDP(a, b []byte) applyAddr {
src := binary.LittleEndian.Uint16(a)
dst := binary.LittleEndian.Uint16(b)
return func(f *FlowID) {
f.AddUDP(src, dst)
}
}

func addTCP(a, b []byte) applyAddr {
src := binary.LittleEndian.Uint16(a)
dst := binary.LittleEndian.Uint16(b)
Expand Down
14 changes: 1 addition & 13 deletions packetbeat/npcap/npcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,7 @@
// specific language governing permissions and limitations
// under the License.

// Package npcap handles fetching and installing Npcap fow Windows.
//
// The npcap package interacts with a registry and download server that
// provides a current_version end point that serves a JSON message that
// corresponds to the this Go type:
//
// struct {
// Version string // The semverish version of the Npcap installer.
// URL string // The location of the Npcap installer.
// Hash string // The sha256 hash of the Npcap installer.
// }
//
// The URL field will point to the location of anb Npcap installer.
// Package npcap handles fetching and installing Npcap for Windows.
package npcap

import (
Expand Down
63 changes: 0 additions & 63 deletions packetbeat/protos/cassandra/internal/gocql/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,60 +271,6 @@ func (t Type) String() string {
}
}

const (
apacheCassandraTypePrefix = "org.apache.cassandra.db.marshal."
)

// get Apache Cassandra types
func getApacheCassandraType(class string) Type {
switch strings.TrimPrefix(class, apacheCassandraTypePrefix) {
case "AsciiType":
return TypeASCII
case "LongType":
return TypeBigInt
case "BytesType":
return TypeBlob
case "BooleanType":
return TypeBoolean
case "CounterColumnType":
return TypeCounter
case "DecimalType":
return TypeDecimal
case "DoubleType":
return TypeDouble
case "FloatType":
return TypeFloat
case "Int32Type":
return TypeInt
case "ShortType":
return TypeSmallInt
case "ByteType":
return TypeTinyInt
case "DateType", "TimestampType":
return TypeTimestamp
case "UUIDType", "LexicalUUIDType":
return TypeUUID
case "UTF8Type":
return TypeVarchar
case "IntegerType":
return TypeVarint
case "TimeUUIDType":
return TypeTimeUUID
case "InetAddressType":
return TypeInet
case "MapType":
return TypeMap
case "ListType":
return TypeList
case "SetType":
return TypeSet
case "TupleType":
return TypeTuple
default:
return TypeCustom
}
}

// error Types
type ErrType int

Expand Down Expand Up @@ -565,15 +511,6 @@ const (
flagHasMorePages int = 0x02
flagNoMetaData int = 0x04

// query flags
flagValues byte = 0x01
flagSkipMetaData byte = 0x02
flagPageSize byte = 0x04
flagWithPagingState byte = 0x08
flagWithSerialConsistency byte = 0x10
flagDefaultTimestamp byte = 0x20
flagWithNameValues byte = 0x40

// header flags
flagDefault byte = 0x00
flagCompress byte = 0x01
Expand Down
13 changes: 4 additions & 9 deletions packetbeat/protos/memcache/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ import (
"errors"
)

var errNotImplemented = errors.New("not implemented")

// memcache text parser errors
var (
errParserCaughtInError = errors.New("memcache parser caught in error loop")
errParserUnknownCommand = errors.New("unknown memcache command found")
errNoMoreArgument = errors.New("no more command arguments")
errExpectedNumber = errors.New("expected number value")
errExpectedNoReply = errors.New("expected noreply in argument list")
errExpectedCRLF = errors.New("expected CRLF")
errExpectedKeys = errors.New("message has no keys")
)

Expand All @@ -49,11 +45,10 @@ var (

// memcache transaction/message errors
var (
errInvalidMessage = errors.New("message is invalid")
errMixOfBinaryAndText = errors.New("mix of binary and text in one connection")
errResponseUnknownTransaction = errors.New("response from unknown transaction")
errExpectedValueForMerge = errors.New("expected value to merge with")
errExpectedStatsForMerge = errors.New("expected stat response to merge with")
errInvalidMessage = errors.New("message is invalid")
errMixOfBinaryAndText = errors.New("mix of binary and text in one connection")
errExpectedValueForMerge = errors.New("expected value to merge with")
errExpectedStatsForMerge = errors.New("expected stat response to merge with")
)

// internal notes to be published with transaction
Expand Down
5 changes: 0 additions & 5 deletions packetbeat/scripts/mage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ import (
devtools "github.com/elastic/beats/v7/dev-tools/mage"
)

const (
// configTemplateGlob matches Packetbeat protocol config file templates.
configTemplateGlob = "protos/*/_meta/config*.yml.tmpl"
)

var defaultDevice = map[string]string{
"darwin": "en0",
"linux": "any",
Expand Down

0 comments on commit 05ac8cf

Please sign in to comment.