Path: blob/main/component/loki/source/cloudflare/internal/cloudflaretarget/fields.go
4097 views
package cloudflaretarget12// This code is copied from Promtail. The cloudflaretarget package is used to3// configure and run a target that can read from the Cloudflare Logpull API and4// forward entries to other loki components.56import (7"fmt"8)910// FieldsType defines the set of fields to fetch alongside logs.11type FieldsType string1213// Valid FieldsType values.14const (15FieldsTypeDefault FieldsType = "default"16FieldsTypeMinimal FieldsType = "minimal"17FieldsTypeExtended FieldsType = "extended"18FieldsTypeAll FieldsType = "all"19)2021var (22defaultFields = []string{23"ClientIP", "ClientRequestHost", "ClientRequestMethod", "ClientRequestURI", "EdgeEndTimestamp", "EdgeResponseBytes",24"EdgeRequestHost", "EdgeResponseStatus", "EdgeStartTimestamp", "RayID",25}26minimalFields = append(defaultFields, []string{27"ZoneID", "ClientSSLProtocol", "ClientRequestProtocol", "ClientRequestPath", "ClientRequestUserAgent", "ClientRequestReferer",28"EdgeColoCode", "ClientCountry", "CacheCacheStatus", "CacheResponseStatus", "EdgeResponseContentType", "SecurityLevel",29"WAFAction", "WAFProfile", "WAFRuleID", "WAFRuleMessage", "EdgeRateLimitID", "EdgeRateLimitAction",30}...)31extendedFields = append(minimalFields, []string{32"ClientSSLCipher", "ClientASN", "ClientIPClass", "CacheResponseBytes", "EdgePathingOp", "EdgePathingSrc", "EdgePathingStatus", "ParentRayID",33"WorkerCPUTime", "WorkerStatus", "WorkerSubrequest", "WorkerSubrequestCount", "OriginIP", "OriginResponseStatus", "OriginSSLProtocol",34"OriginResponseHTTPExpires", "OriginResponseHTTPLastModified",35}...)36allFields = append(extendedFields, []string{37"BotScore", "BotScoreSrc", "ClientRequestBytes", "ClientSrcPort", "ClientXRequestedWith", "CacheTieredFill", "EdgeResponseCompressionRatio", "EdgeServerIP", "FirewallMatchesSources",38"FirewallMatchesActions", "FirewallMatchesRuleIDs", "OriginResponseBytes", "OriginResponseTime", "ClientDeviceType", "WAFFlags", "WAFMatchedVar", "EdgeColoID",39"RequestHeaders", "ResponseHeaders",40}...)41)4243// Fields returns the mapping of FieldsType to the set of fields it represents.44func Fields(t FieldsType) ([]string, error) {45switch t {46case FieldsTypeDefault:47return defaultFields, nil48case FieldsTypeMinimal:49return minimalFields, nil50case FieldsTypeExtended:51return extendedFields, nil52case FieldsTypeAll:53return allFields, nil54default:55return nil, fmt.Errorf("unknown fields type: %s", t)56}57}585960