Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Add Topology ATS Config Generation#4790

Merged
mitchell852 merged 14 commits intoapache:masterfrom
rob05c:add-topology-config-gen
Aug 6, 2020
Merged

Add Topology ATS Config Generation#4790
mitchell852 merged 14 commits intoapache:masterfrom
rob05c:add-topology-config-gen

Conversation

@rob05c
Copy link
Copy Markdown
Member

@rob05c rob05c commented Jun 12, 2020

Adds Topologies to ATS Config Generation.

Includes tests.
No docs, docs already exist for Topologies, and details of config gen aren't documented.
Includes changelog.

  • This PR is not related to any other Issue

Which Traffic Control components are affected by this PR?

  • Traffic Ops ORT

What is the best way to verify this PR?

Run tests.
Create Topologies in TO/TP with a Server, and a Delivery Service. Run ORT on that Server, and verify the config generated is correct. Verify servers not in a topology aren't included. Verify DSes without Topologies still use DeliveryServiceServers appropriately. Verify ATS loads config and serves requests to the DS appropriately.

If this is a bug fix, what versions of Traffic Control are affected?

Not a bug fix.

The following criteria are ALL met by this PR

  • This PR includes tests OR I have explained why tests are unnecessary
  • This PR includes documentation OR I have explained why documentation is unnecessary
  • This PR includes an update to CHANGELOG.md OR such an update is not necessary
  • This PR includes any and all required license headers
  • This PR ensures that database migration sequence is correct OR this PR does not include a database migration
  • This PR DOES NOT FIX A SERIOUS SECURITY VULNERABILITY (see the Apache Software Foundation's security guidelines for details)

Additional Information

@rob05c rob05c added new feature A new feature, capability or behavior Traffic Ops ORT *DEPRECATED* related to the traffic_ops_ort.pl script labels Jun 12, 2020
@rawlinp
Copy link
Copy Markdown
Contributor

rawlinp commented Jun 23, 2020

With the merging of #4807, would you like to account for firstHeaderRewrite, innerHeaderRewrite, and lastHeaderRewrite in this PR as well? I figure it might be easier to work those into this PR than tack them on later, but really it's up to you. It looks like it basically ignores edgeHeaderRewrite and midHeaderRewrite if the DS is assigned to a Topology which is good, but now we can consider those new fields for the Topology case.

@zrhoffman
Copy link
Copy Markdown
Member

Now that #4724 is merged, there's a CHANGELOG.md merge conflict

Comment thread lib/go-atscfg/atscfg.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With first/inner/last header rewrite now it might make sense for this function to specify which of those 3 buckets the server is in and use this when generating those configs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. I'll make it do whatever makes the most sense when I add those Header Rewrites to the generation. Not sure what that'll be until I start changing it.

Comment thread lib/go-atscfg/hostingdotconfig.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function appears to basically duplicate the makeDSTopologies function in remapdotconfig.go except for the == nil checks and using tc.DeliveryServiceNullable. Can they be consolidated and shared?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without a function to translate RemapConfigDSData to DeliveryServiceNullable, which would be even more code.

The non-API types like RemapConfigDSData exist in order to reduce duplication and unnecessary queries in TO. I'd like to remove them and change all the atscfg funcs to take standard API objects, but I was waiting until the config files were removed from the TO API.

Comment thread lib/go-atscfg/hostingdotconfig.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message should say hosting.config, but if this function is consolidated with makeDSTopologies maybe it should be left to the caller to prepend the Making *.config context.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than sending context down, I think it would be cleaner to propagate the error up and add the context in the caller. Most of config gen doesn't use errors now, because it needed to emulate the Perl in the TO API.

Once that's done, many functions like this will also distinguish between fatal and non-fatal errors.

I changed it to "hosting.config" for now, and added a TODO to propagate once config gen is returning errors properly.

Comment thread lib/go-atscfg/parentdotconfig.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine this comment was helpful for developing this PR but probably isn't needed anymore.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, accidentally left in. Removed.

Comment thread lib/go-atscfg/atscfg.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for MSO purposes I think we may need to include ORG_LOC cachegroups in topologies. So a more valid check for this is probably that there are no parents or the parents are all ORG_LOC.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it's been a few weeks, I'll have to verify, but I'm pretty sure the rest of the Topology Config expects that.

I believe I wrote it expecting MSO Origins to be the "last tier," and everything generates correctly. In terms of the remapping config, the last tier is no different than an intermediary tier, and multiple MSO origins are set as parents exactly the same way as multiple Mid parents.

That said, that may not work with the First/Middle/Last Header Rewrites. I'm planning to start implementing those soon, so hopefully I'll verify then.

I seem to recall it being very clean and elegant how MSO Origins were treated like any other server in the generation, I think it would be nice to preserve that if possible.

Comment thread lib/go-atscfg/remapdotconfig.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serverInfo is now unused

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Comment thread lib/go-atscfg/remapdotconfig.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to check the required capabilities before generating a remap line for a given DS, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread lib/go-atscfg/remapdotconfig.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to check the required capabilities before generating a remap line for a given DS, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread lib/go-atscfg/remapdotconfig.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should include the topology name as well

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to take capabilities into account when determining whether or not a given header-rewrite should be generated for a cache? I suppose as long as the remap is omitted in that case, the header-rewrite configs are just cruft.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, but yeah, not critical.

Header rewrites are their own file, so the place to do that is the meta gen.

The assignedEdges here are only used to calculate Max Origin Connections. The change here is just saying "if the DS is in a Topology, include the Edge in the Assigned count for MaxOriginConns."

@rob05c rob05c force-pushed the add-topology-config-gen branch 3 times, most recently from 3f73867 to 0742063 Compare July 9, 2020 21:24
@mitchell852
Copy link
Copy Markdown
Member

@rob05c - does this PR add the value of ds.max_origin_conns to header_rewrite_last_dsname.config

@rob05c
Copy link
Copy Markdown
Member Author

rob05c commented Jul 22, 2020

Yep, Max Origin Conns is in there, on the LastHeaderRewrite: https://github.com/apache/trafficcontrol/pull/4790/files#diff-4943b4d6fbf18539076e8631e37f740cR98

Copy link
Copy Markdown
Member

@zrhoffman zrhoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toreq.GetServerUpdateStatus() calls the API 1.4 version of GET /servers/{host_name}/update_status. Since #4901 only adds Flexible Topologies support for API 3.0 version of GET /servers/{host_name}/update_status, atstccfg won't get accurate parent_pending and parent_reval_pendinginfo if it uses API 1.4 for this route.

Comment thread lib/go-atscfg/parentdotconfig.go Outdated
Comment on lines 565 to 573
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the immediate parent cachegroup has no servers in it GetTopologyParents(), returns empty arrays, even if there are servers in further ancestor topology nodes. Should it keep going until it finds a topology node with a non-empty cachegroup?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, maybe we should perform validation to make sure a topology node's cachegroup contains at least 1 server.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(That validation would occur in TO and is outside the scope of this PR)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been trying to log errors on every possible bad data the config gen can receive.
I'd agree with doing the validation in TO, but also logging an error in the config gen. I'll make it do that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I made it log the error

rob05c added 8 commits August 4, 2020 14:21
Adds ORT location param inference. If location Parameters do not exist
the files are created and added anyway with the directory determined
from the local ATS install, for:
- cache.config
- hosting.config
- ip_allow.config
- parent.config
- plugin.config
- records.config
- remap.config
- storage.config
- volume.config
- Delivery Services with
  - Edge Header Rewrite
  - Mid Header Rewrite,
  - Cache URL
  - URL Sig
  - URI Signing

Note this is not an exhaustive of required files, and many files
must be dynamic and cannot be inferred.

But this does remove the manual configuration for this list.
More files may be added in the future.
Refactors parent.config generation to have a single DS for-loop,
instead of different loops for top-level vs non-top-level caches.

This is to prepare for Topologies, which will need their own
behavior, irrespective of "top level" Edge vs Mid, for every DS.
Also adds a TODO to propogate, once config gen returns errors.
@rob05c rob05c force-pushed the add-topology-config-gen branch from de1c7fc to 4b65101 Compare August 4, 2020 20:22
rob05c added 2 commits August 4, 2020 14:29
Necessary because the latest API considers Topologies, previous API
doesn't.
@rob05c
Copy link
Copy Markdown
Member Author

rob05c commented Aug 4, 2020

toreq.GetServerUpdateStatus() calls the API 1.4 version of GET /servers/{host_name}/update_status. Since #4901 only adds Flexible Topologies support for API 3.0 version of GET /servers/{host_name}/update_status, atstccfg won't get accurate parent_pending and parent_reval_pendinginfo if it uses API 1.4 for this route.

Fixed - ORT/atstccfg will now use the latest API if it exists, and fall back to the prior if it doesn't.

@zrhoffman
Copy link
Copy Markdown
Member

atscfg.TestMakeParentDotConfigTopologies fails:

--- FAIL: TestMakeParentDotConfigTopologies (0.00s)
    parentdotconfig_test.go:488: expected parent 'dest_domain=ds0.example.net', actual: '# DO NOT EDIT - Generated for myserver by myToolName (https://myto.example.net) on Tue Aug 4 21:44:15 UTC 2020
        dest_domain=ds0.example.net port=80 parent=""  round_robin=consistent_hash go_direct=false qstring=myQStringHandlingParam
        dest_domain=. parent="" round_robin=consistent_hash go_direct=false qstring=myQstringParam
        '
--- FAIL: TestMakeParentDotConfigTopologiesCapabilities (0.00s)
    parentdotconfig_test.go:721: expected parent 'dest_domain=ds0.example.net' without required capabilities: '# DO NOT EDIT - Generated for myserver by myToolName (https://myto.example.net) on Tue Aug 4 21:44:15 UTC 2020
        dest_domain=. parent="" round_robin=consistent_hash go_direct=false qstring=myQstringParam
        '
    parentdotconfig_test.go:724: expected parent 'dest_domain=ds1.example.net' with necessary required capabilities, actual: '# DO NOT EDIT - Generated for myserver by myToolName (https://myto.example.net) on Tue Aug 4 21:44:15 UTC 2020
        dest_domain=. parent="" round_robin=consistent_hash go_direct=false qstring=myQstringParam
        '
FAIL
exit status 1
FAIL    github.com/apache/trafficcontrol/lib/go-atscfg  0.007s

@rob05c
Copy link
Copy Markdown
Member Author

rob05c commented Aug 4, 2020

atscfg.TestMakeParentDotConfigTopologies fails:

Ah, the code was right, just the latest Capability changes broke the tests, needed more data.
Fixed.

Comment thread lib/go-atscfg/atscfg.go Outdated
}

