You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by "AbdelrahmanElawady (via GitHub)" <gi...@apache.org> on 2023/07/21 18:30:40 UTC
[GitHub] [trafficcontrol] AbdelrahmanElawady opened a new pull request, #7669: Add parents to varnish cache
AbdelrahmanElawady opened a new pull request, #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669
<!--
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.
-->
Add the least required changes to run Varnish in a topology with parents by reusing some implementation already made in `go-atscfg` and add Dockerfile for Varnish to be testable in CIAB.
<!-- **^ 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)
- CDN in a Box
## 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. -->
Using CIAB:
- change the dockerfile path to point to varnish dir in either edge or mid.
- change the status to ONLINE in the cache server you choose overriding Traffic Monitor reports. for edge it will be [here](https://github.com/apache/trafficcontrol/blob/master/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh#L217).
- start docker-compose and curl the CDN domain from enroller container.
- check varnish container logs to verify it properly handled the request.
- try again and it should be a hit returning cached object.
Note: it has some issues with mid-02 as the initial data from Traffic Ops does not show any parents or origins. So, ATS `remap.config` and `parent.config` is initially empty unlike edge and mid-01. but, since t3c is running periodically it gets fixed once the data is correct. In Varnish case since t3c-apply is not integrated with Varnish only initial data is used and it is not changed. So, it is not working as mid-02 only mid-01. you can avoid that by adding `sleep` before running t3c-generate to ensure right data exists.
## PR submission checklist
- [x] 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. -->
- [ ] 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] AbdelrahmanElawady commented on a diff in pull request #7669: Add parents to varnish cache
Posted by "AbdelrahmanElawady (via GitHub)" <gi...@apache.org>.
AbdelrahmanElawady commented on code in PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#discussion_r1282906079
##########
infrastructure/cdn-in-a-box/enroller/Dockerfile:
##########
@@ -42,6 +42,9 @@ COPY ./traffic_ops/toclientlib/ /go/src/github.com/apache/trafficcontrol/traffic
COPY ./traffic_ops/v4-client/ /go/src/github.com/apache/trafficcontrol/traffic_ops/v4-client/
COPY ./infrastructure/cdn-in-a-box/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/
+# varnishcfg requires t3c for ToData struct and not needed for enroller
+RUN rm -rf /go/src/github.com/apache/trafficcontrol/lib/varnishcfg
+
Review Comment:
Maybe the comment can be improved, but it is not removed for optimization reasons. if we remove this line it won't be able to build the enroller binary because `varnishcfg` requires `t3c-util` package for the `ConfigData` struct [here](https://github.com/AbdelrahmanElawady/trafficcontrol/blob/add-parents-varnish/lib/varnishcfg/vclbuilder.go#L32). So, we will need to copy `t3c` packages too. `t3c` also requires some other packages not included with the enroller, so also they will need to be copied. The problem will be in keeping track of all these packages and what they require and any changes in the future. So I Just remove it instead of managing all that when it is not needed. But I believe it might be better to make `varnishcfg` not depend on `t3c-util`
--
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] ocket8888 merged pull request #7669: Add parents to varnish cache
Posted by "ocket8888 (via GitHub)" <gi...@apache.org>.
ocket8888 merged PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669
--
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] codecov[bot] commented on pull request #7669: Add parents to varnish cache
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#issuecomment-1646101075
## [Codecov](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
> Merging [#7669](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (fa77f07) into [master](https://app.codecov.io/gh/apache/trafficcontrol/commit/75ec56fa1bc4cf9c9e9ba54bde92197d4381649d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (75ec56f) will **decrease** coverage by `40.68%`.
> The diff coverage is `35.48%`.
```diff
@@ Coverage Diff @@
## master #7669 +/- ##
=============================================
- Coverage 65.05% 24.38% -40.68%
Complexity 98 98
=============================================
Files 314 371 +57
Lines 12365 27055 +14690
Branches 907 90 -817
=============================================
- Hits 8044 6597 -1447
- Misses 3968 19927 +15959
- Partials 353 531 +178
```
| Flag | Coverage Δ | |
|---|---|---|
| grove_unit | `4.60% <ø> (?)` | |
| t3c_unit | `5.27% <0.00%> (?)` | |
| traffic_monitor_unit | `21.30% <0.00%> (?)` | |
| traffic_portal_v2 | `?` | |
| traffic_stats_unit | `10.14% <ø> (?)` | |
| unit_tests | `11.57% <0.00%> (-62.21%)` | :arrow_down: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
| [Impacted Files](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [cache-config/t3c-generate/cfgfile/varnish.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y2FjaGUtY29uZmlnL3QzYy1nZW5lcmF0ZS9jZmdmaWxlL3Zhcm5pc2guZ28=) | `0.00% <0.00%> (ø)` | |
| [cache-config/t3c-generate/config/config.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y2FjaGUtY29uZmlnL3QzYy1nZW5lcmF0ZS9jb25maWcvY29uZmlnLmdv) | `0.81% <0.00%> (-0.08%)` | :arrow_down: |
| [cache-config/t3c-generate/t3c-generate.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-Y2FjaGUtY29uZmlnL3QzYy1nZW5lcmF0ZS90M2MtZ2VuZXJhdGUuZ28=) | `0.00% <0.00%> (ø)` | |
| [traffic\_monitor/tmclient/tmclient.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19tb25pdG9yL3RtY2xpZW50L3RtY2xpZW50Lmdv) | `0.00% <0.00%> (ø)` | |
| [traffic\_ops/v5-client/session.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdjUtY2xpZW50L3Nlc3Npb24uZ28=) | `72.22% <50.00%> (-2.78%)` | :arrow_down: |
| [traffic\_ops/v5-client/division.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdjUtY2xpZW50L2RpdmlzaW9uLmdv) | `100.00% <100.00%> (ø)` | |
| [traffic\_ops/v5-client/federation\_resolver.go](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-dHJhZmZpY19vcHMvdjUtY2xpZW50L2ZlZGVyYXRpb25fcmVzb2x2ZXIuZ28=) | `100.00% <100.00%> (ø)` | |
... and [272 files with indirect coverage changes](https://app.codecov.io/gh/apache/trafficcontrol/pull/7669/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
--
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] AbdelrahmanElawady commented on a diff in pull request #7669: Add parents to varnish cache
Posted by "AbdelrahmanElawady (via GitHub)" <gi...@apache.org>.
AbdelrahmanElawady commented on code in PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#discussion_r1282930571
##########
cache-config/t3c-apply/config/config.go:
##########
@@ -533,6 +535,9 @@ If any of the related flags are also set, they override the mode's default behav
if tsHome != "" {
TSHome = tsHome
tsConfigDir = tsHome + "/etc/trafficserver"
+ if cache != nil && *cache == "varnish" {
+ tsConfigDir = tsHome + "/etc/varnish"
Review Comment:
I believe the config dir will be either `home + /etc/trafficserver`, `home + /etc/varnish` or if `--trafficserver-home` flag is not used it will default to `/opt/trafficerver/etc/trafficserver` and won't go into the if block (which is not good) other than that it will be `home + /etc/varnish` for varnish case. For example specifying `--trafficserver-home` flag with `/opt/cache` will write the config to `/opt/cache/etc/varnish` and that is what is done in varnish [entrypoint](https://github.com/AbdelrahmanElawady/trafficcontrol/blob/add-parents-varnish/infrastructure/cdn-in-a-box/varnish/run.sh#L85).
I think ultimately default home and config dir shouldn't be related to TS. However, this change will affect CIAB, tests, workflows and some other code depending on that. So, Maybe it would be better if it is done in a separate 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] ocket8888 commented on a diff in pull request #7669: Add parents to varnish cache
Posted by "ocket8888 (via GitHub)" <gi...@apache.org>.
ocket8888 commented on code in PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#discussion_r1282504399
##########
infrastructure/cdn-in-a-box/enroller/Dockerfile:
##########
@@ -42,6 +42,9 @@ COPY ./traffic_ops/toclientlib/ /go/src/github.com/apache/trafficcontrol/traffic
COPY ./traffic_ops/v4-client/ /go/src/github.com/apache/trafficcontrol/traffic_ops/v4-client/
COPY ./infrastructure/cdn-in-a-box/ /go/src/github.com/apache/trafficcontrol/infrastructure/cdn-in-a-box/
+# varnishcfg requires t3c for ToData struct and not needed for enroller
+RUN rm -rf /go/src/github.com/apache/trafficcontrol/lib/varnishcfg
+
Review Comment:
I wouldn't worry about it; the enroller is pulling in a lot of things it doesn't strictly need. We can evaluate it if it becomes a problem, and try to clean it up a bit, but varnishcfg is small compared to the rest of the cruft so there's no point worrying about it
##########
cache-config/t3c-apply/torequest/torequest.go:
##########
@@ -1188,7 +1192,13 @@ func (r *TrafficOpsReq) StartServices(syncdsUpdate *UpdateStatus, metaData *t3cu
log.Errorln("ATS configuration has changed. The new config will be picked up the next time ATS is started.")
} else if serviceNeeds == t3cutil.ServiceNeedsReload {
log.Infoln("ATS configuration has changed, Running 'traffic_ctl config reload' now.")
- if _, _, err := util.ExecCommand(config.TSHome+config.TrafficCtl, "config", "reload"); err != nil {
+ reloadCommand := config.TSHome + config.TrafficCtl
+ reloadArgs := []string{"config", "reload"}
+ if cfg.CacheType == "varnish" {
+ reloadCommand = "varnishreload"
Review Comment:
This seems to be relying on `varnishreload` being in the running user's `$PATH` - with ATS cache servers we typically install everything under `/opt/trafficserver` (not that I think that's a good idea, personally) but it seems like that won't work for varnish caches if everything winds up installed under e.g. `/opt/varnish`. Or, at least, not without some extra work. Is that intentional, or is there some reason why it wouldn't find `varnishreload` in the same directory as the `varnish` binary?
##########
lib/varnishcfg/vclbuilder.go:
##########
@@ -0,0 +1,73 @@
+package varnishcfg
Review Comment:
At least one file in a package should have a GoDoc comment.
##########
cache-config/t3c-apply/config/config.go:
##########
@@ -533,6 +535,9 @@ If any of the related flags are also set, they override the mode's default behav
if tsHome != "" {
TSHome = tsHome
tsConfigDir = tsHome + "/etc/trafficserver"
+ if cache != nil && *cache == "varnish" {
+ tsConfigDir = tsHome + "/etc/varnish"
Review Comment:
It looks like for varnish cache servers, this will cause it to look for configuration files under `/etc/trafficserver/etc/varnish` (by default I think `tsHome` is `/opt/trafficserver` so that winds up being `/opt/trafficserver/etc/trafficserver/etc/varnish`) - is that really how we want to structure that?
##########
infrastructure/cdn-in-a-box/varnish/Dockerfile:
##########
@@ -0,0 +1,63 @@
+# 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.
+
+ARG BASE_IMAGE=rockylinux \
+ RHEL_VERSION=8
+FROM ${BASE_IMAGE}:${RHEL_VERSION} AS common-varnish-cache-config-layers
+ARG RHEL_VERSION=8
+# Makes RHEL_VERSION available at runtime
+ENV RHEL_VERSION="$RHEL_VERSION"
+
+RUN dnf module disable varnish -y && yum install -y epel-release
+
+RUN curl -s https://packagecloud.io/install/repositories/varnishcache/varnish73/script.rpm.sh | bash
+
+RUN yum install varnish-7.3.0-1.el8.x86_64 -y
Review Comment:
Do you really want to pin down to a specific release like that? If there's a major security bug that gets fixed with no breaking changes in v7.3.0-2 then we'd have to update this script. Also not sure it's a good idea to hard-code the CPU architecture; a lot of ATC devs use Macs, for example, and their new chipset isn't x86_64.
##########
infrastructure/cdn-in-a-box/varnish/Dockerfile:
##########
@@ -0,0 +1,63 @@
+# 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.
+
+ARG BASE_IMAGE=rockylinux \
+ RHEL_VERSION=8
+FROM ${BASE_IMAGE}:${RHEL_VERSION} AS common-varnish-cache-config-layers
+ARG RHEL_VERSION=8
+# Makes RHEL_VERSION available at runtime
+ENV RHEL_VERSION="$RHEL_VERSION"
+
+RUN dnf module disable varnish -y && yum install -y epel-release
+
+RUN curl -s https://packagecloud.io/install/repositories/varnishcache/varnish73/script.rpm.sh | bash
+
+RUN yum install varnish-7.3.0-1.el8.x86_64 -y
+
+RUN dnf install -y bind-utils kyotocabinet-libs initscripts iproute net-tools nmap-ncat gettext autoconf automake libtool gcc-c++ cronie glibc-devel openssl-devel git perl && \
+ dnf install -y jq logrotate findutils && \
+ dnf clean all
+
+
+COPY infrastructure/cdn-in-a-box/varnish/run.sh infrastructure/cdn-in-a-box/traffic_ops/to-access.sh infrastructure/cdn-in-a-box/enroller/server_template.json /
+
+COPY infrastructure/cdn-in-a-box/dns/set-dns.sh \
+ infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh \
+ /usr/local/sbin/
+
+
+COPY infrastructure/cdn-in-a-box/varnish/systemctl.sh /usr/bin/systemctl
Review Comment:
is it absolutely necessary to use systemd? Doing that in a Docker container is prone to problems and headaches
##########
cache-config/t3c-generate/cfgfile/varnish.go:
##########
@@ -0,0 +1,46 @@
+package cfgfile
+
+import (
+ "github.com/apache/trafficcontrol/cache-config/t3c-generate/config"
+ "github.com/apache/trafficcontrol/cache-config/t3cutil"
+ "github.com/apache/trafficcontrol/lib/varnishcfg"
+)
+
+/*
+ * 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.
+ */
Review Comment:
license header should go above imports, below package declaration
--
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] limited commented on pull request #7669: Add parents to varnish cache
Posted by "limited (via GitHub)" <gi...@apache.org>.
limited commented on PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#issuecomment-1658642821
Left a few comments, still need to test it out
--
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] AbdelrahmanElawady commented on a diff in pull request #7669: Add parents to varnish cache
Posted by "AbdelrahmanElawady (via GitHub)" <gi...@apache.org>.
AbdelrahmanElawady commented on code in PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#discussion_r1282949540
##########
cache-config/t3c-apply/torequest/torequest.go:
##########
@@ -1188,7 +1192,13 @@ func (r *TrafficOpsReq) StartServices(syncdsUpdate *UpdateStatus, metaData *t3cu
log.Errorln("ATS configuration has changed. The new config will be picked up the next time ATS is started.")
} else if serviceNeeds == t3cutil.ServiceNeedsReload {
log.Infoln("ATS configuration has changed, Running 'traffic_ctl config reload' now.")
- if _, _, err := util.ExecCommand(config.TSHome+config.TrafficCtl, "config", "reload"); err != nil {
+ reloadCommand := config.TSHome + config.TrafficCtl
+ reloadArgs := []string{"config", "reload"}
+ if cfg.CacheType == "varnish" {
+ reloadCommand = "varnishreload"
Review Comment:
It is done that way because Varnish currently is installed under root. So, `varnishreload` is currently installed in user's `$PATH`. It will be a problem indeed if Varnish is installed under different directory. Should Varnish be installed under different directory?
--
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] AbdelrahmanElawady commented on pull request #7669: Add parents to varnish cache
Posted by "AbdelrahmanElawady (via GitHub)" <gi...@apache.org>.
AbdelrahmanElawady commented on PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#issuecomment-1646097647
Also, will create issues for all TODOs added to be tracked and also changes that need to be done for proper integration with TC
--
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] limited commented on a diff in pull request #7669: Add parents to varnish cache
Posted by "limited (via GitHub)" <gi...@apache.org>.
limited commented on code in PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#discussion_r1279468470
##########
lib/varnishcfg/vcl.go:
##########
@@ -0,0 +1,99 @@
+package varnishcfg
+
+import "fmt"
+
+/*
+ * 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.
+ */
+
+const defaultVCLVersion = "4.1"
+
+// vclFile contains all VCL components
+type vclFile struct {
+ version string
+ imports []string
+ acls map[string][]string
+ backends map[string]backend
+ subroutines map[string][]string
+}
+
+func newVCLFile(version string) vclFile {
+ return vclFile{
+ version: version,
+ imports: make([]string, 0),
+ acls: make(map[string][]string),
+ backends: make(map[string]backend),
+ subroutines: make(map[string][]string),
+ }
+}
+
+func (v vclFile) String() string {
+ txt := fmt.Sprintf("vcl %s;\n", v.version)
+ for _, i := range v.imports {
+ txt += fmt.Sprintf("import %s;\n", i)
+ }
+
+ for name, backend := range v.backends {
+ txt += fmt.Sprintf("backend %s {\n", name)
+ txt += fmt.Sprint(backend)
+ txt += fmt.Sprint("}\n")
+ }
+ // varnishd will fail if there are no backends defined
+ if len(v.backends) == 0 {
+ txt += fmt.Sprint("backend default none;\n")
+ }
+
+ for name, acl := range v.acls {
+ txt += fmt.Sprintf("acl %s {\n", name)
+ for _, entry := range acl {
+ txt += fmt.Sprintf("\t%s\n", entry)
+ }
+ txt += fmt.Sprint("}\n")
+ }
+
+ // has to be before other subroutines for variables initialization
+ txt += fmt.Sprint("sub vcl_init {\n")
+ for _, entry := range v.subroutines["vcl_init"] {
Review Comment:
are we guaranteed to always have a `vcl_init` or do we need to check for presence first?
##########
lib/varnishcfg/backends.go:
##########
@@ -0,0 +1,172 @@
+package varnishcfg
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/apache/trafficcontrol/lib/go-atscfg"
+ "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+/*
+ * 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.
+ */
+
+func (v *VCLBuilder) configureDirectors(vclFile *vclFile, parents *atscfg.ParentAbstraction) ([]string, error) {
+ warnings := []string{}
+
+ vclFile.imports = append(vclFile.imports, "directors")
+ var err error
+ requestFQDNs := make([]string, 0)
+
+ for _, svc := range parents.Services {
+ addBackends(vclFile.backends, append(svc.Parents, svc.SecondaryParents...), svc.DestDomain, svc.Port)
+ addDirectors(vclFile.subroutines, svc)
+
+ requestFQDNs = []string{svc.DestDomain}
+
+ if v.toData.Server.Type == tc.CacheTypeEdge.String() {
+ dsRegexes := atscfg.MakeDSRegexMap(v.toData.DeliveryServiceRegexes)
+ anyCastPartners := atscfg.GetAnyCastPartners(v.toData.Server, v.toData.Servers)
+ requestFQDNs, err = atscfg.GetDSRequestFQDNs(
+ &svc.DS,
+ dsRegexes[tc.DeliveryServiceName(*svc.DS.XMLID)],
+ v.toData.Server,
+ anyCastPartners,
+ v.toData.CDN.DomainName,
+ )
+ if err != nil {
+ warnings = append(warnings, "error getting ds '"+*svc.DS.XMLID+"' request fqdns, skipping! Error: "+err.Error())
+ continue
+ }
+ }
+
+ assignBackends(vclFile.subroutines, svc, requestFQDNs)
+ }
+
+ return warnings, nil
+}
+
+func assignBackends(subroutines map[string][]string, svc *atscfg.ParentAbstractionService, requestFQDNs []string) {
+ lines := make([]string, 0)
+
+ conditions := make([]string, 0)
+ for _, fqdn := range requestFQDNs {
+ conditions = append(conditions, fmt.Sprintf(`req.http.host == "%s"`, fqdn))
+ }
+
+ lines = append(lines, fmt.Sprintf("if (%s) {", strings.Join(conditions, " || ")))
+ lines = append(lines, fmt.Sprintf("\tset req.backend_hint = %s.backend();", svc.Name))
+
+ // only change request host from edge servers which typically has multiple request FQDNs or
+ // one request FQDN that is not the origin.
+ if len(requestFQDNs) > 1 || (len(requestFQDNs) == 1 && requestFQDNs[0] != svc.DestDomain) {
+ lines = append(lines, fmt.Sprintf("\tset req.http.host = \"%s\";", svc.DestDomain))
Review Comment:
Might want to consider moving this to vcl_backend_fetch, and doing `set bereq.http.host=...` so that the host header is only changed on the request to the backend, and the original host header is preserved in the client request processing
##########
lib/varnishcfg/backends.go:
##########
@@ -0,0 +1,172 @@
+package varnishcfg
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/apache/trafficcontrol/lib/go-atscfg"
+ "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+/*
+ * 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.
+ */
+
+func (v *VCLBuilder) configureDirectors(vclFile *vclFile, parents *atscfg.ParentAbstraction) ([]string, error) {
+ warnings := []string{}
+
+ vclFile.imports = append(vclFile.imports, "directors")
+ var err error
+ requestFQDNs := make([]string, 0)
+
+ for _, svc := range parents.Services {
+ addBackends(vclFile.backends, append(svc.Parents, svc.SecondaryParents...), svc.DestDomain, svc.Port)
+ addDirectors(vclFile.subroutines, svc)
+
+ requestFQDNs = []string{svc.DestDomain}
+
+ if v.toData.Server.Type == tc.CacheTypeEdge.String() {
+ dsRegexes := atscfg.MakeDSRegexMap(v.toData.DeliveryServiceRegexes)
+ anyCastPartners := atscfg.GetAnyCastPartners(v.toData.Server, v.toData.Servers)
+ requestFQDNs, err = atscfg.GetDSRequestFQDNs(
+ &svc.DS,
+ dsRegexes[tc.DeliveryServiceName(*svc.DS.XMLID)],
+ v.toData.Server,
+ anyCastPartners,
+ v.toData.CDN.DomainName,
+ )
+ if err != nil {
+ warnings = append(warnings, "error getting ds '"+*svc.DS.XMLID+"' request fqdns, skipping! Error: "+err.Error())
+ continue
+ }
+ }
+
+ assignBackends(vclFile.subroutines, svc, requestFQDNs)
+ }
+
+ return warnings, nil
+}
+
+func assignBackends(subroutines map[string][]string, svc *atscfg.ParentAbstractionService, requestFQDNs []string) {
+ lines := make([]string, 0)
+
+ conditions := make([]string, 0)
+ for _, fqdn := range requestFQDNs {
+ conditions = append(conditions, fmt.Sprintf(`req.http.host == "%s"`, fqdn))
+ }
+
+ lines = append(lines, fmt.Sprintf("if (%s) {", strings.Join(conditions, " || ")))
+ lines = append(lines, fmt.Sprintf("\tset req.backend_hint = %s.backend();", svc.Name))
+
+ // only change request host from edge servers which typically has multiple request FQDNs or
+ // one request FQDN that is not the origin.
+ if len(requestFQDNs) > 1 || (len(requestFQDNs) == 1 && requestFQDNs[0] != svc.DestDomain) {
+ lines = append(lines, fmt.Sprintf("\tset req.http.host = \"%s\";", svc.DestDomain))
+ }
+
+ lines = append(lines, "}")
+
+ if _, ok := subroutines["vcl_recv"]; !ok {
+ subroutines["vcl_recv"] = make([]string, 0)
+ }
+ subroutines["vcl_recv"] = append(subroutines["vcl_recv"], lines...)
+}
+
+func addBackends(backends map[string]backend, parents []*atscfg.ParentAbstractionServiceParent, originDomain string, originPort int) {
+ for _, parent := range parents {
+ backendName := fmt.Sprintf("%s", getBackendName(parent.FQDN, parent.Port))
+ if _, ok := backends[backendName]; ok {
+ continue
+ }
+ backends[backendName] = backend{
+ host: parent.FQDN,
+ port: parent.Port,
+ }
+ }
+ backendName := fmt.Sprintf("%s", getBackendName(originDomain, originPort))
+ if _, ok := backends[backendName]; ok {
+ return
Review Comment:
Why skip this silently? Seems like it would be an error if the parent and origin backend names conflict?
##########
infrastructure/cdn-in-a-box/varnish/systemctl.sh:
##########
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+# 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.
+
+VARNISHD_EXECUTABLE="/usr/sbin/varnishd"
+
+is_varnishd_running() {
+ pgrep -x "$(basename "$VARNISHD_EXECUTABLE")" >/dev/null
+}
+
+start_varnishd() {
+ if is_varnishd_running; then
+ echo "varnishd is already running."
+ else
+ echo "Starting varnishd..."
+ "$VARNISHD_EXECUTABLE" -f /opt/trafficserver/etc/trafficserver/default.vcl
Review Comment:
Consider moving default.vcl into a different directory, not `trafficserver` related?
##########
lib/varnishcfg/backends.go:
##########
@@ -0,0 +1,172 @@
+package varnishcfg
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/apache/trafficcontrol/lib/go-atscfg"
+ "github.com/apache/trafficcontrol/lib/go-tc"
+)
+
+/*
+ * 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.
+ */
+
+func (v *VCLBuilder) configureDirectors(vclFile *vclFile, parents *atscfg.ParentAbstraction) ([]string, error) {
+ warnings := []string{}
+
+ vclFile.imports = append(vclFile.imports, "directors")
+ var err error
+ requestFQDNs := make([]string, 0)
+
+ for _, svc := range parents.Services {
+ addBackends(vclFile.backends, append(svc.Parents, svc.SecondaryParents...), svc.DestDomain, svc.Port)
+ addDirectors(vclFile.subroutines, svc)
+
+ requestFQDNs = []string{svc.DestDomain}
+
+ if v.toData.Server.Type == tc.CacheTypeEdge.String() {
+ dsRegexes := atscfg.MakeDSRegexMap(v.toData.DeliveryServiceRegexes)
+ anyCastPartners := atscfg.GetAnyCastPartners(v.toData.Server, v.toData.Servers)
+ requestFQDNs, err = atscfg.GetDSRequestFQDNs(
+ &svc.DS,
+ dsRegexes[tc.DeliveryServiceName(*svc.DS.XMLID)],
+ v.toData.Server,
+ anyCastPartners,
+ v.toData.CDN.DomainName,
+ )
+ if err != nil {
+ warnings = append(warnings, "error getting ds '"+*svc.DS.XMLID+"' request fqdns, skipping! Error: "+err.Error())
+ continue
+ }
+ }
+
+ assignBackends(vclFile.subroutines, svc, requestFQDNs)
+ }
+
+ return warnings, nil
+}
+
+func assignBackends(subroutines map[string][]string, svc *atscfg.ParentAbstractionService, requestFQDNs []string) {
+ lines := make([]string, 0)
+
+ conditions := make([]string, 0)
+ for _, fqdn := range requestFQDNs {
+ conditions = append(conditions, fmt.Sprintf(`req.http.host == "%s"`, fqdn))
+ }
+
+ lines = append(lines, fmt.Sprintf("if (%s) {", strings.Join(conditions, " || ")))
+ lines = append(lines, fmt.Sprintf("\tset req.backend_hint = %s.backend();", svc.Name))
+
+ // only change request host from edge servers which typically has multiple request FQDNs or
+ // one request FQDN that is not the origin.
+ if len(requestFQDNs) > 1 || (len(requestFQDNs) == 1 && requestFQDNs[0] != svc.DestDomain) {
+ lines = append(lines, fmt.Sprintf("\tset req.http.host = \"%s\";", svc.DestDomain))
+ }
+
+ lines = append(lines, "}")
+
+ if _, ok := subroutines["vcl_recv"]; !ok {
+ subroutines["vcl_recv"] = make([]string, 0)
+ }
+ subroutines["vcl_recv"] = append(subroutines["vcl_recv"], lines...)
+}
+
+func addBackends(backends map[string]backend, parents []*atscfg.ParentAbstractionServiceParent, originDomain string, originPort int) {
+ for _, parent := range parents {
+ backendName := fmt.Sprintf("%s", getBackendName(parent.FQDN, parent.Port))
+ if _, ok := backends[backendName]; ok {
+ continue
+ }
+ backends[backendName] = backend{
+ host: parent.FQDN,
+ port: parent.Port,
+ }
+ }
+ backendName := fmt.Sprintf("%s", getBackendName(originDomain, originPort))
+ if _, ok := backends[backendName]; ok {
+ return
+ }
+ backends[backendName] = backend{
+ host: originDomain,
+ port: originPort,
+ }
+}
+
+func addDirectors(subroutines map[string][]string, svc *atscfg.ParentAbstractionService) {
+ lines := make([]string, 0)
+ fallbackDirectorLines := make([]string, 0)
+ fallbackDirectorLines = append(fallbackDirectorLines, fmt.Sprintf("new %s = directors.fallback();", svc.Name))
+
+ if len(svc.Parents) != 0 {
+ lines = append(lines, addBackendsToDirector(svc.Name+"_primary", svc.RetryPolicy, svc.Parents)...)
+ fallbackDirectorLines = append(fallbackDirectorLines, fmt.Sprintf("%s.add_backend(%s_primary.backend());", svc.Name, svc.Name))
+ }
+ if len(svc.SecondaryParents) != 0 {
+ lines = append(lines, addBackendsToDirector(svc.Name+"_secondary", svc.RetryPolicy, svc.SecondaryParents)...)
+ fallbackDirectorLines = append(fallbackDirectorLines, fmt.Sprintf("%s.add_backend(%s_secondary.backend());", svc.Name, svc.Name))
+ }
+ fallbackDirectorLines = append(fallbackDirectorLines, fmt.Sprintf("%s.add_backend(%s);", svc.Name, getBackendName(svc.DestDomain, svc.Port)))
+
+ lines = append(lines, fallbackDirectorLines...)
+
+ if _, ok := subroutines["vcl_init"]; !ok {
+ subroutines["vcl_init"] = make([]string, 0)
+ }
+ subroutines["vcl_init"] = append(subroutines["vcl_init"], lines...)
+}
+
+func addBackendsToDirector(name string, retryPolicy atscfg.ParentAbstractionServiceRetryPolicy, parents []*atscfg.ParentAbstractionServiceParent) []string {
+ lines := make([]string, 0)
+ directorType := getDirectorType(retryPolicy)
+ sticky := ""
+ if directorType == "fallback" && retryPolicy == atscfg.ParentAbstractionServiceRetryPolicyLatched {
Review Comment:
Consider adding a separate `sticky` return from getDirectorType so all that evaluation happens in the same place
--
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] AbdelrahmanElawady commented on a diff in pull request #7669: Add parents to varnish cache
Posted by "AbdelrahmanElawady (via GitHub)" <gi...@apache.org>.
AbdelrahmanElawady commented on code in PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#discussion_r1282885135
##########
infrastructure/cdn-in-a-box/varnish/Dockerfile:
##########
@@ -0,0 +1,63 @@
+# 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.
+
+ARG BASE_IMAGE=rockylinux \
+ RHEL_VERSION=8
+FROM ${BASE_IMAGE}:${RHEL_VERSION} AS common-varnish-cache-config-layers
+ARG RHEL_VERSION=8
+# Makes RHEL_VERSION available at runtime
+ENV RHEL_VERSION="$RHEL_VERSION"
+
+RUN dnf module disable varnish -y && yum install -y epel-release
+
+RUN curl -s https://packagecloud.io/install/repositories/varnishcache/varnish73/script.rpm.sh | bash
+
+RUN yum install varnish-7.3.0-1.el8.x86_64 -y
+
+RUN dnf install -y bind-utils kyotocabinet-libs initscripts iproute net-tools nmap-ncat gettext autoconf automake libtool gcc-c++ cronie glibc-devel openssl-devel git perl && \
+ dnf install -y jq logrotate findutils && \
+ dnf clean all
+
+
+COPY infrastructure/cdn-in-a-box/varnish/run.sh infrastructure/cdn-in-a-box/traffic_ops/to-access.sh infrastructure/cdn-in-a-box/enroller/server_template.json /
+
+COPY infrastructure/cdn-in-a-box/dns/set-dns.sh \
+ infrastructure/cdn-in-a-box/dns/insert-self-into-dns.sh \
+ /usr/local/sbin/
+
+
+COPY infrastructure/cdn-in-a-box/varnish/systemctl.sh /usr/bin/systemctl
Review Comment:
Since `t3c-apply` only manages services using `systemctl` (or `service` in sysV systems) Traffic Server image and Varnish image both include a script replacing `systemctl` to start, restart, show status, enable and stop the cache service. There is no actual invoking of systemd, the scripts just mimics the behavior of `systemctl` regarding services
--
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] limited commented on pull request #7669: Add parents to varnish cache
Posted by "limited (via GitHub)" <gi...@apache.org>.
limited commented on PR #7669:
URL: https://github.com/apache/trafficcontrol/pull/7669#issuecomment-1666162792
Verified CIAB works to pull traffic through varnish following instructions above
--
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