github.com/verrazzano/verrazzano@v1.7.1/application-operator/controllers/wlsworkload/weblogic_logging_test.go (about)

     1  // Copyright (c) 2021, 2022, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package wlsworkload
     5  
     6  import (
     7  	"regexp"
     8  	"strings"
     9  	"testing"
    10  
    11  	asserts "github.com/stretchr/testify/assert"
    12  )
    13  
    14  const log1 = `####<Nov 17, 2021 10:36:24,316 PM GMT> <Info> <Security> <bobs-bookstore-managed-server1> <> <main> <> <> <> <1637188584316> <[severity-value: 64] [partition-id: 0] [partition-name: DOMAIN] > <BEA-090905> <Disabling the CryptoJ JCE Provider self-integrity check for better startup performance. To enable this check, specify -Dweblogic.security.allowCryptoJDefaultJCEVerification=true.> 
    15  `
    16  const log2 = `####<Nov 17, 2021 5:55:46,955 PM GMT> <Trace> <com.oracle.logging.SystemLogger> <tododomain-adminserver> <AdminServer> <[ACTIVE] ExecuteThread: '9' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <cd1631dc-0279-48fc-bb29-85462f5ea85c-00000013> <1637171746955> <[severity-value: 256] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-000000> <[com.oracle.cie.wls.config.online.Util:log] CIE Config Helper: registering MBean >>
    17  ####<Nov 17, 2021 5:55:46,955 PM GMT> <Trace> <com.oracle.logging.SystemLogger> <tododomain-adminserver> <AdminServer> <[ACTIVE] ExecuteThread: '9' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <cd1631dc-0279-48fc-bb29-85462f5ea85c-00000013> <1637171746955> <[severity-value: 256] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-000000> <[com.oracle.cie.wls.config.online.Util:log] CIE Config Helper: isRegistered MBean: true> `
    18  
    19  const log3 = `####<Nov 17, 2021 10:36:32,616 PM GMT> <Info> <RJVM> <bobs-bookstore-managed-server1> <> <Thread-11> <> <> <> <1637188592616> <[severity-value: 64] [partition-id: 0] [partition-name: DOMAIN] > <BEA-000570> <Network Configuration for Channel "managed-server1"
    20   Listen Address		 bobs-bookstore-managed-server1:8001
    21   Public Address		 N/A
    22   Http Enabled		 true
    23   Tunneling Enabled	 false
    24   Outbound Enabled	 false
    25   Admin Traffic Enabled	 true ResolveDNSName Enabled	 false>
    26  `
    27  const log4 = `####<Nov 17, 2021 10:37:35,553 PM GMT> <Info> <JDBC> <bobs-bookstore-managed-server1> <managed-server1> <[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'> <<anonymous>> <> <c10cf642-4fbe-4753-9b2c-3c99b96df564-00000013> <1637188655553> <[severity-value: 64] [rid: 0] [partition-id: 0] [partition-name: DOMAIN] > <BEA-001156> <Stack trace associated with message 001129 follows: 
    28  
    29  com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
    30  
    31  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    32  	at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
    33  	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
    34  	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
    35  	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
    36  	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
    37  	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    38  	at weblogic.jdbc.common.internal.ConnectionEnvFactory.makeConnection0(ConnectionEnvFactory.java:321)
    39  	at weblogic.jdbc.common.internal.ConnectionEnvFactory.access$000(ConnectionEnvFactory.java:20)
    40  	at weblogic.jdbc.common.internal.ConnectionEnvFactory$1.run(ConnectionEnvFactory.java:219)
    41  	at java.security.AccessController.doPrivileged(Native Method)
    42  	at weblogic.jdbc.common.internal.ConnectionEnvFactory.makeConnection(ConnectionEnvFactory.java:216)
    43  	at weblogic.jdbc.common.internal.ConnectionEnvFactory.setConnection(ConnectionEnvFactory.java:143)
    44  	at weblogic.jdbc.common.internal.JDBCResourceFactoryImpl.createResource(JDBCResourceFactoryImpl.java:205)
    45  	at weblogic.common.resourcepool.ResourcePoolImpl.makeResource(ResourcePoolImpl.java:1561)
    46  	... 
    47  	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
    48  	at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)
    49  Caused By: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
    50  
    51  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    52  	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    53  	...
    54  	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
    55  	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
    56  	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
    57  	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    58  	...
    59  	at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)
    60  Caused By: java.net.UnknownHostException: mysql.wrong.svc.cluster.local: Temporary failure in name resolution
    61  	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
    62  	...
    63  	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
    64  	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
    65  	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
    66  	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    67      ...
    68  	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
    69  	at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)
    70  > 
    71  `
    72  
    73  // readFormat reads format1 ~ format13 in WlsFluentdParsingRules and combines format1 ~ format13 into one line
    74  // - change ?< to ?P< to capture groups
    75  // - use (?s) for new-line
    76  func readFormat() string {
    77  	format := false
    78  	pattern := ""
    79  	for _, line := range strings.Split(WlsFluentdParsingRules, "\n") {
    80  		if strings.Contains(line, "format1 /") || format {
    81  			format = true
    82  			s := line[strings.Index(line, "/")+1 : strings.LastIndex(line, "/")]
    83  			pattern = pattern + strings.ReplaceAll(s, "?<", "?P<")
    84  			if strings.Contains(line, "format13 /") {
    85  				return pattern + "(?s)"
    86  			}
    87  		}
    88  	}
    89  	return pattern
    90  }
    91  
    92  func Test_parseFormat(t *testing.T) {
    93  	tests := []struct {
    94  		name             string
    95  		text             string
    96  		expectedMessage  string //expected text in the last line of the message
    97  		expectedSeverity string //expected severity as severity-value attribute of the message
    98  	}{
    99  		{"log1", log1, "-Dweblogic.security.allowCryptoJDefaultJCEVerification=true.", "64"},
   100  		{"log2", log2, "registering MBean >", "256"},
   101  		{"log3", log3, "Admin Traffic Enabled\t true ResolveDNSName Enabled\t false", "64"},
   102  		{"log4", log4, "java.net.UnknownHostException: mysql.wrong.svc.cluster.local", "64"},
   103  	}
   104  	assert := asserts.New(t)
   105  	for _, tt := range tests {
   106  		t.Run(tt.name, func(t *testing.T) {
   107  			reg := regexp.MustCompile(readFormat())
   108  			matches := reg.FindStringSubmatch(tt.text)
   109  			//Total number of matches should be 27 = 1 + 13*2
   110  			assert.Equal(27, len(matches))
   111  			//The last match should be the message
   112  			assert.Contains(matches[26], tt.expectedMessage)
   113  			//The 22nd match should be the severity value
   114  			assert.Contains(matches[22], tt.expectedSeverity)
   115  		})
   116  	}
   117  }