github.com/GuanceCloud/cliutils@v1.1.21/point/rand_deprecated.go (about)

     1  // Unless explicitly stated otherwise all files in this repository are licensed
     2  // under the MIT License.
     3  // This product includes software developed at Guance Cloud (https://www.guance.com/).
     4  // Copyright 2021-present Guance, Inc.
     5  
     6  //nolint:gosec
     7  package point
     8  
     9  import (
    10  	"fmt"
    11  	mrand "math/rand" //nolint:gosec
    12  	"time"
    13  
    14  	"github.com/GuanceCloud/cliutils"
    15  )
    16  
    17  // doRandomPoints deprecated.
    18  func doRandomPoints(count int) ([]*Point, error) {
    19  	if count <= 0 {
    20  		return nil, nil
    21  	}
    22  
    23  	// nolint: lll
    24  	sampleLogs := []string{
    25  		`2022-10-27T16:12:46.699+0800	DEBUG	io	io/io.go:265	on tick(10s) to flush /v1/write/logging(0 pts), last flush 10.000006916s ago...`,
    26  		`2022-10-27T16:12:46.306+0800	DEBUG	dataway	dataway/send.go:219	send request https://openway.guance.com/v1/datakit/pull?token=tkn_2af4b19d7f5a4xxxxxxxxxxxxxxxxxxx&filters=true, proxy: , dwcli: 0x1400049e000, timeout: 30s(30s)`,
    27  		`2022-10-27T16:12:46.306+0800	DEBUG	dataway	dataway/cli.go:27	performing request%!(EXTRA string=method, string=GET, string=url, *url.URL=https://openway.guance.com/v1/datakit/pull?token=tkn_2af4b19dxxxxxxxxxxxxxxxxxxxxxxxx&filters=true)`,
    28  		`2022-10-27T16:12:46.305+0800	DEBUG	ddtrace	trace/filters.go:235	keep tid: 2790747027482021869 service: compiled-in-example resource: ./demo according to PRIORITY_AUTO_KEEP and sampling ratio: 100%`,
    29  		`2022-10-27T16:12:46.305+0800	DEBUG	ddtrace	trace/filters.go:235	keep tid: 1965248471827589152 service: compiled-in-example resource: file-not-exists according to PRIORITY_AUTO_KEEP and sampling ratio: 100%`,
    30  		`2022-10-27T16:12:46.305+0800	DEBUG	ddtrace	trace/filters.go:102	keep tid: 2790747027482021869 service: compiled-in-example resource: ./demo according to PRIORITY_AUTO_KEEP.`,
    31  		`2022-10-27T16:12:46.305+0800	DEBUG	ddtrace	trace/filters.go:102	keep tid: 1965248471827589152 service: compiled-in-example resource: file-not-exists according to PRIORITY_AUTO_KEEP.`,
    32  		`2022-10-27T16:12:45.481+0800	DEBUG	disk	disk/utils.go:62	disk---fstype:nullfs ,device:/Applications/xxxxxx.app ,mountpoint:/private/var/folders/71/4pnfjgwn0x3fcy4r3ddxw1fm0000gn/T/AppTranslocation/1A552256-4134-4CAA-A4FF-7D2DEF11A6AC`,
    33  		`2022-10-27T16:12:45.481+0800	DEBUG	disk	disk/utils.go:62	disk---fstype:nullfs ,device:/Applications/oss-browser.app ,mountpoint:/private/var/folders/71/4pnfjgwn0x3fcy4r3ddxw1fm0000gn/T/AppTranslocation/97346A30-EA8C-4AC8-991D-3AD64E2479E1`,
    34  		`2022-10-27T16:12:45.481+0800	DEBUG	disk	disk/utils.go:62	disk---fstype:nullfs ,device:/Applications/Sublime Text.app ,mountpoint:/private/var/folders/71/4pnfjgwn0x3fcy4r3ddxw1fm0000gn/T/AppTranslocation/0EE2FB5D-6535-47AB-938B-DCB79CE11CE6`,
    35  	}
    36  
    37  	var pts []*Point
    38  	for i := 0; i < count; i++ {
    39  		if pt, err := NewPoint(cliutils.CreateRandomString(30),
    40  			map[string]string{ // 4 tags
    41  				cliutils.CreateRandomString(10): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
    42  				cliutils.CreateRandomString(11): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
    43  				cliutils.CreateRandomString(12): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
    44  				cliutils.CreateRandomString(13): sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
    45  			},
    46  
    47  			map[string]interface{}{
    48  				"message":                       sampleLogs[mrand.Int63()%int64(len(sampleLogs))],
    49  				cliutils.CreateRandomString(10): mrand.Int63(),
    50  				cliutils.CreateRandomString(10): mrand.Int63(),
    51  				cliutils.CreateRandomString(10): mrand.Int63(),
    52  				cliutils.CreateRandomString(10): mrand.Int63(),
    53  				cliutils.CreateRandomString(10): mrand.Int63(),
    54  				cliutils.CreateRandomString(10): mrand.Int63(),
    55  				cliutils.CreateRandomString(10): mrand.Int63(),
    56  				cliutils.CreateRandomString(10): mrand.Int63(),
    57  				cliutils.CreateRandomString(10): mrand.Int63(),
    58  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    59  				cliutils.CreateRandomString(10): false,
    60  				cliutils.CreateRandomString(10): true,
    61  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    62  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    63  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    64  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    65  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    66  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    67  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    68  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    69  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    70  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    71  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    72  				cliutils.CreateRandomString(10): mrand.NormFloat64(),
    73  			}); err != nil {
    74  			return nil, err
    75  		} else {
    76  			pts = append(pts, pt)
    77  		}
    78  	}
    79  
    80  	return pts, nil
    81  }
    82  
    83  // RandPoints deprecated.
    84  func RandPoints(count int) []*Point {
    85  	if pts, err := doRandomPoints(count); err != nil {
    86  		panic(fmt.Sprintf("doRandomPoints failed: %s", err))
    87  	} else {
    88  		return pts
    89  	}
    90  }
    91  
    92  // doRandomPBPoints deprecated.
    93  func doRandomPBPoints(count int) (*PBPoints, error) {
    94  	if count <= 0 {
    95  		return nil, nil
    96  	}
    97  
    98  	pts := &PBPoints{}
    99  
   100  	for i := 0; i < count; i++ {
   101  		pts.Arr = append(pts.Arr, &PBPoint{
   102  			Name: cliutils.CreateRandomString(30),
   103  			Fields: []*Field{
   104  				{IsTag: true, Key: cliutils.CreateRandomString(10), Val: &Field_S{cliutils.CreateRandomString(37)}},
   105  				{IsTag: true, Key: cliutils.CreateRandomString(11), Val: &Field_S{cliutils.CreateRandomString(38)}},
   106  				{IsTag: true, Key: cliutils.CreateRandomString(12), Val: &Field_S{cliutils.CreateRandomString(39)}},
   107  				{IsTag: true, Key: cliutils.CreateRandomString(13), Val: &Field_S{cliutils.CreateRandomString(40)}},
   108  
   109  				{Key: cliutils.CreateRandomString(9), Val: &Field_S{cliutils.CreateRandomString(37)}},
   110  				{Key: cliutils.CreateRandomString(10), Val: &Field_D{[]byte(cliutils.CreateRandomString(37))}},
   111  				{Key: cliutils.CreateRandomString(11), Val: &Field_I{mrand.Int63()}},
   112  				{Key: cliutils.CreateRandomString(12), Val: &Field_F{mrand.NormFloat64()}},
   113  				{Key: cliutils.CreateRandomString(13), Val: &Field_B{false}},
   114  				{Key: cliutils.CreateRandomString(14), Val: &Field_B{true}},
   115  			},
   116  			Time: time.Now().UnixNano(),
   117  		})
   118  	}
   119  
   120  	return pts, nil
   121  }
   122  
   123  // RandPBPoints deprecated.
   124  func RandPBPoints(count int) *PBPoints {
   125  	if pts, err := doRandomPBPoints(count); err != nil {
   126  		panic(fmt.Sprintf("doRandomPoints failed: %s", err))
   127  	} else {
   128  		return pts
   129  	}
   130  }