You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/07/13 19:12:25 UTC

[GitHub] [trafficcontrol] jpappa200 opened a new pull request, #6960: add t3c-tail sub-app

jpappa200 opened a new pull request, #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960

   <!--
   Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
   If this closes or relates to an existing issue, please reference it using one of the following:
   
   Closes: #ISSUE
   Related: #ISSUE
   
   If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
   the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://apache.org/security regarding vulnerability disclosure.
   -->
   
   Adds the sub-app t3c-tail which can be used to tail a file, usually a log file. Reads json input from stdin. will mainly be used by t3c-apply to watch diags.log after trafficserver restart or reload. it can be useful to see what happened in diags.log without having to tail the file in a separate window. this will also be logged with the t3c log output.
   
   <!-- **^ Add meaningful description above** --><hr/>
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this PR.
   Feel free to add the name of a tool or script that is affected but not on the list.
   -->
   
   - Traffic Control Cache Config (`t3c`, formerly ORT)
    <!-- Please specify which (GitHub Actions, Docker images, Ansible Roles, etc.) -->
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your PR.
   If your PR has tests (and most should), provide the steps needed to run the tests.
   If not, please provide step-by-step instructions to test the PR manually and explain why your PR does not need tests. -->
   Build Traffic Control Cache Config and install. run t3c-apply in syncds or badass mode. verify that after reload/restart diags logs messages are displayed. 
   
   ## If this is a bugfix, which Traffic Control versions contained the bug?
   <!-- Delete this section if the PR is not a bugfix, or if the bug is only in the master branch.
   Examples:
   - 5.1.2
   - 5.1.3 (RC1)
    -->
   
   
   ## PR submission checklist
   - [ ] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
   - [x] This PR has documentation <!-- If not, please delete this text and explain why this PR does not need documentation. -->
   - [x] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] jpappa200 commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
jpappa200 commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r927964812


##########
cache-config/t3c-tail/t3c-tail.go:
##########
@@ -0,0 +1,131 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"fmt"
+	"os"
+	"regexp"
+	"time"
+
+	"github.com/apache/trafficcontrol/cache-config/t3cutil"
+	"github.com/apache/trafficcontrol/lib/go-log"
+
+	"github.com/nxadm/tail"
+	"github.com/pborman/getopt/v2"
+)
+
+const AppName = "t3c-tail"
+
+// Version is the application version.
+// This is overwritten by the build with the current project version.
+var Version = "0.4"
+
+// GitRevision is the git revision the application was built from.
+// This is overwritten by the build with the current project version.
+var GitRevision = "nogit"
+
+//default time out is 15 seconds, if not included in json input.
+var timeOutSeconds = 15

Review Comment:
   this has been renamed to `defaultTimeOutMs` and the comment has been fixed too. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] jpappa200 commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
jpappa200 commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r927958468


##########
CHANGELOG.md:
##########
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added layered profile feature to 4.0 for `GET` /deliveryservices/{id}/servers/ and /deliveryservices/{id}/servers/eligible.
 - Change to t3c regex_revalidate so that STALE is no longer explicitly added for default revalidate rule for ATS version backwards compatibility.
 - Change to t3c diff to flag a config file for replacement if owner/group settings are not `ats` [#6879](https://github.com/apache/trafficcontrol/issues/6879).
+- Added a sub-app t3c-tail to tail diags.log and caputre output when t3c reloads and restarts trafficserver  

Review Comment:
   fixed type



##########
CHANGELOG.md:
##########
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added layered profile feature to 4.0 for `GET` /deliveryservices/{id}/servers/ and /deliveryservices/{id}/servers/eligible.
 - Change to t3c regex_revalidate so that STALE is no longer explicitly added for default revalidate rule for ATS version backwards compatibility.
 - Change to t3c diff to flag a config file for replacement if owner/group settings are not `ats` [#6879](https://github.com/apache/trafficcontrol/issues/6879).
+- Added a sub-app t3c-tail to tail diags.log and caputre output when t3c reloads and restarts trafficserver  

Review Comment:
   fixed typo



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] rob05c merged pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
rob05c merged PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] jpappa200 commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
jpappa200 commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r927963524