return len(serverNode.Parents) == 0, true
topologyHasChildren := false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A name like topologyNodeHasChildren or nodeHasChildren might make more sense here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Comment thread lib/go-atscfg/atscfg.go
Comment on lines +195 to +202
for _, node := range topology.Nodes {
for _, parent := range node.Parents {
if parent == serverNodeIndex {
topologyHasChildren = true
break
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should break out of the outer loop if topologyHasChildren is true

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not a bug, just less efficient. I'll fix.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread lib/go-atscfg/meta.go Outdated
Comment on lines 160 to 165
for _, to := range topologies {
if to.Name == *ds.Topology {
topology = to
break
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a tc.DeliveryServiceNullable array and a tc.Topology array in this scope, consider calling atscfg.hostingMakeDSTopologies() to get a topologies by DS name map so that running time is number of DSes + number of Topologies instead of number of DSes * number of Topologies like it currently is.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back and forth whether to use a map for these. The performance doesn't matter, unless someone had on the order of a million topologies, the network cost vastly outweighs this. But I don't really object, I'll change them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines +67 to +72
for _, to := range topologies {
if to.Name == *ds.Topology {
topology = to
break
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another place where a topologies by DS name map would be useful (though it doesn't make sense to build it here).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// Topologies must be all the topologies for the server's cdn.
// May incude topologies of other cdns.
Topologies []tc.Topology
Copy link
Copy Markdown
Member

@zrhoffman zrhoffman Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any advantage to having topologies not assigned to any DS? If not, including a topologies by DS name map in TOData instead of a topology array might make more sense, since there are several places where we need to get a topology, given a certain DS.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep TOData as the raw data from Traffic Ops, in order to make the config gen library lib/go-atscfg more flexible.

As soon as the config routes are removed from TO, the plan is to change lib/go-atscfg to take standard API objects.

If we do pre-processing like putting things in maps in ORT/atstccfg, and pass pre-processed data to lib/go-atscfg, then atscfg is harder to use for anyone wanting to just make a TO request for the necessary data and pass it to a config gen func.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that makes more sense in the long run.

rob05c added 3 commits August 5, 2020 10:34
More performant for large numbers of topologies. Per PR review.
Copy link
Copy Markdown
Member

@zrhoffman zrhoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Code is formatted correctly
  • Unit tests pass
  • atstccfg respects Topologies parentage but only for topology-based DSes, ATS serves requests appropriately
  • Non-topology-based DSes continue to work with DeliveryServiceServers as expected
  • FirstHeaderRewrite/InnerHeaderRewrite/LastHeaderRewrite rules are places on the appropriate caches

LGTM!

@mitchell852 mitchell852 merged commit dababd8 into apache:master Aug 6, 2020
@zrhoffman zrhoffman added this to the Flexible Topologies milestone Sep 18, 2020
@zrhoffman zrhoffman removed this from the Flexible Topologies milestone Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

new feature A new feature, capability or behavior Traffic Ops ORT *DEPRECATED* related to the traffic_ops_ort.pl script

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants