github.com/alibaba/ilogtail/pkg@v0.0.0-20250526110833-c53b480d046c/selfmonitor/metrics_imp_test.go (about)

     1  // Copyright 2021 iLogtail Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package selfmonitor
    16  
    17  import (
    18  	"github.com/alibaba/ilogtail/pkg/protocol"
    19  
    20  	"reflect"
    21  	"testing"
    22  	"time"
    23  )
    24  
    25  func TestStrMetric_Name(t *testing.T) {
    26  	type fields struct {
    27  		name   string
    28  		value  string
    29  		labels []*protocol.Log_Content
    30  	}
    31  	tests := []struct {
    32  		name   string
    33  		fields fields
    34  		want   string
    35  	}{
    36  		{
    37  			name: "test_name",
    38  			fields: fields{
    39  				name:  "field",
    40  				value: "v",
    41  			},
    42  			want: "field",
    43  		},
    44  		{
    45  			name: "test_name",
    46  			fields: fields{
    47  				name:  "field",
    48  				value: "v",
    49  				labels: []*protocol.Log_Content{
    50  					{
    51  						Key:   "key",
    52  						Value: "value",
    53  					},
    54  				},
    55  			},
    56  			want: "field#key=value",
    57  		},
    58  	}
    59  	for _, tt := range tests {
    60  		t.Run(tt.name, func(t *testing.T) {
    61  			s := &StrMetric{
    62  				name:   tt.fields.name,
    63  				value:  tt.fields.value,
    64  				labels: tt.fields.labels,
    65  			}
    66  			if got := s.Name(); got != tt.want {
    67  				t.Errorf("StrMetric.Name() = %v, want %v", got, tt.want)
    68  			}
    69  		})
    70  	}
    71  }
    72  
    73  func TestStrMetric_Set(t *testing.T) {
    74  	type fields struct {
    75  		name  string
    76  		value string
    77  	}
    78  	type args struct {
    79  		v string
    80  	}
    81  	tests := []struct {
    82  		name   string
    83  		fields fields
    84  		args   args
    85  	}{
    86  		{
    87  			name: "1",
    88  			fields: fields{
    89  				name:  "n",
    90  				value: "v",
    91  			},
    92  			args: args{
    93  				"x",
    94  			},
    95  		},
    96  	}
    97  	for _, tt := range tests {
    98  		t.Run(tt.name, func(t *testing.T) {
    99  			s := &StrMetric{
   100  				name:  tt.fields.name,
   101  				value: tt.fields.value,
   102  			}
   103  			s.Set(tt.args.v)
   104  			if s.Get() != tt.args.v {
   105  				t.Errorf("fail %s != %s\n", s.Get(), tt.args.v)
   106  			}
   107  		})
   108  	}
   109  }
   110  
   111  func TestStrMetric_Get(t *testing.T) {
   112  	type fields struct {
   113  		name  string
   114  		value string
   115  	}
   116  	tests := []struct {
   117  		name   string
   118  		fields fields
   119  		want   string
   120  	}{
   121  		// TODO: Add test cases.
   122  	}
   123  	for _, tt := range tests {
   124  		t.Run(tt.name, func(t *testing.T) {
   125  			s := &StrMetric{
   126  				name:  tt.fields.name,
   127  				value: tt.fields.value,
   128  			}
   129  			if got := s.Get(); got != tt.want {
   130  				t.Errorf("StrMetric.Get() = %v, want %v", got, tt.want)
   131  			}
   132  		})
   133  	}
   134  }
   135  
   136  func TestNormalMetric_Add(t *testing.T) {
   137  	type fields struct {
   138  		name  string
   139  		value int64
   140  	}
   141  	type args struct {
   142  		v int64
   143  	}
   144  	tests := []struct {
   145  		name   string
   146  		fields fields
   147  		args   args
   148  	}{
   149  		// TODO: Add test cases.
   150  	}
   151  	for _, tt := range tests {
   152  		t.Run(tt.name, func(t *testing.T) {
   153  			s := &NormalMetric{
   154  				name:  tt.fields.name,
   155  				value: tt.fields.value,
   156  			}
   157  			s.Add(tt.args.v)
   158  		})
   159  	}
   160  }
   161  
   162  func TestNormalMetric_Clear(t *testing.T) {
   163  	type fields struct {
   164  		name  string
   165  		value int64
   166  	}
   167  	type args struct {
   168  		v int64
   169  	}
   170  	tests := []struct {
   171  		name   string
   172  		fields fields
   173  		args   args
   174  	}{
   175  		// TODO: Add test cases.
   176  	}
   177  	for _, tt := range tests {
   178  		t.Run(tt.name, func(t *testing.T) {
   179  			s := &NormalMetric{
   180  				name:  tt.fields.name,
   181  				value: tt.fields.value,
   182  			}
   183  			s.Clear(tt.args.v)
   184  		})
   185  	}
   186  }
   187  
   188  func TestNormalMetric_Get(t *testing.T) {
   189  	type fields struct {
   190  		name  string
   191  		value int64
   192  	}
   193  	tests := []struct {
   194  		name   string
   195  		fields fields
   196  		want   int64
   197  	}{
   198  		// TODO: Add test cases.
   199  	}
   200  	for _, tt := range tests {
   201  		t.Run(tt.name, func(t *testing.T) {
   202  			s := &NormalMetric{
   203  				name:  tt.fields.name,
   204  				value: tt.fields.value,
   205  			}
   206  			if got := s.Get(); got != tt.want {
   207  				t.Errorf("NormalMetric.Get() = %v, want %v", got, tt.want)
   208  			}
   209  		})
   210  	}
   211  }
   212  
   213  func TestNormalMetric_Name(t *testing.T) {
   214  	type fields struct {
   215  		name  string
   216  		value int64
   217  	}
   218  	tests := []struct {
   219  		name   string
   220  		fields fields
   221  		want   string
   222  	}{
   223  		// TODO: Add test cases.
   224  	}
   225  	for _, tt := range tests {
   226  		t.Run(tt.name, func(t *testing.T) {
   227  			s := &NormalMetric{
   228  				name:  tt.fields.name,
   229  				value: tt.fields.value,
   230  			}
   231  			if got := s.Name(); got != tt.want {
   232  				t.Errorf("NormalMetric.Name() = %v, want %v", got, tt.want)
   233  			}
   234  		})
   235  	}
   236  }
   237  
   238  func TestAvgMetric_Add(t *testing.T) {
   239  	type fields struct {
   240  		name    string
   241  		value   int64
   242  		count   int64
   243  		prevAvg float64
   244  	}
   245  	type args struct {
   246  		v int64
   247  	}
   248  	tests := []struct {
   249  		name   string
   250  		fields fields
   251  		args   args
   252  	}{
   253  		// TODO: Add test cases.
   254  	}
   255  	for _, tt := range tests {
   256  		t.Run(tt.name, func(t *testing.T) {
   257  			s := &AvgMetric{
   258  				name:    tt.fields.name,
   259  				value:   tt.fields.value,
   260  				count:   tt.fields.count,
   261  				prevAvg: tt.fields.prevAvg,
   262  			}
   263  			s.Add(tt.args.v)
   264  		})
   265  	}
   266  }
   267  
   268  func TestAvgMetric_Clear(t *testing.T) {
   269  	type fields struct {
   270  		name    string
   271  		value   int64
   272  		count   int64
   273  		prevAvg float64
   274  	}
   275  	type args struct {
   276  		v int64
   277  	}
   278  	tests := []struct {
   279  		name   string
   280  		fields fields
   281  		args   args
   282  	}{
   283  		// TODO: Add test cases.
   284  	}
   285  	for _, tt := range tests {
   286  		t.Run(tt.name, func(t *testing.T) {
   287  			s := &AvgMetric{
   288  				name:    tt.fields.name,
   289  				value:   tt.fields.value,
   290  				count:   tt.fields.count,
   291  				prevAvg: tt.fields.prevAvg,
   292  			}
   293  			s.Clear(tt.args.v)
   294  		})
   295  	}
   296  }
   297  
   298  func TestAvgMetric_Get(t *testing.T) {
   299  	type fields struct {
   300  		name    string
   301  		value   int64
   302  		count   int64
   303  		prevAvg float64
   304  	}
   305  	tests := []struct {
   306  		name   string
   307  		fields fields
   308  		want   int64
   309  	}{
   310  		// TODO: Add test cases.
   311  	}
   312  	for _, tt := range tests {
   313  		t.Run(tt.name, func(t *testing.T) {
   314  			s := &AvgMetric{
   315  				name:    tt.fields.name,
   316  				value:   tt.fields.value,
   317  				count:   tt.fields.count,
   318  				prevAvg: tt.fields.prevAvg,
   319  			}
   320  			if got := s.Get(); got != tt.want {
   321  				t.Errorf("AvgMetric.Get() = %v, want %v", got, tt.want)
   322  			}
   323  		})
   324  	}
   325  }
   326  
   327  func TestAvgMetric_GetAvg(t *testing.T) {
   328  	type fields struct {
   329  		name    string
   330  		value   int64
   331  		count   int64
   332  		prevAvg float64
   333  	}
   334  	tests := []struct {
   335  		name   string
   336  		fields fields
   337  		want   float64
   338  	}{
   339  		// TODO: Add test cases.
   340  	}
   341  	for _, tt := range tests {
   342  		t.Run(tt.name, func(t *testing.T) {
   343  			s := &AvgMetric{
   344  				name:    tt.fields.name,
   345  				value:   tt.fields.value,
   346  				count:   tt.fields.count,
   347  				prevAvg: tt.fields.prevAvg,
   348  			}
   349  			if got := s.GetAvg(); got != tt.want {
   350  				t.Errorf("AvgMetric.GetAvg() = %v, want %v", got, tt.want)
   351  			}
   352  		})
   353  	}
   354  }
   355  
   356  func TestAvgMetric_Name(t *testing.T) {
   357  	type fields struct {
   358  		name    string
   359  		value   int64
   360  		count   int64
   361  		prevAvg float64
   362  	}
   363  	tests := []struct {
   364  		name   string
   365  		fields fields
   366  		want   string
   367  	}{
   368  		// TODO: Add test cases.
   369  	}
   370  	for _, tt := range tests {
   371  		t.Run(tt.name, func(t *testing.T) {
   372  			s := &AvgMetric{
   373  				name:    tt.fields.name,
   374  				value:   tt.fields.value,
   375  				count:   tt.fields.count,
   376  				prevAvg: tt.fields.prevAvg,
   377  			}
   378  			if got := s.Name(); got != tt.want {
   379  				t.Errorf("AvgMetric.Name() = %v, want %v", got, tt.want)
   380  			}
   381  		})
   382  	}
   383  }
   384  
   385  func TestLatMetric_Name(t *testing.T) {
   386  	type fields struct {
   387  		name       string
   388  		t          time.Time
   389  		count      int
   390  		latencySum time.Duration
   391  	}
   392  	tests := []struct {
   393  		name   string
   394  		fields fields
   395  		want   string
   396  	}{
   397  		// TODO: Add test cases.
   398  	}
   399  	for _, tt := range tests {
   400  		t.Run(tt.name, func(t *testing.T) {
   401  			s := &LatMetric{
   402  				name:       tt.fields.name,
   403  				t:          tt.fields.t,
   404  				count:      tt.fields.count,
   405  				latencySum: tt.fields.latencySum,
   406  			}
   407  			if got := s.Name(); got != tt.want {
   408  				t.Errorf("LatMetric.Name() = %v, want %v", got, tt.want)
   409  			}
   410  		})
   411  	}
   412  }
   413  
   414  func TestLatMetric_Begin(t *testing.T) {
   415  	type fields struct {
   416  		name       string
   417  		t          time.Time
   418  		count      int
   419  		latencySum time.Duration
   420  	}
   421  	tests := []struct {
   422  		name   string
   423  		fields fields
   424  	}{
   425  		// TODO: Add test cases.
   426  	}
   427  	for _, tt := range tests {
   428  		t.Run(tt.name, func(t *testing.T) {
   429  			s := &LatMetric{
   430  				name:       tt.fields.name,
   431  				t:          tt.fields.t,
   432  				count:      tt.fields.count,
   433  				latencySum: tt.fields.latencySum,
   434  			}
   435  			s.Begin()
   436  		})
   437  	}
   438  }
   439  
   440  func TestLatMetric_End(t *testing.T) {
   441  	type fields struct {
   442  		name       string
   443  		t          time.Time
   444  		count      int
   445  		latencySum time.Duration
   446  	}
   447  	tests := []struct {
   448  		name   string
   449  		fields fields
   450  	}{
   451  		// TODO: Add test cases.
   452  	}
   453  	for _, tt := range tests {
   454  		t.Run(tt.name, func(t *testing.T) {
   455  			s := &LatMetric{
   456  				name:       tt.fields.name,
   457  				t:          tt.fields.t,
   458  				count:      tt.fields.count,
   459  				latencySum: tt.fields.latencySum,
   460  			}
   461  			s.End()
   462  		})
   463  	}
   464  }
   465  
   466  func TestLatMetric_Clear(t *testing.T) {
   467  	type fields struct {
   468  		name       string
   469  		t          time.Time
   470  		count      int
   471  		latencySum time.Duration
   472  	}
   473  	tests := []struct {
   474  		name   string
   475  		fields fields
   476  	}{
   477  		// TODO: Add test cases.
   478  	}
   479  	for _, tt := range tests {
   480  		t.Run(tt.name, func(t *testing.T) {
   481  			s := &LatMetric{
   482  				name:       tt.fields.name,
   483  				t:          tt.fields.t,
   484  				count:      tt.fields.count,
   485  				latencySum: tt.fields.latencySum,
   486  			}
   487  			s.Clear()
   488  		})
   489  	}
   490  }
   491  
   492  func TestLatMetric_Get(t *testing.T) {
   493  	type fields struct {
   494  		name       string
   495  		t          time.Time
   496  		count      int
   497  		latencySum time.Duration
   498  	}
   499  	tests := []struct {
   500  		name   string
   501  		fields fields
   502  		want   int64
   503  	}{
   504  		// TODO: Add test cases.
   505  	}
   506  	for _, tt := range tests {
   507  		t.Run(tt.name, func(t *testing.T) {
   508  			s := &LatMetric{
   509  				name:       tt.fields.name,
   510  				t:          tt.fields.t,
   511  				count:      tt.fields.count,
   512  				latencySum: tt.fields.latencySum,
   513  			}
   514  			if got := s.Get(); got != tt.want {
   515  				t.Errorf("LatMetric.Get() = %v, want %v", got, tt.want)
   516  			}
   517  		})
   518  	}
   519  }
   520  
   521  func TestNewCounterMetric(t *testing.T) {
   522  	type args struct {
   523  		n string
   524  	}
   525  	tests := []struct {
   526  		name string
   527  		args args
   528  		want CounterMetric
   529  	}{
   530  		// TODO: Add test cases.
   531  	}
   532  	for _, tt := range tests {
   533  		t.Run(tt.name, func(t *testing.T) {
   534  			if got := NewCumulativeCounterMetric(tt.args.n); !reflect.DeepEqual(got, tt.want) {
   535  				t.Errorf("NewCounterMetric() = %v, want %v", got, tt.want)
   536  			}
   537  		})
   538  	}
   539  }
   540  
   541  func TestNewAverageMetric(t *testing.T) {
   542  	type args struct {
   543  		n string
   544  	}
   545  	tests := []struct {
   546  		name string
   547  		args args
   548  		want CounterMetric
   549  	}{
   550  		// TODO: Add test cases.
   551  	}
   552  	for _, tt := range tests {
   553  		t.Run(tt.name, func(t *testing.T) {
   554  			if got := NewAverageMetric(tt.args.n); !reflect.DeepEqual(got, tt.want) {
   555  				t.Errorf("NewAverageMetric() = %v, want %v", got, tt.want)
   556  			}
   557  		})
   558  	}
   559  }
   560  
   561  func TestNewStringMetric(t *testing.T) {
   562  	type args struct {
   563  		n string
   564  	}
   565  	tests := []struct {
   566  		name string
   567  		args args
   568  		want StringMetric
   569  	}{
   570  		// TODO: Add test cases.
   571  	}
   572  	for _, tt := range tests {
   573  		t.Run(tt.name, func(t *testing.T) {
   574  			if got := NewStringMetric(tt.args.n); !reflect.DeepEqual(got, tt.want) {
   575  				t.Errorf("NewStringMetric() = %v, want %v", got, tt.want)
   576  			}
   577  		})
   578  	}
   579  }
   580  
   581  func TestNewLatencyMetric(t *testing.T) {
   582  	type args struct {
   583  		n string
   584  	}
   585  	tests := []struct {
   586  		name string
   587  		args args
   588  		want LatencyMetric
   589  	}{
   590  		// TODO: Add test cases.
   591  	}
   592  	for _, tt := range tests {
   593  		t.Run(tt.name, func(t *testing.T) {
   594  			if got := NewLatencyMetric(tt.args.n); !reflect.DeepEqual(got, tt.want) {
   595  				t.Errorf("NewLatencyMetric() = %v, want %v", got, tt.want)
   596  			}
   597  		})
   598  	}
   599  }