##########
cache-config/t3c-tail/t3c-tail.go:
##########
@@ -0,0 +1,131 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"fmt"
+	"os"
+	"regexp"
+	"time"
+
+	"github.com/apache/trafficcontrol/cache-config/t3cutil"
+	"github.com/apache/trafficcontrol/lib/go-log"
+
+	"github.com/nxadm/tail"
+	"github.com/pborman/getopt/v2"
+)
+
+const AppName = "t3c-tail"
+
+// Version is the application version.
+// This is overwritten by the build with the current project version.
+var Version = "0.4"
+
+// GitRevision is the git revision the application was built from.
+// This is overwritten by the build with the current project version.
+var GitRevision = "nogit"
+
+//default time out is 15 seconds, if not included in json input.
+var timeOutSeconds = 15
+
+func main() {
+	version := getopt.BoolLong("version", 'V', "Print version information and exit.")
+	help := getopt.BoolLong("help", 'h', "Print usage information and exit")
+	getopt.Parse()
+
+	log.Init(os.Stderr, os.Stderr, os.Stderr, os.Stderr, os.Stderr)
+
+	if *help {
+		fmt.Println(usageStr())
+		os.Exit(0)
+	} else if *version {
+		fmt.Println(t3cutil.VersionStr(AppName, Version, GitRevision))
+		os.Exit(0)
+	}
+
+	tailCfg := &t3cutil.TailCfg{}
+	if err := json.NewDecoder(os.Stdin).Decode(tailCfg); err != nil {

Review Comment:
   Changed these to flags. I was on the fence about flags vs stdin, and almost changed it before opening the PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] rob05c commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
rob05c commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r923611437


##########
cache-config/t3c-tail/t3c-tail.go:
##########
@@ -0,0 +1,131 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"fmt"
+	"os"
+	"regexp"
+	"time"
+
+	"github.com/apache/trafficcontrol/cache-config/t3cutil"
+	"github.com/apache/trafficcontrol/lib/go-log"
+
+	"github.com/nxadm/tail"
+	"github.com/pborman/getopt/v2"
+)
+
+const AppName = "t3c-tail"
+
+// Version is the application version.
+// This is overwritten by the build with the current project version.
+var Version = "0.4"
+
+// GitRevision is the git revision the application was built from.
+// This is overwritten by the build with the current project version.
+var GitRevision = "nogit"
+
+//default time out is 15 seconds, if not included in json input.
+var timeOutSeconds = 15
+
+func main() {
+	version := getopt.BoolLong("version", 'V', "Print version information and exit.")
+	help := getopt.BoolLong("help", 'h', "Print usage information and exit")
+	getopt.Parse()
+
+	log.Init(os.Stderr, os.Stderr, os.Stderr, os.Stderr, os.Stderr)
+
+	if *help {
+		fmt.Println(usageStr())
+		os.Exit(0)
+	} else if *version {
+		fmt.Println(t3cutil.VersionStr(AppName, Version, GitRevision))
+		os.Exit(0)
+	}
+
+	tailCfg := &t3cutil.TailCfg{}
+	if err := json.NewDecoder(os.Stdin).Decode(tailCfg); err != nil {

Review Comment:
   Would you object to making these settings (`file`, `match`, `end-match`, `timeout`) flags instead of `stdin`? 
   I think flags are more common and expected for Linux/POSIX apps, when they're static values not at risk of being arbitrarily long and overflowing Linux command buffers.



##########
cache-config/t3c-tail/t3c-tail.go:
##########
@@ -0,0 +1,131 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"fmt"
+	"os"
+	"regexp"
+	"time"
+
+	"github.com/apache/trafficcontrol/cache-config/t3cutil"
+	"github.com/apache/trafficcontrol/lib/go-log"
+
+	"github.com/nxadm/tail"
+	"github.com/pborman/getopt/v2"
+)
+
+const AppName = "t3c-tail"
+
+// Version is the application version.
+// This is overwritten by the build with the current project version.
+var Version = "0.4"
+
+// GitRevision is the git revision the application was built from.
+// This is overwritten by the build with the current project version.
+var GitRevision = "nogit"
+
+//default time out is 15 seconds, if not included in json input.
+var timeOutSeconds = 15
+
+func main() {
+	version := getopt.BoolLong("version", 'V', "Print version information and exit.")
+	help := getopt.BoolLong("help", 'h', "Print usage information and exit")
+	getopt.Parse()
+
+	log.Init(os.Stderr, os.Stderr, os.Stderr, os.Stderr, os.Stderr)
+
+	if *help {
+		fmt.Println(usageStr())
+		os.Exit(0)
+	} else if *version {
+		fmt.Println(t3cutil.VersionStr(AppName, Version, GitRevision))
+		os.Exit(0)
+	}
+
+	tailCfg := &t3cutil.TailCfg{}
+	if err := json.NewDecoder(os.Stdin).Decode(tailCfg); err != nil {

Review Comment:
   Also, mind making the timeout in milliseconds, e.g. `--timeout-ms`? Users might want sub-second timeouts



##########
CHANGELOG.md:
##########
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - Added layered profile feature to 4.0 for `GET` /deliveryservices/{id}/servers/ and /deliveryservices/{id}/servers/eligible.
 - Change to t3c regex_revalidate so that STALE is no longer explicitly added for default revalidate rule for ATS version backwards compatibility.
 - Change to t3c diff to flag a config file for replacement if owner/group settings are not `ats` [#6879](https://github.com/apache/trafficcontrol/issues/6879).
+- Added a sub-app t3c-tail to tail diags.log and caputre output when t3c reloads and restarts trafficserver  

Review Comment:
   Typo, `caputre`



##########
cache-config/t3c-apply/torequest/cmd.go:
##########
@@ -274,6 +275,36 @@ func sendUpdate(cfg config.Cfg, configApplyTime, revalApplyTime *time.Time, conf
 	return nil
 }
 
+//doTail calls t3c-tail and will run a tail on the log file provided with string for a regex to
+//maatch on default is .* endMatch will make t3c-tail exit when a pattern is matched otherwise
+//a timeout in a given number of seconds will occur.
+func doTail(cfg config.Cfg, file string, logMatch string, endMatch string, timeoutSeconds int) error {
+	tailData := t3cutil.TailCfg{
+		File:     &file,
+		LogMatch: &logMatch,
+		EndMatch: &endMatch,
+		TimeOut:  &timeoutSeconds,
+	}
+	tailInput, err := json.Marshal(&tailData)
+	if err != nil {
+		return fmt.Errorf("error loading json input")
+	}
+	stdOut, stdErr, code := t3cutil.DoInput(tailInput, `t3c-tail`, "")
+	if code > 1 {
+		return fmt.Errorf("t3c-tail returned error code %v stdout '%v' stderr '%v'", code, string(stdOut), string(stdErr))
+	}
+	logSubApp(`t3c-tail`, stdErr)
+
+	stripDate := regexp.MustCompile(`\[\w{3}\s{1,2}\d{1,2}\s\d{2}:\d{2}:\d{2}\.\d{3}\]\s`)

Review Comment:
   Would you object to moving this to a variable outside the function? `MustCompile` will cause the app to panic and crash if it fails. It _shouldn't_ ever fail, but moving it as a `var` outside the func will make it crash as soon as the application starts, instead of in the middle of a run, which should be easier to debug.



##########
cache-config/t3c-apply/torequest/torequest.go:
##########
@@ -47,6 +47,15 @@ const (
 	UpdateTropsFailed     UpdateStatus = 3
 )
 
+const (
+	TailDiagsLog       = "/opt/trafficserver/var/log/trafficserver/diags.log"

Review Comment:
   Not everyone installs to `/opt`. `t3c-apply/config` will attempt to find the install dir, and put it in `Cfg.TsHome`. Can this be changed to the relative `var/log/trafficserver/diags.log` and the things that use it changed to `filepath.Join(cfg.TsHome, TailDiagsLogRelative)`?



##########
cache-config/t3c-tail/t3c-tail.go:
##########
@@ -0,0 +1,131 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"fmt"
+	"os"
+	"regexp"
+	"time"
+
+	"github.com/apache/trafficcontrol/cache-config/t3cutil"
+	"github.com/apache/trafficcontrol/lib/go-log"
+
+	"github.com/nxadm/tail"
+	"github.com/pborman/getopt/v2"
+)
+
+const AppName = "t3c-tail"
+
+// Version is the application version.
+// This is overwritten by the build with the current project version.
+var Version = "0.4"
+
+// GitRevision is the git revision the application was built from.
+// This is overwritten by the build with the current project version.
+var GitRevision = "nogit"
+
+//default time out is 15 seconds, if not included in json input.
+var timeOutSeconds = 15

Review Comment:
   Mind renaming this `defaultTimeoutSeconds`, just so it's clear it's a default, not always the timeout?
   
   Also, the comment needs to start with the variable name for GoDoc, e.g. ` // defaultTimeoutSeconds time out is 15 seconds, if not included in json input.
   
   (Technically unexported symbols aren't used by GoDoc, but we try to keep unexported symbols GoDoc-compliant for ease of reading, and so they're automatically compliant if they're changed to be exported in the future.)



##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -43,6 +43,13 @@ type ATSConfigFile struct {
 	Warnings    []string `json:"warnings"`
 }
 
+type TailCfg struct {
+	File     *string `json:"file"`
+	LogMatch *string `json:"logMatch"`
+	EndMatch *string `json:"endMatch"`
+	TimeOut  *int    `json:"timeOut"`

Review Comment:
   Mind adding the units to the name here, just so it's easier for readers to see? E.g. `TimeoutSeconds` or `TimeoutMS`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] jpappa200 commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
jpappa200 commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r927962614


##########
cache-config/t3c-apply/torequest/torequest.go:
##########
@@ -47,6 +47,15 @@ const (
 	UpdateTropsFailed     UpdateStatus = 3
 )
 
+const (
+	TailDiagsLog       = "/opt/trafficserver/var/log/trafficserver/diags.log"

Review Comment:
   changed to `/var/log/trafficserver/diags.log` and `func doTail` adds `cfg.TsHome`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] rob05c commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
rob05c commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r923633223


##########
cache-config/t3c-tail/t3c-tail.go:
##########
@@ -0,0 +1,131 @@
+package main
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import (
+	"encoding/json"
+	"fmt"
+	"os"
+	"regexp"
+	"time"
+
+	"github.com/apache/trafficcontrol/cache-config/t3cutil"
+	"github.com/apache/trafficcontrol/lib/go-log"
+
+	"github.com/nxadm/tail"
+	"github.com/pborman/getopt/v2"
+)
+
+const AppName = "t3c-tail"
+
+// Version is the application version.
+// This is overwritten by the build with the current project version.
+var Version = "0.4"
+
+// GitRevision is the git revision the application was built from.
+// This is overwritten by the build with the current project version.
+var GitRevision = "nogit"
+
+//default time out is 15 seconds, if not included in json input.
+var timeOutSeconds = 15

Review Comment:
   Mind renaming this `defaultTimeoutSeconds`, just so it's clear it's a default, not always the timeout?
   
   Also, the comment needs to start with the variable name for GoDoc, e.g. `// defaultTimeoutSeconds time out is 15 seconds, if not included in json input.`
   
   (Technically unexported symbols aren't used by GoDoc, but we try to keep unexported symbols GoDoc-compliant for ease of reading, and so they're automatically compliant if they're changed to be exported in the future.)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] jpappa200 commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
jpappa200 commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r927960316


##########
cache-config/t3c-apply/torequest/cmd.go:
##########
@@ -274,6 +275,36 @@ func sendUpdate(cfg config.Cfg, configApplyTime, revalApplyTime *time.Time, conf
 	return nil
 }
 
+//doTail calls t3c-tail and will run a tail on the log file provided with string for a regex to
+//maatch on default is .* endMatch will make t3c-tail exit when a pattern is matched otherwise
+//a timeout in a given number of seconds will occur.
+func doTail(cfg config.Cfg, file string, logMatch string, endMatch string, timeoutSeconds int) error {
+	tailData := t3cutil.TailCfg{
+		File:     &file,
+		LogMatch: &logMatch,
+		EndMatch: &endMatch,
+		TimeOut:  &timeoutSeconds,
+	}
+	tailInput, err := json.Marshal(&tailData)
+	if err != nil {
+		return fmt.Errorf("error loading json input")
+	}
+	stdOut, stdErr, code := t3cutil.DoInput(tailInput, `t3c-tail`, "")
+	if code > 1 {
+		return fmt.Errorf("t3c-tail returned error code %v stdout '%v' stderr '%v'", code, string(stdOut), string(stdErr))
+	}
+	logSubApp(`t3c-tail`, stdErr)
+
+	stripDate := regexp.MustCompile(`\[\w{3}\s{1,2}\d{1,2}\s\d{2}:\d{2}:\d{2}\.\d{3}\]\s`)

Review Comment:
   Moved outside of func



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] jpappa200 commented on a diff in pull request #6960: add t3c-tail sub-app

Posted by GitBox <gi...@apache.org>.
jpappa200 commented on code in PR #6960:
URL: https://github.com/apache/trafficcontrol/pull/6960#discussion_r927964105


##########
cache-config/t3cutil/t3cutil.go:
##########
@@ -43,6 +43,13 @@ type ATSConfigFile struct {
 	Warnings    []string `json:"warnings"`
 }
 
+type TailCfg struct {
+	File     *string `json:"file"`
+	LogMatch *string `json:"logMatch"`
+	EndMatch *string `json:"endMatch"`
+	TimeOut  *int    `json:"timeOut"`

Review Comment:
   This structure is no longer needed/used since I'm not using stdin. it has been removed. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org